:root {
    --bg: #f1f5f9;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --border-soft: #e2e8f0;
    --primary: #2563eb;
    --surface: #ffffff;
    --radius-lg: 10px;
    --radius-md: 8px;
    --sticky-1-w: 128px;
    --sticky-2-w: 300px;
    --sidebar-bg: #ffffff;
    --sidebar-border: #e5e7eb;
    --sidebar-active-bg: #f3f4f6;
    --sidebar-hover-bg: #f9fafb;
    --sidebar-danger: #ef4444;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    overflow: hidden;
    font-family: Inter, system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

.topbar { display: none; }

.app-shell {
    display: flex;
    height: 100vh;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

/* —— ERP-style sidebar (1:1) —— */
.panel-sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    height: 100vh;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    width: var(--sidebar-width);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-x: hidden;
    overflow-y: auto;
}
.panel-sidebar.collapsed { width: var(--sidebar-collapsed-width); }

.sidebar-header {
    padding: 28px 20px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.logo-link { display: block; text-decoration: none; max-width: 100%; width: 100%; text-align: center; }
.logo-full {
    display: block;
    height: auto;
    width: 100%;
    max-width: 220px;
    max-height: 120px;
    margin: 0 auto;
    object-fit: contain;
}
.logo-collapsed {
    display: none;
    height: 40px;
    width: auto;
    max-width: 48px;
    margin: 0 auto;
    object-fit: contain;
    border-radius: 5px;
}
.panel-sidebar.collapsed .logo-full { display: none; }
.panel-sidebar.collapsed .logo-collapsed { display: block; }
.logo-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #111827;
}
.logo-fallback.logo-collapsed { display: none; }
.panel-sidebar.collapsed .logo-fallback.logo-full { display: none; }
.panel-sidebar.collapsed .logo-fallback.logo-collapsed { display: flex; justify-content: center; }
.logo-fallback strong {
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}
.brand-mark {
    width: 36px; height: 36px; border-radius: 8px;
    background: #eff6ff; color: #2563eb;
    display: grid; place-items: center; font-size: 15px;
    flex-shrink: 0;
}

.sidebar-separator {
    height: 1px;
    background: var(--sidebar-border);
    margin: 0 24px;
    flex-shrink: 0;
}

.panel-sidebar .sidebar-nav {
    flex: 1;
    padding: 32px 16px;
    overflow-y: auto;
    min-height: 0;
    display: block;
}
.panel-sidebar .sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.sidebar-link {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    color: #4b5563;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    font-size: 15px;
    border: none;
    background: none;
    width: 100%;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}
.sidebar-link:hover {
    color: #111827;
    background: var(--sidebar-hover-bg);
}
.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: #111827;
    font-weight: 600;
}
.icon-wrapper {
    width: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    font-size: 18px;
    color: #6b7280;
    flex-shrink: 0;
}
.sidebar-link:hover .icon-wrapper,
.sidebar-link.active .icon-wrapper { color: #111827; }
.link-text { white-space: nowrap; }

.panel-sidebar.collapsed .sidebar-link {
    padding: 12px;
    justify-content: center;
}
.panel-sidebar.collapsed .icon-wrapper { margin-right: 0; }
.panel-sidebar.collapsed .link-text { display: none; }

.sidebar-footer {
    padding: 24px 16px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}
.logout-link { color: var(--sidebar-danger) !important; }
.logout-link .icon-wrapper { color: var(--sidebar-danger) !important; }
.logout-link:hover { background: #fef2f2 !important; }
.collapse-btn {
    margin-top: 8px;
    color: #9ca3af !important;
}
.panel-sidebar:not(.collapsed) .collapse-btn { justify-content: flex-start; }
.panel-sidebar.collapsed .collapse-btn .icon-wrapper { margin-right: 0; }

.mobile-close-btn {
    display: none !important;
    background: none;
    border: none;
    font-size: 20px;
    color: #6b7280;
    cursor: pointer;
    position: absolute;
    right: 16px;
    top: 16px;
}

.app-main {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}
.content-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    background: #fff;
    border-bottom: 1px solid var(--border-soft);
    flex-shrink: 0;
}
.content-head-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.content-head h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -0.02em;
}
.content-head h1 i { color: #2563eb; font-size: 16px; }
.sidebar-toggle,
.mobile-toggle {
    display: none;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #334155;
    cursor: pointer;
    place-items: center;
}
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 90;
}
.sidebar-backdrop[hidden] { display: none !important; }

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo {
    height: 40px;
    max-width: 160px;
    object-fit: contain;
    display: block;
}
.user-pill {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 12px; border-radius: 20px;
    background: #f8fafc; border: 1px solid #e2e8f0;
    font-size: 12px; font-weight: 700; color: #334155;
}
a.btn-soft {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.brand-text { min-width: 0; }
.brand-text strong {
    display: block;
    font-size: 14px;
    font-weight: 800;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.brand-text span {
    display: block;
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
    margin-top: 1px;
}
.topbar-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.live-pill {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 12px; border-radius: 20px;
    background: #f0fdf4; border: 1px solid #bbf7d0;
    font-size: 12px; font-weight: 700; color: #15803d;
}
.online-pill {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 12px; border-radius: 20px;
    background: #eff6ff; border: 1px solid #bfdbfe;
    font-size: 12px; font-weight: 700; color: #1d4ed8;
}
.online-pill i { font-size: 8px; color: #22c55e; }

.btn-soft, .btn-primary, .modal-close {
    font-family: inherit; cursor: pointer;
}
.btn-soft {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 14px; border-radius: 6px;
    background: #fff; border: 1px solid #cbd5e1;
    color: #334155; font-weight: 700; font-size: 13px;
}
.btn-soft:hover { background: #f8fafc; border-color: #94a3b8; }
.btn-primary {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 16px; border-radius: 6px; border: none;
    background: #16a34a; color: #fff; font-weight: 800; font-size: 13px;
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.2);
}
.btn-primary:hover { background: #15803d; }

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px 24px 12px;
    gap: 12px;
    min-height: 0;
    overflow: hidden;
}

.page-head {
    display: none;
}
.page-head h1 {
    margin: 0;
    font-size: 22px; font-weight: 800;
    display: flex; align-items: center; gap: 10px;
    letter-spacing: -0.02em;
}
.page-head h1 i { color: #2563eb; font-size: 18px; }
.sub {
    margin-top: 4px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}
.updated {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--muted);
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: 20px;
    padding: 7px 12px;
}
.page-head-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.view-switch { display: none; }
.view-tab { display: none; }

.workspace {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.workspace[hidden] { display: none !important; }
.workspace .table-shell { flex: 1; }

/* Clickable status filters */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    flex-shrink: 0;
}
.stat-card {
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    font: inherit;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.stat-card:hover {
    border-color: #bfdbfe;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.06);
}
.stat-card.is-active {
    border-color: #2563eb;
    background: #eff6ff;
    box-shadow: 0 0 0 1px #2563eb;
}
.stat-icon {
    width: 38px; height: 38px; border-radius: 10px;
    display: grid; place-items: center; font-size: 15px; flex-shrink: 0;
}
.stat-icon.blue { background: #eff6ff; color: #2563eb; }
.stat-icon.green { background: #f0fdf4; color: #16a34a; }
.stat-icon.purple { background: #faf5ff; color: #9333ea; }
.stat-icon.orange { background: #fff7ed; color: #ea580c; }
.stat-icon.slate { background: #f1f5f9; color: #475569; }
.stat-val { font-size: 20px; font-weight: 800; color: #0f172a; line-height: 1.15; }
.stat-lbl { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 2px; }

.controls-card {
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    flex-shrink: 0;
}
.search-wrap {
    position: relative;
    flex: 1;
    min-width: 220px;
    max-width: 420px;
}
.search-wrap i {
    position: absolute; right: 14px; top: 50%;
    transform: translateY(-50%);
    color: #94a3b8; font-size: 13px;
}
.search-input {
    width: 100%;
    padding: 10px 40px 10px 14px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    color: #0f172a;
    outline: none;
}
.search-input:focus {
    border-color: #2563eb;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.counter-badge {
    margin-left: auto;
    font-size: 12.5px;
    font-weight: 700;
    color: #2563eb;
    background: #eff6ff;
    padding: 6px 14px;
    border-radius: 20px;
}
#btnNewOrder {
    flex-shrink: 0;
}
.modal-body .edit-grid {
    margin-bottom: 0;
}

.table-shell {
    flex: 1 1 auto;
    min-height: 0;
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.table-scroll {
    height: 100%;
    overflow: auto;
    scrollbar-width: auto;
    scrollbar-color: #64748b #e2e8f0;
}
.table-scroll::-webkit-scrollbar { width: 12px; height: 14px; }
.table-scroll::-webkit-scrollbar-track {
    background: #e2e8f0;
    border-top: 1px solid #cbd5e1;
}
.table-scroll::-webkit-scrollbar-thumb {
    background: #64748b;
    border-radius: 8px;
    border: 3px solid #e2e8f0;
    min-width: 48px;
}
.table-scroll::-webkit-scrollbar-thumb:hover { background: #334155; }
.table-scroll::-webkit-scrollbar-corner { background: #e2e8f0; }

.plan-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13.5px;
    table-layout: fixed;
}
.plan-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    padding: 12px 14px;
    text-align: left;
    font-size: 11.5px;
    font-weight: 800;
    color: #334155;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
}
.plan-table thead th .col-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    bottom: 0;
    width: 8px;
    cursor: col-resize;
    z-index: 8;
}
.plan-table thead th .col-resizer:hover,
.plan-table thead th .col-resizer.is-active {
    background: rgba(37, 99, 235, 0.35);
}
body.col-resizing { cursor: col-resize !important; user-select: none !important; }
body.col-resizing * { cursor: col-resize !important; }
.th-sort {
    cursor: pointer;
    user-select: none;
}
.th-sort:hover { background: #eff6ff; color: #1d4ed8; }
.th-sort.is-sorted { color: #1d4ed8; background: #eff6ff; }
.th-sort .sort-ico {
    margin-left: 4px;
    opacity: 0.45;
    font-size: 11px;
}
.th-sort.is-sorted .sort-ico { opacity: 1; color: #2563eb; }
.c-grate-click { cursor: pointer; }
.c-grate-click:hover { outline: 1px dashed #fbbf24; outline-offset: -2px; }
.plan-table tbody td {
    padding: 14px;
    border-bottom: 1px solid #eef2f7;
    border-right: 1px solid #f1f5f9;
    vertical-align: middle;
    background: #fff;
    line-height: 1.4;
}
.plan-table tbody tr:hover td { background: #f8fafc; }
.plan-table tbody tr.row-status-wyslane td { background: #f8fdf9; }
.plan-table tbody tr.row-status-w_produkcji td { background: #f8fbff; }
.plan-table tbody tr.row-status-oczekujace td { background: #fffdf7; }
.plan-table tbody tr.row-status-anulowane td { background: #fffafa; }
.plan-table tbody tr.row-status-wyslane:hover td,
.plan-table tbody tr.row-status-w_produkcji:hover td,
.plan-table tbody tr.row-status-oczekujace:hover td,
.plan-table tbody tr.row-status-anulowane:hover td { filter: brightness(0.985); }

.loading-row td, .empty-row td {
    text-align: center;
    padding: 48px 16px;
    color: var(--muted);
    font-weight: 600;
    background: #fff !important;
}

.c-lp { width: 48px; min-width: 48px; text-align: center; font-weight: 800; color: #94a3b8; }
.c-order { min-width: var(--sticky-1-w); width: var(--sticky-1-w); font-weight: 800; color: #1e293b; white-space: nowrap; }
.order-cell { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.presence-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.presence-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 8px; border-radius: 999px;
    background: color-mix(in srgb, var(--u) 12%, #fff);
    border: 1px solid color-mix(in srgb, var(--u) 35%, #fff);
    color: var(--u);
    font-size: 10.5px; font-weight: 800;
    max-width: 140px;
}
.presence-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.presence-chip.is-typing { background: color-mix(in srgb, var(--u) 18%, #fff); }
.typing-dots { display: inline-flex; gap: 2px; align-items: center; }
.typing-dots i {
    width: 3px; height: 3px; border-radius: 50%; background: currentColor;
    display: inline-block; animation: typingBounce 1s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-2px); }
}
tr.is-being-edited td {
    box-shadow: inset 3px 0 0 var(--primary, #2563eb);
}
.live-preview {
    border: 1px solid color-mix(in srgb, var(--u) 40%, #e2e8f0);
    background: color-mix(in srgb, var(--u) 8%, #fff);
    border-radius: 10px;
    padding: 10px 12px;
    margin: 0 0 12px;
}
.live-preview-head {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    font-size: 12px; font-weight: 650; color: #334155;
}
.live-preview-head strong { color: var(--u); font-weight: 800; }
.live-preview-text {
    margin: 8px 0 0;
    white-space: pre-wrap;
    word-break: break-word;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.4;
}
.c-product { min-width: var(--sticky-2-w); width: var(--sticky-2-w); font-weight: 650; color: #0f172a; word-break: break-word; white-space: normal; }
.c-qty { min-width: 72px; width: 88px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.c-date { min-width: 110px; width: 120px; font-weight: 650; white-space: nowrap; color: #334155; }
.c-status { min-width: 130px; width: 140px; }
.c-line { min-width: 88px; width: 100px; font-weight: 700; color: #334155; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-comment, .c-grate { min-width: 180px; width: 220px; font-weight: 500; color: #334155; word-break: break-word; white-space: normal; }
.c-grate { color: #92400e; }
.c-actions { min-width: 100px; width: 110px; white-space: nowrap; }
.grate-text { margin-bottom: 6px; }
.muted { opacity: 0.55; font-weight: 600; }

/* Sticky Order + Product */
.sticky-col {
    position: sticky;
    z-index: 1;
    background: inherit;
}
thead .sticky-col { z-index: 4; background: #f8fafc; }
.sticky-1 { left: 0; box-shadow: 1px 0 0 #e2e8f0; }
.sticky-2 { left: var(--sticky-1-w); box-shadow: 2px 0 8px rgba(15, 23, 42, 0.04); }
tbody .sticky-1, tbody .sticky-2 { background: #fff; }
tbody tr:hover .sticky-1,
tbody tr:hover .sticky-2 { background: #f8fafc; }
tbody tr.row-status-wyslane .sticky-1,
tbody tr.row-status-wyslane .sticky-2 { background: #f8fdf9; }
tbody tr.row-status-w_produkcji .sticky-1,
tbody tr.row-status-w_produkcji .sticky-2 { background: #f8fbff; }
tbody tr.row-status-oczekujace .sticky-1,
tbody tr.row-status-oczekujace .sticky-2 { background: #fffdf7; }
tbody tr.row-status-anulowane .sticky-1,
tbody tr.row-status-anulowane .sticky-2 { background: #fffafa; }

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 800;
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge-wyslane { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.badge-w_produkcji { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.badge-oczekujace { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.badge-anulowane { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

.status-readonly {
    display: flex;
    align-items: center;
    min-height: 38px;
}

/* Custom calendar dropdown */
.date-dd {
    position: relative;
    width: 100%;
    min-width: 150px;
}
.date-dd-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 11px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #0f172a;
    font: inherit;
    font-size: 13.5px;
    font-weight: 650;
    cursor: pointer;
    text-align: left;
}
.date-dd:not(.has-value) .date-dd-label { color: #94a3b8; }
.date-dd-btn i { color: #64748b; font-size: 13px; }
.date-dd.is-open .date-dd-btn,
.date-dd-btn:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.date-dd-panel {
    position: fixed;
    z-index: 200;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
}
.date-dd-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}
.date-dd-month {
    font-size: 13px;
    font-weight: 800;
    color: #0f172a;
    text-transform: none;
    letter-spacing: 0;
}
.date-dd-nav-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    color: #475569;
    cursor: pointer;
}
.date-dd-nav-btn:hover { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.date-dd-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 4px;
}
.date-dd-weekdays span {
    text-align: center;
    font-size: 10px;
    font-weight: 800;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 4px 0;
}
.date-dd-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}
.date-dd-day {
    height: 34px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #0f172a;
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
}
.date-dd-day:hover:not(:disabled) { background: #eff6ff; color: #1d4ed8; }
.date-dd-day.is-out { visibility: hidden; cursor: default; }
.date-dd-day.is-today { box-shadow: inset 0 0 0 1px #93c5fd; }
.date-dd-day.is-selected {
    background: #2563eb;
    color: #fff;
    font-weight: 800;
}
.date-dd-day.is-selected:hover { background: #1d4ed8; color: #fff; }
.date-dd-actions {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #f1f5f9;
}
.date-dd-clear,
.date-dd-today {
    border: none;
    background: transparent;
    color: #2563eb;
    font: inherit;
    font-size: 12px;
    font-weight: 750;
    cursor: pointer;
    padding: 4px 2px;
}
.date-dd-clear { color: #64748b; }
.date-dd-clear:hover { color: #0f172a; }
.date-dd-today:hover { color: #1d4ed8; }

.sheet-table-inner .date-dd-btn {
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 13px;
    min-height: 38px;
}

.edit-form {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px;
    margin: 4px 0 12px;
}
.edit-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}
.edit-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
}
.edit-field-full { grid-column: 1 / -1; }
.edit-field em {
    font-style: normal;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    color: #94a3b8;
    font-size: 11px;
    margin-left: 6px;
}
.edit-field input,
.edit-field select,
.edit-field textarea {
    font: inherit;
    font-size: 13.5px;
    font-weight: 650;
    text-transform: none;
    letter-spacing: 0;
    color: #0f172a;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 9px 11px;
    background: #fff;
    outline: none;
}
.edit-field textarea {
    resize: vertical;
    min-height: 96px;
    line-height: 1.45;
}
.edit-field input:focus,
.edit-field select:focus,
.edit-field textarea:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.detail-readonly { margin-top: 4px; }

.btn-edit-comment, .btn-details {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 6px;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}
.btn-edit-comment {
    margin-top: 4px;
    border: 1px solid #fde68a;
    background: #fffbeb;
    color: #b45309;
}
.btn-edit-comment:hover { background: #fef3c7; }
.btn-details {
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #475569;
}
.btn-details:hover { background: #f8fafc; color: #0f172a; border-color: #cbd5e1; }

.toast {
    position: fixed;
    top: 70px; right: 24px;
    z-index: 50;
    padding: 12px 16px;
    border-radius: 8px;
    background: #16a34a;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 8px 20px rgba(0,0,0,.12);
}
.toast.err { background: #dc2626; }

/* Details drawer */
.drawer[hidden] { display: none !important; }
.drawer {
    position: fixed; inset: 0; z-index: 10040;
}
.drawer-backdrop {
    position: absolute; inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
}
.drawer-panel {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: min(420px, 100%);
    background: #fff;
    border-left: 1px solid #e2e8f0;
    box-shadow: -12px 0 40px rgba(15, 23, 42, 0.12);
    display: flex;
    flex-direction: column;
    animation: drawerIn .22s cubic-bezier(.16, 1, .3, 1);
}
@keyframes drawerIn {
    from { transform: translateX(16px); opacity: 0.6; }
    to { transform: none; opacity: 1; }
}
.drawer-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid #eef2f7;
}
.drawer-head h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 800;
    line-height: 1.35;
    letter-spacing: -0.02em;
}
.drawer-body {
    padding: 8px 20px 16px;
    overflow: auto;
    flex: 1;
}
.drawer-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid #eef2f7;
    background: #fff;
    flex-shrink: 0;
}
.drawer-foot-right { display: flex; gap: 10px; }
.btn-danger-soft {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 14px; border-radius: 6px;
    background: #fff; border: 1px solid #fecaca;
    color: #b91c1c; font: inherit; font-weight: 700; font-size: 13px;
    cursor: pointer;
}
.btn-danger-soft:hover { background: #fef2f2; }
.comment-edit-box {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 10px;
    padding: 14px;
    margin: 8px 0 16px;
}
.comment-edit-box .field-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}
.hint-inline {
    font-size: 11px;
    font-weight: 600;
    color: #b45309;
    text-transform: none;
    letter-spacing: 0;
    opacity: 0.85;
}
#drawerComment {
    width: 100%;
    min-height: 110px;
    border-radius: 8px;
    border: 1px solid #fcd34d;
    background: #fff;
    color: #0f172a;
    padding: 12px 14px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.45;
    resize: vertical;
    outline: none;
}
#drawerComment:focus {
    border-color: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}
.detail-row {
    padding: 14px 0;
    border-bottom: 1px solid #f1f5f9;
}
.detail-label {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #94a3b8;
    margin-bottom: 6px;
}
.detail-value {
    font-size: 14px;
    font-weight: 650;
    color: #0f172a;
    line-height: 1.45;
    word-break: break-word;
}

.modal[hidden] { display: none !important; }
.modal {
    position: fixed; inset: 0; z-index: 10050;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(3px);
}
.modal-card {
    position: relative;
    width: min(520px, 100%);
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 16px 40px -12px rgba(15, 23, 42, 0.25);
    animation: modalIn .2s cubic-bezier(.16, 1, .3, 1);
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(10px) scale(.98); }
    to { opacity: 1; transform: none; }
}
.modal-head, .modal-foot {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
}
.modal-head { border-bottom: 1px solid #eef2f7; align-items: center; }
.modal-kicker {
    font-size: 11px; font-weight: 700;
    letter-spacing: .08em; text-transform: uppercase;
    color: #64748b; margin-bottom: 4px;
}
.modal-head h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -.02em;
}
.modal-close {
    width: 36px; height: 36px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    color: #64748b;
    display: grid; place-items: center;
    flex-shrink: 0;
}
.modal-close:hover { background: #f8fafc; color: #0f172a; }
.modal-body { padding: 18px 20px; }
.modal-product {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
    line-height: 1.4;
}
.field-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: #334155;
    margin-bottom: 8px;
}
#modalComment {
    width: 100%;
    min-height: 140px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #0f172a;
    padding: 12px 14px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.45;
    resize: vertical;
    outline: none;
}
#modalComment:focus {
    border-color: #2563eb;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.modal-foot {
    border-top: 1px solid #eef2f7;
    justify-content: flex-end;
    align-items: center;
}

/* Order desk list */
.desk-list-shell {
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 16px 18px;
}
.desk-list-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.desk-kicker {
    font-size: 11px; font-weight: 700;
    letter-spacing: .08em; text-transform: uppercase;
    color: #64748b; margin-bottom: 4px;
}
.desk-list-head h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.02em;
}
.desk-list-meta {
    font-size: 12.5px;
    font-weight: 700;
    color: #2563eb;
    background: #eff6ff;
    padding: 6px 12px;
    border-radius: 20px;
}
.desk-list {
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    flex: 1;
}
.desk-empty {
    text-align: center;
    padding: 48px 16px;
    color: var(--muted);
    font-weight: 650;
}
.desk-card {
    display: grid;
    grid-template-columns: minmax(100px, 140px) minmax(0, 1.6fr) 80px 110px 140px auto;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.desk-card:hover {
    border-color: #bfdbfe;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.06);
}
.desk-card .d-order { font-weight: 800; color: #0f172a; }
.desk-card .d-product {
    font-weight: 650; color: #1e293b;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.desk-card .d-qty { font-weight: 750; font-variant-numeric: tabular-nums; text-align: right; }
.desk-card .d-date { font-weight: 650; color: #334155; white-space: nowrap; }
.desk-card .d-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.sheet-table.wrap {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    overflow: auto;
    background: #fff;
}
.sheet-table-inner {
    width: 100%;
    min-width: 720px;
    border-collapse: separate;
    border-spacing: 0;
}
.sheet-table-inner thead th {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    padding: 10px 12px;
    text-align: left;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #475569;
    white-space: nowrap;
}
.sheet-table-inner thead th:last-child,
.sheet-table-inner tbody td:last-child { border-right: none; }
.sheet-table-inner tbody td {
    padding: 8px;
    border-right: 1px solid #f1f5f9;
    vertical-align: middle;
    background: #fff;
}
.sheet-table-inner input,
.sheet-table-inner select {
    width: 100%;
    border: 1px solid transparent;
    background: #f8fafc;
    border-radius: 6px;
    padding: 9px 10px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 650;
    color: #0f172a;
    outline: none;
}
.sheet-table-inner input:focus,
.sheet-table-inner select:focus {
    border-color: #2563eb;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.modal-card.modal-sheet {
    width: min(920px, 100%);
    border-radius: 14px;
}
.sheet-head { align-items: center; }
.sheet-brand { display: flex; align-items: center; gap: 12px; }
.sheet-icon {
    width: 44px; height: 44px; border-radius: 12px;
    background: #eff6ff; color: #2563eb;
    display: grid; place-items: center; font-size: 18px;
}
.sheet-lead {
    margin: 0 0 14px;
    color: #64748b;
    font-size: 13.5px;
    font-weight: 550;
    line-height: 1.45;
}
.sheet-note {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 14px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
}
.sheet-note textarea {
    font: inherit;
    font-size: 13.5px;
    font-weight: 650;
    text-transform: none;
    letter-spacing: 0;
    color: #0f172a;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 12px 14px;
    background: #f8fafc;
    resize: vertical;
    min-height: 84px;
    outline: none;
}
.sheet-note textarea:focus {
    border-color: #2563eb;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.btn-icon {
    width: 34px; height: 34px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #475569;
    display: grid; place-items: center;
    cursor: pointer;
}
.btn-icon:hover { background: #f8fafc; color: #0f172a; }
.btn-icon.danger:hover { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    :root { --sticky-2-w: 220px; }
}
@media (max-width: 980px) {
    .desk-card {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    .desk-card .d-product { grid-column: 1 / -1; }
    .desk-card .d-actions { grid-column: 1 / -1; justify-content: flex-start; }
}
@media (max-width: 1024px) {
    .panel-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        transform: translateX(-105%);
        transition: transform .2s ease;
        box-shadow: 8px 0 30px rgba(15, 23, 42, 0.18);
        width: var(--sidebar-width) !important;
    }
    body.sidebar-open .panel-sidebar,
    .panel-sidebar.is-open { transform: translateX(0); }
    .panel-sidebar.collapsed { width: var(--sidebar-width) !important; }
    .collapse-btn { display: none; }
    .sidebar-toggle,
    .mobile-toggle { display: grid; }
    .mobile-close-btn { display: flex !important; }
    .sidebar-header { padding-top: 48px; }
}

@media (max-width: 720px) {
    body { overflow: hidden; height: 100%; }
    .main { height: auto; padding: 14px; flex: 1; }
    .content-head { padding: 12px 14px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-card[data-status=""] { grid-column: 1 / -1; }
    .table-shell { min-height: 55vh; }
    .sticky-col { position: static; box-shadow: none; }
}
