:root {
    --ink: #17201d;
    --muted: #66716d;
    --paper: #f5f3ed;
    --panel: #ffffff;
    --line: #dddcd4;
    --green: #1d5c48;
    --green-dark: #164537;
    --green-soft: #e7f0ec;
    --amber: #a96416;
    --amber-soft: #fff2dc;
    --red: #a64034;
    --red-soft: #fbe9e6;
    --shadow: 0 16px 40px rgba(35, 44, 40, 0.08);
    --radius: 18px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at top right, rgba(29, 92, 72, 0.08), transparent 28rem),
        var(--paper);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    line-height: 1.5;
}

a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-dark); }

.topbar {
    min-height: 72px;
    padding: 12px clamp(18px, 4vw, 56px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); }
.brand:hover { color: var(--ink); }
.brand-mark {
    width: 42px; height: 42px; border-radius: 12px;
    display: grid; place-items: center;
    color: white; background: var(--green);
    font-weight: 800; letter-spacing: .04em;
}
.brand strong, .brand small { display: block; }
.brand small { color: var(--muted); font-size: 12px; }

.topbar-actions { display: flex; align-items: center; gap: 18px; }
.topbar-actions form { margin: 0; }
.user-name { color: var(--muted); }
.link-button {
    border: 0; padding: 0; background: none; color: var(--green);
    cursor: pointer; font: inherit;
}

.page-shell {
    width: min(1440px, calc(100% - 36px));
    margin: 0 auto;
    padding: 38px 0 80px;
}

