:root {
    --navy: #13243b;
    --navy-light: #203954;
    --orange: #ec731e;
    --orange-dark: #cc5b0c;
    --background: #f2f5f9;
    --text: #203047;
    --muted: #68768a;
    --line: #e0e6ef;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 20px; }

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a { color: #195ca5; text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }

:focus-visible {
    outline: 3px solid #71aaff;
    outline-offset: 3px;
}

.topbar {
    min-height: 76px;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 14px 28px;
    background: white;
    border-bottom: 1px solid var(--line);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: var(--navy);
    font-size: 23px;
    font-weight: 800;
    letter-spacing: -.7px;
}

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

.brand-symbol {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    background: var(--orange);
    border-radius: 11px;
    color: white;
    font-size: 24px;
}

.company { color: var(--muted); font-size: 14px; }

.userbar {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 15px;
}

.userbar form { margin: 0; }

.layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    min-height: calc(100vh - 76px);
}

.layout.plain { display: block; }

.sidebar {
    padding: 28px 14px;
    background: var(--navy);
    color: white;
}

.sidebar a {
    display: block;
    color: #d5dfeb;
    padding: 13px 16px;
    border-radius: 9px;
    margin-bottom: 7px;
    font-weight: 550;
}

.sidebar a.active,
.sidebar a:hover {
    color: white;
    background: var(--navy-light);
    text-decoration: none;
}

.sidebar-note {
    color: #9eafc2;
    font-size: 12px;
    padding: 28px 16px;
}

main {
    min-width: 0;
    padding: 32px;
    max-width: 1700px;
    width: 100%;
    margin: 0 auto;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
    font-size: clamp(26px, 3vw, 36px);
    letter-spacing: -.8px;
    line-height: 1.2;
    margin-bottom: 12px;
    overflow-wrap: anywhere;
}

h2 { font-size: 20px; letter-spacing: -.3px; }
h3 { font-size: 16px; }

.eyebrow {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 1.6px;
    color: var(--muted);
    margin-bottom: 10px;
}

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

.page-heading,
.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.section-heading { margin-bottom: 12px; }
.section-heading h2 { margin: 0; }

.card {
    background: white;
    border: 1px solid var(--line);
    border-radius: 15px;
    padding: 24px;
    box-shadow: 0 3px 16px rgb(20 36 59 / 3%);
    min-width: 0;
}

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

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

.stat strong {
    display: block;
    color: var(--navy);
    font-size: 38px;
    margin-top: 10px;
    line-height: 1.1;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 17px;
    min-height: 45px;
    border: 1px solid transparent;
    border-radius: 9px;
    cursor: pointer;
    font-weight: 650;
    font-size: 14px;
    text-align: center;
    text-decoration: none;
}

.button:hover { text-decoration: none; }
.button:disabled { opacity: .65; cursor: wait; }
.primary { background: var(--orange); color: white; }
.primary:hover { background: var(--orange-dark); }

.secondary {
    background: white;
    border-color: #ccd6e2;
    color: var(--navy);
}

.secondary:hover { background: #f4f7fb; }
.small { padding: 7px 12px; min-height: 36px; font-size: 12px; }
.big { min-height: 58px; font-size: 17px; }
.full-width { width: 100%; }

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .8px;
    padding: 15px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

td {
    padding: 13px 12px;
    border-bottom: 1px solid #edf0f5;
    font-size: 14px;
    vertical-align: middle;
    max-width: 310px;
    overflow-wrap: anywhere;
}

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

.order-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 4px 0;
    font-size: 16px;
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 3px;
}

small {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
}

.badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    border-radius: 20px;
    padding: 6px 11px;
    background: #eaf0f7;
    color: #425570;
    white-space: nowrap;
}

