/* ============================================================
   TD-OPS | app.css — Dark Industrial Design System
   Font: IBM Plex Mono (data) + Syne (headings)
   ============================================================ */

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

:root {
    --bg-base:      #0a0b0d;
    --bg-surface:   #111318;
    --bg-elevated:  #181b22;
    --bg-input:     #1e222b;
    --bg-hover:     #232730;

    --border:       #2a2f3a;
    --border-soft:  #1e2229;

    --text-primary: #e8eaf0;
    --text-secondary:#8891a4;
    --text-muted:   #4d5566;

    --accent:       #FF3D00;
    --accent-soft:  rgba(255,61,0,.12);
    --accent-hover: #ff5722;

    --green:        #22c55e;
    --green-soft:   rgba(34,197,94,.1);
    --red:          #ef4444;
    --red-soft:     rgba(239,68,68,.1);
    --yellow:       #f59e0b;
    --yellow-soft:  rgba(245,158,11,.1);
    --blue:         #3b82f6;
    --blue-soft:    rgba(59,130,246,.1);

    --font-mono:    'JetBrains Mono', 'Fira Code', monospace;
    --font-display: 'Inter', sans-serif;

    --sidebar-w:    240px;
    --header-h:     60px;
    --radius:       8px;
    --radius-lg:    12px;
    --shadow:       0 4px 24px rgba(0,0,0,.4);
}

/* ── Light theme ─────────────────────────────────────────── */

[data-theme="light"] {
    --bg-base:       #f0f2f5;
    --bg-surface:    #ffffff;
    --bg-elevated:   #f8f9fb;
    --bg-input:      #f0f2f5;
    --bg-hover:      #e8eaf0;

    --border:        #d1d5e0;
    --border-soft:   #e4e7ef;

    --text-primary:  #111318;
    --text-secondary:#4d5566;
    --text-muted:    #8891a4;

    --accent:        #FF3D00;
    --accent-soft:   rgba(255,61,0,.08);
    --accent-hover:  #ff5722;

    --green:         #16a34a;
    --green-soft:    rgba(22,163,74,.1);
    --red:           #dc2626;
    --red-soft:      rgba(220,38,38,.1);
    --yellow:        #d97706;
    --yellow-soft:   rgba(217,119,6,.1);
    --blue:          #2563eb;
    --blue-soft:     rgba(37,99,235,.1);

    --shadow:        0 4px 24px rgba(0,0,0,.08);
}

/* ── Base ────────────────────────────────────────────────── */

html { font-size: 15px; }
body {
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-display);
    display: flex;
    min-height: 100vh;
    line-height: 1.6;
    transition: background .2s, color .2s;
}

/* ── Theme toggle ────────────────────────────────────────── */

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    font-size: .72rem;
    font-family: var(--font-mono);
    font-weight: 600;
    letter-spacing: .05em;
    transition: all .15s;
    white-space: nowrap;
}
.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.theme-toggle svg { flex-shrink: 0; }

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

input, select, textarea, button {
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── SIDEBAR ─────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform .25s ease;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    border-bottom: 1px solid var(--border-soft);
}

.logo-text {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -.03em;
}
.logo-text span { color: var(--accent); }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 0;
}

.nav-section {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 14px 18px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    color: var(--text-secondary);
    transition: all .15s;
    font-size: 0.82rem;
    border-left: 2px solid transparent;
    margin: 1px 0;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }
.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-left-color: var(--border);
}
.nav-item.active {
    background: var(--accent-soft);
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 600;
}
.nav-item.active svg { opacity: 1; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--border-soft);
}
.user-avatar {
    width: 32px; height: 32px;
    background: var(--accent);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 0.8rem; font-weight: 600; truncate: ellipsis; overflow: hidden; white-space: nowrap; }
.user-role { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.logout-btn { color: var(--text-muted); padding: 4px; border-radius: 4px; transition: color .15s; }
.logout-btn:hover { color: var(--red); }

/* ── MAIN CONTENT ────────────────────────────────────────── */

.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.page-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    border-bottom: 1px solid var(--border-soft);
    position: sticky;
    top: 0;
    background: var(--bg-base);
    backdrop-filter: blur(8px);
    z-index: 50;
    gap: 16px;
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 8px; }

.page-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -.02em;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

.page-body {
    padding: 28px;
    flex: 1;
}

/* ── CARDS ───────────────────────────────────────────────── */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 12px;
}

.card-title {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -.01em;
}

/* ── STAT CARDS ──────────────────────────────────────────── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--accent);
    opacity: .6;
}

.stat-label {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
    letter-spacing: -.01em;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }
.stat-value.accent   { color: var(--accent); }

.stat-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── BUTTONS ─────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    border: 1px solid transparent;
    text-decoration: none;
    white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border-color: var(--border);
}
.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger {
    background: var(--red-soft);
    color: var(--red);
    border-color: rgba(239,68,68,.2);
}
.btn-danger:hover { background: var(--red); color: #fff; }

.btn-sm { padding: 5px 10px; font-size: 0.75rem; }
.btn-lg { padding: 11px 22px; font-size: 0.9rem; }

/* ── TABLES ──────────────────────────────────────────────── */

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-soft);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

thead th {
    padding: 10px 14px;
    text-align: left;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-soft);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border-soft);
    transition: background .1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

td {
    padding: 10px 14px;
    color: var(--text-secondary);
    vertical-align: middle;
}

td.mono { font-family: var(--font-mono); }
td.bold { color: var(--text-primary); font-weight: 500; }
td.positive { color: var(--green); }
td.negative { color: var(--red); }
td.accent { color: var(--accent); font-weight: 600; }