.page-heading {
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: 24px; margin-bottom: 26px;
}
.page-heading h1 { font-size: clamp(32px, 5vw, 52px); line-height: 1.05; margin: 6px 0 10px; letter-spacing: -.035em; }
.page-heading p { margin: 0; color: var(--muted); max-width: 760px; }
.eyebrow {
    color: var(--green); font-size: 12px; font-weight: 800;
    letter-spacing: .14em; text-transform: uppercase;
}
.back-link { display: inline-block; margin-bottom: 16px; font-weight: 600; }
.heading-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.panel {
    background: var(--panel);
    border: 1px solid rgba(221, 220, 212, 0.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.button {
    min-height: 44px;
    padding: 10px 18px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid transparent; border-radius: 12px;
    font: inherit; font-weight: 700; cursor: pointer;
}
.button-primary { background: var(--green); color: white; }
.button-primary:hover { background: var(--green-dark); color: white; }
.button-secondary { background: var(--green-soft); color: var(--green-dark); border-color: #cfe0d9; }
.button-secondary:hover { background: #dae9e3; color: var(--green-dark); }
.button-danger { background: var(--red-soft); color: var(--red); border-color: #efc8c1; }
.button-danger:hover { background: #f5d7d2; color: #812f27; }
.button-quiet { background: transparent; color: var(--muted); }
.button-small { min-height: 38px; padding: 7px 14px; }
.button-full { width: 100%; }

.messages { margin-bottom: 20px; }
.message { padding: 13px 16px; border-radius: 12px; border: 1px solid; }
.message-success { background: var(--green-soft); border-color: #bad7cc; color: var(--green-dark); }
.message-error { background: var(--red-soft); border-color: #efc8c1; color: var(--red); }
.message-info { background: #edf3f8; border-color: #ccdce8; color: #36586e; }

.search-panel { padding: 18px; margin-bottom: 20px; }
.search-form { display: flex; align-items: flex-end; gap: 12px; }
.search-field { flex: 1; }

.field { min-width: 0; }
.field label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 750; }
.field small { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
.field input:not([type="checkbox"]),
.field select,
.field textarea,
.stack-form input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    color: var(--ink);
    background: #fbfbf8;
    border: 1px solid #cfd2cd;
    border-radius: 10px;
    font: inherit;
}
.field textarea { resize: vertical; }
.field #id_products {
    display: grid;
    gap: 6px;
    padding: 10px 12px;
    border: 1px solid #cfd2cd;
    border-radius: 10px;
    background: #fbfbf8;
}
.field #id_products > div label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-weight: 500;
    cursor: pointer;
}
.field #id_products input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--green);
}
.field #id_products label:has(input:disabled) {
    color: var(--muted);
    cursor: not-allowed;
    opacity: 0.55;
}
.field input:focus, .field select:focus, .field textarea:focus, .stack-form input:focus {
    outline: 3px solid rgba(29, 92, 72, 0.14);
    border-color: var(--green);
}
.errorlist { margin: 6px 0 0; padding: 0; list-style: none; color: var(--red); font-size: 12px; }
.field-error input, .field-error select, .field-error textarea { border-color: var(--red); }
.form-errors { padding: 10px; margin-bottom: 12px; background: var(--red-soft); border-radius: 10px; }
.field-warning { margin: 12px 0 0; color: var(--amber); font-size: 13px; font-weight: 700; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 15px 16px; text-align: left; border-bottom: 1px solid #ecece7; vertical-align: top; }
.data-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; background: #fafaf7; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fcfcf9; }
.table-wrap { overflow-x: auto; border-radius: inherit; }
.table-action { text-align: right !important; white-space: nowrap; font-weight: 700; }

.tag-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
    display: inline-flex; padding: 4px 9px; margin: 2px;
    color: #3f524b; background: #edf1ef; border-radius: 999px;
    font-size: 12px; font-weight: 700;
}
.tag-large { padding: 7px 12px; font-size: 14px; }
.status {
    display: inline-flex; padding: 7px 11px; border-radius: 999px;
    font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
}
.status-draft { color: var(--amber); background: var(--amber-soft); }
.status-completed { color: var(--green-dark); background: var(--green-soft); }
.status-annulled { color: #9f2f2f; background: #fde9e7; }
.heading-actions form { margin: 0; }

.empty-state { padding: 70px 24px; text-align: center; }
.empty-state h2 { margin: 0 0 6px; }
.empty-state p, .muted { color: var(--muted); }

.section-panel { padding: clamp(20px, 3vw, 34px); margin-bottom: 22px; }
.warning-panel { border-color: #e7c692; background: #fffdf8; }
.section-heading {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 24px; margin-bottom: 24px;
}
.section-heading > div { display: flex; align-items: center; gap: 12px; }
.section-heading h2 { margin: 0; font-size: 22px; }
.section-heading p { margin: 3px 0 0; color: var(--muted); max-width: 560px; text-align: right; }
.section-number {
    width: 38px; height: 38px; display: grid; place-items: center;
    color: var(--green); background: var(--green-soft); border-radius: 10px;
    font-weight: 800; font-size: 12px;
}

.form-grid { display: grid; gap: 16px; margin-bottom: 16px; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.formset-list { display: grid; gap: 14px; margin-bottom: 16px; }
.formset-card {
    padding: 18px;
    background: #fafaf7;
    border: 1px solid #e4e4dc;
    border-radius: 14px;
}
.formset-card-heading {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; margin-bottom: 16px;
}
.delete-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.delete-marker { display: none; }
.calculation-strip {
    display: flex; gap: 24px; flex-wrap: wrap;
    margin: 4px 0 14px; padding: 10px 12px;
    color: #45534e; background: white; border: 1px solid #e4e4dc; border-radius: 10px;
}

.output-matrix { display: grid; gap: 14px; }
.output-group {
    padding: 18px;
    background: #fafaf7;
    border: 1px solid #e4e4dc;
    border-radius: 14px;
}
.output-group-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.size-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
    gap: 10px;
}
.size-quantity { display: grid; gap: 5px; }
.size-quantity span { color: var(--muted); font-size: 12px; font-weight: 800; }
.size-quantity input {
    width: 100%;
    min-height: 42px;
    padding: 8px 10px;
    color: var(--ink);
    background: white;
    border: 1px solid #cfd2cd;
    border-radius: 9px;
    font: inherit;
}
.compact-empty { padding: 28px 18px; }
.missing-data { color: var(--amber); font-size: 13px; font-weight: 750; }
.detail-meta-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
    padding: 10px 24px 24px;
}
.detail-meta-grid > div { display: grid; gap: 10px; }

.sticky-actions {
    position: sticky; bottom: 16px; z-index: 15;
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 14px;
    background: rgba(255, 255, 255, .94);
    border: 1px solid var(--line); border-radius: 16px;
    box-shadow: 0 12px 32px rgba(35, 44, 40, .14);
    backdrop-filter: blur(12px);
}

.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 22px; }
.summary-card {
    min-height: 150px; padding: 20px;
    display: flex; flex-direction: column;
    background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: var(--shadow);
}
.summary-card span { color: var(--muted); font-size: 13px; }
.summary-card strong { margin: auto 0 4px; font-size: clamp(24px, 3vw, 34px); letter-spacing: -.03em; }
.summary-card small { color: var(--muted); }
.detail-section { margin-bottom: 20px; }
.detail-section > .section-heading, .detail-section > .tag-list, .timeline { padding: 22px 24px; margin: 0; }
.detail-section > .section-heading { padding-bottom: 12px; }

.timeline { display: grid; gap: 18px; }
.timeline-item { display: grid; grid-template-columns: 14px 1fr; gap: 12px; }
.timeline-dot { width: 10px; height: 10px; margin-top: 6px; border-radius: 50%; background: var(--green); }
.timeline-item p { margin: 4px 0; }
.timeline-item small { color: var(--muted); }
.revision-details { margin-top: 8px; }
.revision-details summary { color: var(--green); cursor: pointer; font-weight: 700; }
.revision-list { display: grid; gap: 6px; margin-top: 10px; }
.revision-list > div {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(90px, 220px) 20px minmax(90px, 220px);
    gap: 8px;
    align-items: start;
    padding: 8px 10px;
    background: #fafaf7;
    border-radius: 8px;
    font-size: 13px;
}
.revision-field { color: var(--muted); font-weight: 650; overflow-wrap: anywhere; }
.revision-value { overflow-wrap: anywhere; }
.revision-field + .revision-value { text-align: right; }
.revision-arrow { color: var(--muted); text-align: center; }

.login-layout {
    min-height: calc(100vh - 170px);
    display: grid; grid-template-columns: 1.3fr minmax(320px, 460px);
    align-items: center; gap: clamp(40px, 8vw, 120px);
}
.login-copy h1 { max-width: 760px; margin: 8px 0 18px; font-size: clamp(42px, 6vw, 76px); line-height: .98; letter-spacing: -.05em; }
.login-copy p { max-width: 620px; color: var(--muted); font-size: 18px; }
.login-card { padding: 30px; }
.login-card h2 { margin: 0 0 4px; font-size: 30px; }
.stack-form { display: grid; gap: 16px; margin-top: 24px; }

.app-footer {
    width: min(100% - 40px, 1440px);
    margin: 0 auto;
    padding: 8px 0 28px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    color: var(--muted);
    font-size: 12px;
}

@media (max-width: 1000px) {
    .form-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .login-layout { grid-template-columns: 1fr; padding-top: 30px; }
    .login-copy h1 { font-size: 48px; }
}

@media (max-width: 700px) {
    .topbar { position: static; align-items: flex-start; }
    .topbar-actions { justify-content: flex-end; flex-wrap: wrap; gap: 10px; }
    .topbar-actions > a:not(.button), .user-name { display: none; }
    .page-shell { width: min(100% - 22px, 1440px); padding-top: 24px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .page-heading h1 { font-size: 38px; }
    .section-heading { flex-direction: column; gap: 8px; }
    .section-heading p { text-align: left; }
    .form-grid-2, .form-grid-3, .form-grid-4, .summary-grid, .detail-meta-grid { grid-template-columns: 1fr; }
    .search-form { align-items: stretch; flex-direction: column; }
    .sticky-actions { flex-wrap: wrap; }
    .sticky-actions .button { flex: 1 1 150px; }
    .revision-list > div { grid-template-columns: minmax(0, 1fr) 20px minmax(0, 1fr); }
    .revision-field { grid-column: 1 / -1; }
    .login-copy { display: none; }
    .app-footer { width: min(100% - 22px, 1440px); }
}
