:root {
    --ink: #17212b;
    --muted: #647180;
    --line: #d9e0e7;
    --paper: #ffffff;
    --canvas: #f5f7fa;
    --brand: #116a7b;
    --brand-dark: #0a4d5c;
    --accent: #c75c2f;
    --green: #197a4d;
    --red: #b42318;
    --yellow: #9a6b00;
    --blue: #2357a5;
    --radius: 8px;
    --shadow: 0 10px 28px rgba(23, 33, 43, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--canvas);
}

body {
    margin: 0;
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-height: 68px;
    padding: 12px 28px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: var(--ink);
    text-decoration: none;
    min-width: 190px;
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    color: #fff;
    background: var(--brand);
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: var(--muted);
    font-size: 12px;
}

.nav {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
}

.nav a,
.link-button {
    min-height: 36px;
    padding: 8px 11px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--ink);
    background: transparent;
    font: inherit;
    cursor: pointer;
}

.nav a:hover,
.link-button:hover {
    background: #edf3f5;
    text-decoration: none;
}

.nav form {
    margin: 0;
}

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 28px auto 54px;
}

.hero,
.record-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 24px 0 28px;
}

.hero h1,
.record-head h1,
.panel h1 {
    margin: 0;
    font-size: 32px;
    line-height: 1.12;
}

.hero p,
.record-head p {
    max-width: 680px;
    margin: 8px 0 0;
    color: var(--muted);
}

.eyebrow {
    margin: 0 0 8px !important;
    color: var(--accent) !important;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.hero-actions,
.record-state,
.form-actions,
.filter-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: var(--paper);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.button:hover {
    text-decoration: none;
    border-color: #b9c6d1;
}

.button.primary {
    color: #fff;
    border-color: var(--brand);
    background: var(--brand);
}

.button.primary:hover {
    background: var(--brand-dark);
}

.button.secondary {
    background: #eef5f6;
    border-color: #c8dce1;
}

.button.ghost {
    background: transparent;
}

.button.small {
    min-height: 36px;
    padding: 8px 12px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat,
.panel,
.auth-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: var(--shadow);
}

.stat {
    display: block;
    min-height: 100px;
    padding: 16px;
    color: var(--ink);
}

.stat:hover {
    text-decoration: none;
    border-color: #b9c6d1;
}

.stat span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.stat strong {
    display: block;
    margin-top: 12px;
    font-size: 32px;
}

.panel {
    padding: 20px;
    margin-bottom: 18px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.panel-head h1,
.panel-head h2,
.panel h2 {
    margin: 0;
}

.panel h2 {
    font-size: 20px;
}

.auth-card {
    width: min(460px, 100%);
    margin: 64px auto;
    padding: 24px;
}

.auth-card h1 {
    margin: 0 0 8px;
    font-size: 28px;
}

.auth-card p {
    margin: 0 0 20px;
    color: var(--muted);
}

.form-grid,
.filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-grid.compact {
    grid-template-columns: 1fr;
}

.filters {
    grid-template-columns: minmax(240px, 1.4fr) minmax(160px, 0.8fr) minmax(180px, 0.9fr) auto;
    align-items: end;
}

label {
    display: grid;
    gap: 7px;
    color: var(--ink);
    font-weight: 700;
}

label span {
    font-size: 13px;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: 10px 11px;
    border: 1px solid #c7d1da;
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    font: inherit;
}

textarea {
    resize: vertical;
    min-height: 116px;
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(17, 106, 123, 0.16);
    border-color: var(--brand);
}

input.invalid {
    border-color: var(--red);
    outline-color: rgba(180, 35, 24, 0.14);
}

small,
.muted {
    color: var(--muted);
}

.full {
    grid-column: 1 / -1;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

table {
    width: 100%;
    min-width: 880px;
    border-collapse: collapse;
    background: #fff;
}

th,
td {
    padding: 12px 11px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    background: #f8fafc;
    font-size: 12px;
    text-transform: uppercase;
}

tr:last-child td {
    border-bottom: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.badge.new {
    color: var(--blue);
    background: #eaf1ff;
}

.badge.sent {
    color: #5a3f04;
    background: #fff3cc;
}

.badge.wait {
    color: var(--yellow);
    background: #fff6dc;
}

.badge.good {
    color: var(--green);
    background: #e8f6ef;
}

.badge.bad {
    color: var(--red);
    background: #fdecea;
}

.badge.closed {
    color: #4b5563;
    background: #eef0f3;
}

.flash {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    font-weight: 700;
}

.flash.success {
    color: var(--green);
    background: #e8f6ef;
}

.flash.error {
    color: var(--red);
    background: #fdecea;
}

.empty {
    margin: 0;
    color: var(--muted);
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 18px;
    align-items: start;
}

.side-stack {
    display: grid;
    gap: 18px;
}

.file-list,
.timeline {
    list-style: none;
    margin: 0;
    padding: 0;
}

.file-list li,
.timeline li {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.file-list li:last-child,
.timeline li:last-child {
    border-bottom: 0;
}

.file-list a,
.timeline strong,
.timeline span,
.timeline p {
    display: block;
}

.file-list small,
.timeline span {
    margin-top: 4px;
    color: var(--muted);
}

.timeline p {
    margin: 6px 0 0;
}

@media (max-width: 920px) {
    .topbar,
    .hero,
    .record-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .nav {
        justify-content: flex-start;
    }

    .stats,
    .form-grid,
    .filters,
    .split {
        grid-template-columns: 1fr;
    }

    .filter-actions {
        align-items: stretch;
    }

    .filter-actions .button,
    .hero-actions .button {
        width: 100%;
    }
}

@media (max-width: 560px) {
    .topbar {
        padding: 12px 16px;
    }

    .shell {
        width: min(100% - 20px, 1180px);
        margin-top: 18px;
    }

    .hero h1,
    .record-head h1,
    .panel h1 {
        font-size: 26px;
    }

    .panel,
    .auth-card {
        padding: 16px;
    }
}
