/* =====================================================
   PALLET TRADING SYSTEM — STYLESHEET
   Aesthetic: refined industrial / warehouse-meets-editorial
   ===================================================== */

:root {
    /* Palette — warm parchment + deep ink + industrial amber */
    --bg:           #f4efe6;
    --bg-paper:    #fbf7ee;
    --ink:         #14110d;
    --ink-2:       #2d2820;
    --ink-3:       #5a5145;
    --ink-mute:    #8a7f6f;
    --line:        #d9d0bf;
    --line-soft:   #e8e0cf;
    --brand:       #1a1612;
    --accent:      #d97706;     /* amber */
    --accent-soft: #fef3c7;
    --green:       #15803d;
    --green-soft:  #dcfce7;
    --red:         #b91c1c;
    --red-soft:    #fee2e2;
    --blue:        #1d4ed8;
    --blue-soft:   #dbeafe;

    /* Typography */
    --font-display: 'Fraunces', 'Georgia', serif;
    --font-body:    'Geist', -apple-system, system-ui, sans-serif;
    --font-mono:    'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Subtle paper grain */
body::before {
    content: '';
    position: fixed; inset: 0;
    background-image: radial-gradient(circle at 1px 1px, rgba(20,17,13,.025) 1px, transparent 0);
    background-size: 16px 16px;
    pointer-events: none;
    z-index: 0;
}

a { color: var(--ink); text-decoration: none; }
a:hover { color: var(--accent); }

/* =====================================================
   LAYOUT
   ===================================================== */
.app {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

.sidebar {
    background: var(--brand);
    color: #f4efe6;
    padding: 28px 20px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    border-right: 1px solid #000;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 36px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-mark {
    width: 38px; height: 38px;
    background: var(--accent);
    color: #14110d;
    display: grid; place-items: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 16px;
    border-radius: 4px;
    letter-spacing: -0.02em;
}

.brand-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 17px;
    letter-spacing: -0.02em;
}

.brand-sub {
    font-size: 11px;
    color: rgba(244,239,230,0.5);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-top: 2px;
}

.nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 6px;
    color: rgba(244,239,230,0.7);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
}

.nav-item:hover {
    background: rgba(255,255,255,0.04);
    color: #f4efe6;
}

.nav-item.active {
    background: rgba(217,119,6,0.12);
    color: var(--accent);
}

.nav-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.5;
}

.nav-item.active .nav-dot { opacity: 1; }

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 16px;
}

.user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #14110d;
    display: grid; place-items: center;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 14px;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; color: #f4efe6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 2px;
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
}
.role-admin { background: rgba(217,119,6,0.2); color: var(--accent); }
.role-staff { background: rgba(29,78,216,0.2); color: #93c5fd; }
.role-viewer { background: rgba(255,255,255,0.08); color: rgba(244,239,230,0.6); }

.logout-btn {
    display: block;
    text-align: center;
    padding: 8px;
    background: rgba(255,255,255,0.04);
    border-radius: 5px;
    font-size: 12px;
    color: rgba(244,239,230,0.7) !important;
    border: 1px solid rgba(255,255,255,0.06);
}
.logout-btn:hover { background: rgba(185,28,28,0.15); color: #fca5a5 !important; border-color: rgba(185,28,28,0.3); }

.main {
    padding: 36px 44px;
    max-width: 100%;
    overflow-x: auto;
}

/* =====================================================
   PAGE HEAD
   ===================================================== */
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 32px;
    gap: 24px;
    flex-wrap: wrap;
}

.eyebrow {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--ink-mute);
    margin-bottom: 6px;
}

.page-title {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 44px;
    letter-spacing: -0.03em;
    line-height: 1;
    margin: 0 0 8px 0;
    font-variation-settings: 'opsz' 144, 'SOFT' 30;
}

.page-sub {
    color: var(--ink-3);
    margin: 0;
    font-size: 14px;
}

.page-actions { display: flex; gap: 10px; }

/* =====================================================
   KPI CARDS
   ===================================================== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 32px;
}
.kpi-grid-2 { grid-template-columns: repeat(2, 1fr); max-width: 600px; }

.kpi {
    background: var(--bg-paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 20px;
    position: relative;
    transition: transform 0.15s, box-shadow 0.15s;
}
.kpi:hover { transform: translateY(-1px); box-shadow: 0 8px 24px -8px rgba(20,17,13,0.08); }

.kpi-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-mute);
    margin-bottom: 8px;
}

.kpi-value {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 36px;
    letter-spacing: -0.03em;
    line-height: 1.05;
    color: var(--ink);
    font-variation-settings: 'opsz' 144;
}

.kpi-foot {
    font-size: 12px;
    color: var(--ink-3);
    margin-top: 6px;
}

.kpi-wide { grid-column: span 2; }
.kpi::before {
    content: '';
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 3px;
    border-radius: 8px 0 0 8px;
}
.kpi-amber::before { background: var(--accent); }
.kpi-green::before { background: var(--green); }
.kpi-red::before   { background: var(--red); }
.kpi-blue::before  { background: var(--blue); }

/* =====================================================
   PANELS / SECTIONS
   ===================================================== */