.status-new { background: #fff0da; color: #8a4b00; }
.status-assigned { background: #e8edf5; color: #425570; }
.status-enroute { background: #e3efff; color: #155bb4; }
.status-onsite, .status-loaded { background: #f0e7ff; color: #7444a3; }
.status-done { background: #e3f5eb; color: #166440; }
.status-cancelled { background: #fbe7e7; color: #9d2525; }

.mobile-orders { display: none; }

.order-card {
    display: block;
    color: var(--text);
    background: white;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 17px;
    min-width: 0;
}

.order-card:hover {
    text-decoration: none;
    background: #f8faff;
    border-color: #aabed7;
}

.order-card-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.order-card-top strong {
    color: #195ca5;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.order-card-plate {
    font-size: 23px;
    font-weight: 800;
    margin-top: 12px;
    overflow-wrap: anywhere;
}

.order-card-place {
    margin-top: 13px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    overflow-wrap: anywhere;
}

.order-card-bottom {
    margin-top: 13px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
}

.form-grid { display: grid; gap: 19px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.full { grid-column: 1 / -1; }
label { display: block; font-size: 14px; font-weight: 650; }

input:not([type="checkbox"]),
select,
textarea {
    display: block;
    width: 100%;
    min-width: 0;
    border: 1px solid #cdd7e3;
    background: white;
    color: var(--text);
    border-radius: 8px;
    padding: 12px;
    margin-top: 7px;
    min-height: 47px;
}

textarea { resize: vertical; }

.filters {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    align-items: center;
}

.filters input, .filters select { margin: 0; }
.filters input { flex: 1; }
.filters select { width: auto; min-width: 180px; }

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

.auth-card { max-width: 460px; margin: 45px auto; padding: 32px; }
.narrow { max-width: 650px; }
.document-card { max-width: 880px; margin: 0 auto; }

.document-data {
    display: grid;
    grid-template-columns: minmax(130px, 1fr) minmax(0, 2fr);
    margin: 25px 0;
}

.document-data dt,
.document-data dd {
    margin: 0;
    padding: 12px 8px;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
}

.document-data dt { color: var(--muted); font-size: 13px; }

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-weight: 400;
}

.checkbox-label input { width: 21px; height: 21px; flex-shrink: 0; }

#signature-pad {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 10 / 3;
    border: 2px dashed #aebed0;
    border-radius: 10px;
    background: white;
    touch-action: none;
    margin: 12px 0;
}

.signature-image {
    display: block;
    max-width: 100%;
    width: 420px;
    height: auto;
    border-bottom: 1px solid #b8c6d6;
    margin-bottom: 20px;
}

.notice {
    border-radius: 10px;
    padding: 15px 18px;
    margin-bottom: 22px;
    overflow-wrap: anywhere;
}

.success { background: #e3f5eb; color: #155d3b; }
.error { background: #fbe7e7; color: #952525; }

.timeline > div {
    border-left: 2px solid #dbe3ee;
    padding: 0 0 22px 20px;
}

.timeline > div:last-child { padding-bottom: 0; }
.timeline strong { font-size: 14px; }
.user-item { padding: 15px 0; border-bottom: 1px solid var(--line); }
.user-item .badge { margin-top: 8px; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }
.spaced { margin-top: 22px; }
.large-text { font-size: 19px; font-weight: 600; overflow-wrap: anywhere; }
.small-text { font-size: 12px; }
.break-word { overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: 25px 5px; }
.document-link { display: inline-block; padding: 8px 0; }

.pagination {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    padding-top: 22px;
    color: var(--muted);
    font-size: 13px;
}

.quick-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 22px;
}

.quick-links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 9px 14px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--navy);
    font-size: 14px;
    font-weight: 650;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.photo-card {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    background: #fafbfd;
}

.photo-card > a { display: block; }

.photo-card img {
    display: block;
    width: 100%;
    height: 210px;
    object-fit: cover;
    background: #e8edf3;
}

.photo-card figcaption { padding: 14px; overflow-wrap: anywhere; }
.photo-card figcaption p { margin: 10px 0; }
.upload-form { padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.upload-message { display: inline-block; margin: 8px 12px; font-size: 13px; }

.dispatch-box {
    background: white;
    border: 1px solid var(--line);
    border-left: 4px solid var(--orange);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 24px;
    min-width: 0;
}

.dispatch-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.dispatch-connection { font-size: 12px; color: var(--muted); }

.dispatch-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    margin-top: 12px;
}

.dispatch-message { font-size: 14px; margin: 12px 0 0; }
.dispatch-message:empty { display: none; }
.dispatch-list { display: grid; gap: 12px; margin-top: 14px; }
.dispatch-list:empty { display: none; }

.dispatch-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 14px;
    background: #fff8ed;
    border: 1px solid #f1d4af;
    border-radius: 10px;
    overflow-wrap: anywhere;
}

.dispatch-item strong { display: block; margin-bottom: 5px; }
.dispatch-item > div:first-child { min-width: 0; font-size: 14px; }
.dispatch-actions { display: flex; gap: 8px; flex-shrink: 0; }
.dispatch-assignment p { margin: 14px 0 0; font-size: 14px; font-weight: 650; }

hr { border: 0; border-top: 1px solid var(--line); margin: 25px 0; }

.footer {
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    padding-top: 30px;
}

@media (max-width: 1050px) {
    .layout { grid-template-columns: 180px minmax(0, 1fr); }
    main { padding: 24px; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .company { display: none; }
    .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .topbar { padding: 12px 16px; gap: 12px; flex-wrap: wrap; }
    .brand { font-size: 20px; }
    .userbar { gap: 10px; font-size: 12px; }
    .layout { display: block; }

    .sidebar {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        padding: 10px;
    }

    .sidebar a {
        white-space: nowrap;
        margin: 0;
        padding: 10px 12px;
        font-size: 13px;
    }

    .sidebar-note { display: none; }
    main { padding: 20px 14px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .detail-grid, .two-columns { grid-template-columns: 1fr; }
    .card { padding: 18px; border-radius: 12px; }
    .stats { gap: 12px; }
    .stat span { font-size: 12px; }
    .stat strong { font-size: 31px; }
    .filters { flex-direction: column; align-items: stretch; }
    .filters select { width: 100%; }
    .desktop-orders { display: none; }
    .mobile-orders { display: grid; gap: 13px; }
    .document-data { grid-template-columns: 1fr; }
    .document-data dt { padding-bottom: 2px; border: 0; }
    .document-data dd { padding-top: 2px; }
    .auth-card { margin-top: 20px; }

    input:not([type="checkbox"]), select, textarea { font-size: 16px; }
    .photo-card img { height: 170px; }
    .dispatch-item { flex-direction: column; align-items: stretch; }
    .dispatch-actions { display: grid; grid-template-columns: 1fr 1fr; }
    .dispatch-actions .button { min-height: 44px; }
    .dispatch-box { padding: 15px; }
}

@media (max-width: 440px) {
    .photo-grid { grid-template-columns: 1fr; }
    .photo-card img { height: 230px; }
}

@media print {
    body { background: white; color: black; font-size: 11pt; }
    .topbar, .sidebar, .no-print, .notice.success { display: none !important; }
    .layout { display: block; }
    main { padding: 0; max-width: none; }

    .document-card {
        border: 0;
        box-shadow: none;
        padding: 0;
        max-width: none;
    }

    .document-data { grid-template-columns: 1fr 2fr; }
    .document-data dt, .document-data dd { break-inside: avoid; }
    .signature-image { break-inside: avoid; }
    a { color: black; }
}