/* ── BADGES ──────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: .04em;
    white-space: nowrap;
}

.badge-green   { background: var(--green-soft);  color: var(--green);  }
.badge-red     { background: var(--red-soft);    color: var(--red);    }
.badge-yellow  { background: var(--yellow-soft); color: var(--yellow); }
.badge-blue    { background: var(--blue-soft);   color: var(--blue);   }
.badge-gray    { background: var(--bg-elevated); color: var(--text-muted); }
.badge-accent  { background: var(--accent-soft); color: var(--accent); }

/* ── FORMS ───────────────────────────────────────────────── */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

input, select, textarea {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    padding: 9px 12px;
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder { color: var(--text-muted); }
select option { background: var(--bg-input); }
textarea { resize: vertical; min-height: 80px; }

.form-actions {
    display: flex;
    gap: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border-soft);
    margin-top: 16px;
}

/* ── FLASH ───────────────────────────────────────────────── */

.flash {
    margin: 0 28px 12px;
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: fadeIn .2s ease;
}
.flash-success { background: var(--green-soft);  border: 1px solid rgba(34,197,94,.2);  color: var(--green);  }
.flash-error   { background: var(--red-soft);    border: 1px solid rgba(239,68,68,.2);  color: var(--red);    }
.flash-warning { background: var(--yellow-soft); border: 1px solid rgba(245,158,11,.2); color: var(--yellow); }
.flash-info    { background: var(--blue-soft);   border: 1px solid rgba(59,130,246,.2); color: var(--blue);   }

/* ── FILTERS BAR ─────────────────────────────────────────── */

.filters-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 320px;
}

.search-box svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-box input { padding-left: 32px; }

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-group select { min-width: 130px; }

/* ── DASHBOARD GRID ──────────────────────────────────────── */

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

.dashboard-table-section {
    background: var(--bg-surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.section-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-soft);
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ── INLINE EDIT ─────────────────────────────────────────── */

.inline-select {
    background: transparent;
    border: none;
    color: inherit;
    font-size: inherit;
    font-family: inherit;
    cursor: pointer;
    padding: 0;
    width: auto;
}
.inline-select:focus { outline: none; }

/* ── EMPTY STATE ─────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: .4;
}
.empty-state h3 {
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.empty-state p { font-size: 0.8rem; }

/* ── STATUS BADGES helpers ───────────────────────────────── */

.status-open     { @extend .badge; background: var(--blue-soft);   color: var(--blue);   }
.status-partial  { @extend .badge; background: var(--yellow-soft); color: var(--yellow); }
.status-closed   { @extend .badge; background: var(--green-soft);  color: var(--green);  }
.status-writeoff { @extend .badge; background: var(--red-soft);    color: var(--red);    }

/* ── LOT DETAIL GRID ─────────────────────────────────────── */

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.detail-item { }
.detail-label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 3px;
}
.detail-value {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
}

/* ── PROFIT INDICATOR ────────────────────────────────────── */

.profit-bar {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
}
.profit-fill {
    height: 100%;
    border-radius: 2px;
    background: var(--green);
    transition: width .4s ease;
}
.profit-fill.negative { background: var(--red); }

/* ── TABS ────────────────────────────────────────────────── */

.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 20px;
}

.tab {
    padding: 10px 18px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    transition: all .15s;
}
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── PAGINATION ──────────────────────────────────────────── */

.pagination {
    display: flex;
    gap: 4px;
    align-items: center;
    justify-content: center;
    padding: 16px 0;
}
.page-btn {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.78rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
}
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── AUTH (login / register) ─────────────────────────────── */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-base);
    padding: 20px;
}

.auth-box {
    width: 100%;
    max-width: 380px;
    background: var(--bg-surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: var(--shadow);
}

.auth-logo {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 900;
    text-align: center;
    margin-bottom: 32px;
    letter-spacing: -.05em;
}
.auth-logo span { color: var(--accent); }

.auth-box h1 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 6px;
}
.auth-box p {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 28px;
}

.auth-form .form-group { gap: 8px; }
.auth-form label { font-size: 0.72rem; }
.auth-form input { padding: 11px 14px; }

.auth-submit {
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 0.9rem;
    margin-top: 8px;
}

.auth-link {
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 20px;
}
.auth-link a { color: var(--accent); }

/* ── ANIMATIONS ──────────────────────────────────────────── */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading { animation: spin 1s linear infinite; }

.fade-in { animation: fadeIn .25s ease; }

/* ── RESPONSIVE ──────────────────────────────────────────── */

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(calc(-1 * var(--sidebar-w)));
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.5);
    }
    .main-content { margin-left: 0; }
    .mobile-menu-btn { display: flex; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .page-body { padding: 16px; }
}

@media (max-width: 580px) {
    .stats-grid { grid-template-columns: 1fr; }
    .form-grid  { grid-template-columns: 1fr; }
}

/* ── TOOLTIP ─────────────────────────────────────────────── */

[data-tip] {
    position: relative;
    cursor: help;
}
[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #1e2229;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s;
    z-index: 200;
}
[data-tip]:hover::after { opacity: 1; }

/* ── MISC ────────────────────────────────────────────────── */

.divider {
    border: none;
    border-top: 1px solid var(--border-soft);
    margin: 20px 0;
}

.text-right { text-align: right; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.w-full { width: 100%; }

.code {
    font-family: var(--font-mono);
    background: var(--bg-elevated);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.82em;
    color: var(--text-primary);
}

/* ── TRANSFER TABLE specific ─────────────────────────────── */

.urgency-high   { color: var(--red);    font-weight: 600; }
.urgency-medium { color: var(--yellow); font-weight: 600; }
.urgency-low    { color: var(--green); }