.panel {
    background: var(--bg-paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
    margin-bottom: 24px;
}
.panel-flush { padding: 0; overflow: hidden; }
.panel-flush .panel-head { padding: 20px 24px; border-bottom: 1px solid var(--line-soft); }

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

.panel-head h2 {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 22px;
    margin: 0;
    letter-spacing: -0.02em;
}

.link {
    color: var(--accent);
    font-size: 13px;
    font-weight: 500;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* =====================================================
   TABLES
   ===================================================== */
.table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead th {
    text-align: left;
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-mute);
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(0,0,0,0.015);
    white-space: nowrap;
}

.data-table tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}

.data-table tbody tr:hover { background: rgba(217,119,6,0.04); }

.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .mono { font-family: var(--font-mono); font-size: 12px; }

.text-red { color: var(--red); font-weight: 600; }
.muted { color: var(--ink-mute); }

.empty-cell {
    text-align: center;
    color: var(--ink-mute);
    padding: 48px 16px !important;
    font-style: italic;
}

.empty {
    text-align: center;
    color: var(--ink-mute);
    padding: 32px 16px;
    font-style: italic;
}

/* Route */
.route { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.route-arrow { color: var(--accent); font-weight: 600; }

/* =====================================================
   BADGES
   ===================================================== */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: lowercase;
    font-variant: small-caps;
    line-height: 1.4;
}
.badge-scheduled  { background: var(--accent-soft); color: #92400e; }
.badge-on_process { background: var(--blue-soft); color: var(--blue); }
.badge-delivered  { background: var(--green-soft); color: var(--green); }
.badge-cancelled  { background: #f3f4f6; color: #6b7280; }
.badge-cb-pending { background: var(--accent-soft); color: #92400e; }
.badge-cb-settled { background: var(--green-soft); color: var(--green); }
.badge-cb-cancelled { background: #f3f4f6; color: #6b7280; }
.badge-neutral    { background: rgba(20,17,13,0.06); color: var(--ink-2); }

/* =====================================================
   BUTTONS
   ===================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--bg-paper);
    color: var(--ink);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}
.btn:hover { border-color: var(--ink-3); background: #fff; }

.btn-primary { background: var(--ink); color: #fbf7ee; border-color: var(--ink); }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: #14110d; }

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(0,0,0,0.04); }

.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #991b1b; border-color: #991b1b; }

.btn-block { width: 100%; }

.icon-btn {
    width: 28px; height: 28px;
    display: inline-grid; place-items: center;
    border: 1px solid var(--line);
    background: transparent;
    border-radius: 5px;
    cursor: pointer;
    color: var(--ink-3);
    font-size: 14px;
    transition: all 0.15s;
}
.icon-btn:hover { background: var(--ink); color: var(--bg-paper); border-color: var(--ink); }
.icon-btn.icon-danger:hover { background: var(--red); border-color: var(--red); }

.actions-cell { white-space: nowrap; }
.actions-cell .icon-btn + .icon-btn { margin-left: 4px; }

/* =====================================================
   FORMS
   ===================================================== */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.field > span {
    font-size: 12px;
    font-weight: 500;
    color: var(--ink-2);
    letter-spacing: 0.01em;
}
.field input, .field select, .field textarea {
    font-family: inherit;
    font-size: 14px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(217,119,6,0.12);
}

.field-2 { grid-column: span 2; }

.form-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.form-row:has(.field:nth-child(3)) { grid-template-columns: repeat(3, 1fr); }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--line-soft);
    margin-top: 8px;
}

.filters {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: center;
}
.filter-search { flex: 1; min-width: 200px; }
.filters input, .filters select {
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    font-family: inherit;
    font-size: 13px;
}
.filters input:focus, .filters select:focus {
    outline: none; border-color: var(--accent);
}

/* =====================================================
   TABS
   ===================================================== */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 24px;
}
.tab {
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-3);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

/* =====================================================
   ALERTS
   ===================================================== */
.alert {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 12px;
    border-left: 3px solid;
}
.alert-error { background: var(--red-soft); color: var(--red); border-left-color: var(--red); }
.alert-warn  { background: var(--accent-soft); color: #92400e; border-left-color: var(--accent); }
.alert-info  { background: var(--blue-soft); color: var(--blue); border-left-color: var(--blue); }

/* =====================================================
   LIST ROWS (recent / cashbon)
   ===================================================== */
.list { display: flex; flex-direction: column; }
.list-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 14px 0;
    border-bottom: 1px solid var(--line-soft);
    gap: 16px;
}
.list-row:last-child { border-bottom: 0; padding-bottom: 0; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 500; font-size: 14px; margin-bottom: 2px; }
.list-sub { font-size: 12px; color: var(--ink-3); }
.list-side { text-align: right; flex-shrink: 0; }
.list-amount { font-family: var(--font-mono); font-size: 13px; font-weight: 600; }
.list-date { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.list-tag {
    display: inline-block;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    margin-top: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.tag-red { background: var(--red-soft); color: var(--red); }
.tag-green { background: var(--green-soft); color: var(--green); }

/* =====================================================
   MATRIX
   ===================================================== */
.matrix-table .matrix-cell {
    cursor: pointer;
    transition: background 0.15s;
    min-width: 140px;
}
.matrix-table .matrix-cell:hover { background: var(--accent-soft); }
.matrix-table .no-price { color: var(--ink-mute); }
.cell-price { font-family: var(--font-mono); font-weight: 600; font-size: 13px; }
.cell-unit { font-size: 11px; color: var(--ink-mute); margin-top: 2px; }

/* =====================================================
   MODAL
   ===================================================== */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(20,17,13,0.5);
    display: grid; place-items: center;
    z-index: 100;
    padding: 20px;
    backdrop-filter: blur(2px);
}
.modal-backdrop[hidden] { display: none; }

.modal {
    background: var(--bg-paper);
    border-radius: 10px;
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 64px -12px rgba(0,0,0,0.3);
    animation: modalIn 0.2s ease-out;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--line-soft);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 22px;
    margin: 0;
    letter-spacing: -0.02em;
}
.modal-close {
    border: none; background: transparent;
    font-size: 24px; cursor: pointer;
    color: var(--ink-3);
    width: 32px; height: 32px; border-radius: 4px;
    display: grid; place-items: center;
}
.modal-close:hover { background: rgba(0,0,0,0.05); color: var(--ink); }
.modal-body { padding: 20px 24px; overflow-y: auto; }

/* =====================================================
   TOAST
   ===================================================== */
.toast {
    position: fixed;
    bottom: 24px; right: 24px;
    background: var(--ink);
    color: #fbf7ee;
    padding: 12px 18px;
    border-radius: 6px;
    font-size: 13px;
    z-index: 200;
    animation: toastIn 0.25s ease-out;
    box-shadow: 0 10px 24px -8px rgba(0,0,0,0.3);
}
.toast.toast-error { background: var(--red); }
.toast.toast-success { background: var(--green); }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================
   LOGIN PAGE
   ===================================================== */
.login-page { background: var(--bg); min-height: 100vh; }

.login-grid {
    display: grid;
    grid-template-columns: 5fr 4fr;
    min-height: 100vh;
}

.login-art {
    background: var(--ink);
    color: var(--bg-paper);
    padding: 60px;
    display: flex;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.login-art::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 80% 20%, rgba(217,119,6,0.18) 0%, transparent 50%),
        radial-gradient(circle at 10% 90%, rgba(217,119,6,0.08) 0%, transparent 50%);
}

.login-art-inner { position: relative; z-index: 1; max-width: 480px; }

.login-mark {
    width: 56px; height: 56px;
    background: var(--accent);
    color: #14110d;
    display: grid; place-items: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 22px;
    border-radius: 8px;
    margin-bottom: 40px;
}

.login-display {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(56px, 8vw, 88px);
    line-height: 0.95;
    letter-spacing: -0.04em;
    margin: 0 0 24px 0;
    font-variation-settings: 'opsz' 144, 'SOFT' 50;
}

.login-tagline {
    font-size: 16px;
    color: rgba(251,247,238,0.7);
    line-height: 1.6;
    max-width: 400px;
    margin: 0 0 56px 0;
}

.login-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 32px;
}
.login-stats > div { display: flex; flex-direction: column; gap: 4px; }
.stat-num {
    font-family: var(--font-display);
    font-size: 28px;
    color: var(--accent);
    font-weight: 500;
    letter-spacing: -0.02em;
}
.stat-lbl {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(251,247,238,0.5);
}

.login-form-wrap {
    display: grid;
    place-items: center;
    padding: 40px;
}
.login-form {
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.login-form-head { margin-bottom: 8px; }
.login-form-head h2 {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 32px;
    margin: 0 0 6px 0;
    letter-spacing: -0.02em;
}
.login-form-head p { color: var(--ink-3); margin: 0; font-size: 14px; }
.login-foot {
    text-align: center;
    font-size: 12px;
    color: var(--ink-mute);
    margin: 24px 0 0 0;
}

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 1024px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: relative;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 16px;
    }
    .brand { margin-bottom: 0; padding-bottom: 0; border: none; flex: 1; }
    .nav { flex-direction: row; flex-wrap: wrap; flex: 0 0 100%; margin-top: 12px; }
    .nav-item { padding: 8px 12px; font-size: 13px; }
    .sidebar-footer { flex: 0 0 auto; border: none; padding-top: 0; }
    .user-card { margin-bottom: 0; }
    .logout-btn { display: none; }
    .main { padding: 24px 18px; }
    .page-title { font-size: 32px; }
    .kpi-grid { grid-template-columns: 1fr; }
    .login-grid { grid-template-columns: 1fr; }
    .login-art { padding: 40px 24px; min-height: 280px; }
    .login-display { font-size: 48px; }
    .form-row { grid-template-columns: 1fr; }
}
