/* =========================================================================
   MODULE PRODUCTION TRACKING SYSTEM -- stylesheet
   Fixed left sidebar + top bar, light content area, dense data tables.
   Color coding: gray=not started, blue=active, amber=warning, red=problem,
   green=completed/reconciled. Every status also carries a text label.
   ========================================================================= */

:root {
    --c-bg: #f4f5f7;
    --c-surface: #ffffff;
    --c-border: #dfe3e8;
    --c-text: #1f2530;
    --c-text-muted: #667085;
    --c-primary: #1d4ed8;
    --c-primary-dark: #1730a3;
    --c-sidebar-bg: #111827;
    --c-sidebar-text: #cbd5e1;
    --c-sidebar-active: #1f2937;
    --c-gray: #94a3b8;
    --c-blue: #2563eb;
    --c-green: #16a34a;
    --c-amber: #d97706;
    --c-red: #dc2626;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    font-size: 14px;
}
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Layout ------------------------------------------------------- */
#app-shell { display: flex; min-height: 100vh; }

#sidebar {
    width: 230px; flex-shrink: 0; background: var(--c-sidebar-bg); color: var(--c-sidebar-text);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
#sidebar .brand { padding: 18px 16px; font-weight: 700; color: #fff; font-size: 15px; border-bottom: 1px solid #1f2937; }
#sidebar .brand small { display: block; font-weight: 400; color: #9ca3af; font-size: 11px; margin-top: 2px; }
#sidebar nav { flex: 1; padding: 8px 0; }
#sidebar .nav-group { margin-top: 14px; padding: 0 16px 4px; font-size: 11px; letter-spacing: .06em; color: #6b7280; text-transform: uppercase; }
#sidebar a.nav-link {
    display: flex; align-items: center; gap: 8px; padding: 8px 16px; color: var(--c-sidebar-text);
    font-size: 13.5px; border-left: 3px solid transparent;
}
#sidebar a.nav-link:hover { background: var(--c-sidebar-active); text-decoration: none; }
#sidebar a.nav-link.active { background: var(--c-sidebar-active); border-left-color: var(--c-primary); color: #fff; font-weight: 600; }

#main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
    height: 56px; background: var(--c-surface); border-bottom: 1px solid var(--c-border);
    display: flex; align-items: center; justify-content: space-between; padding: 0 20px; position: sticky; top: 0; z-index: 20;
}
#topbar .search-box input { width: 320px; }
#topbar .user-menu { display: flex; align-items: center; gap: 12px; font-size: 13px; }
#topbar .role-pill { background: #eef2ff; color: #3730a3; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }

#content { padding: 20px 24px 60px; overflow-x: hidden; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.page-header h1 { font-size: 19px; margin: 0; }
.page-header .subtitle { color: var(--c-text-muted); font-size: 12.5px; margin-top: 2px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Cards / KPI ---------------------------------------------------- */
.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi-card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi-card .kpi-value { font-size: 24px; font-weight: 700; line-height: 1.1; }
.kpi-card .kpi-label { color: var(--c-text-muted); font-size: 11.5px; margin-top: 4px; text-transform: uppercase; letter-spacing: .03em; }
.kpi-card.warn .kpi-value { color: var(--c-amber); }
.kpi-card.danger .kpi-value { color: var(--c-red); }
.kpi-card.good .kpi-value { color: var(--c-green); }

.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.grid-2 > .card { min-width: 0; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--c-text-muted); margin: 0 0 10px; }

/* ---- Tables ---------------------------------------------------------- */
.table-wrap { overflow-x: auto; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
table.data-table th, table.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--c-border); text-align: left; }
table.data-table thead th { position: sticky; top: 0; background: #f8fafc; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--c-text-muted); z-index: 1; }
table.data-table tbody tr:hover { background: #f8fafc; }
table.data-table td.num, table.data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data-table td.sticky-col, table.data-table th.sticky-col { position: sticky; left: 0; background: inherit; z-index: 2; }
table.data-table tbody tr:hover td.sticky-col { background: #f8fafc; }
table.data-table tfoot td { font-weight: 700; border-top: 2px solid var(--c-border); background: #f8fafc; }
.text-muted { color: var(--c-text-muted); }
.empty-state { padding: 40px 20px; text-align: center; color: var(--c-text-muted); }

/* ---- Badges / status pills -------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.gray   { background: #f1f5f9; color: #475569; }
.badge.blue   { background: #dbeafe; color: #1d4ed8; }
.badge.green  { background: #dcfce7; color: #15803d; }
.badge.amber  { background: #fef3c7; color: #b45309; }
.badge.red    { background: #fee2e2; color: #b91c1c; }

/* ---- Stage tracker ----------------------------------------------------- */
.stage-tracker { display: flex; align-items: center; gap: 0; overflow-x: auto; padding: 4px 0; }
.stage-step { display: flex; flex-direction: column; align-items: center; min-width: 88px; text-align: center; }
.stage-dot { width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 700; }
.stage-dot.NOT_STARTED { background: var(--c-gray); }
.stage-dot.IN_PROGRESS { background: var(--c-blue); }
.stage-dot.COMPLETED { background: var(--c-green); }
.stage-dot.PROBLEM { background: var(--c-red); }
.stage-label { font-size: 10.5px; margin-top: 4px; color: var(--c-text-muted); max-width: 88px; }
.stage-connector { flex: 1; height: 2px; background: var(--c-border); min-width: 16px; margin-top: -18px; }

/* ---- Forms --------------------------------------------------------- */
label { display: block; font-size: 12.5px; font-weight: 600; margin: 10px 0 4px; color: #344054; }
input, select, textarea {
    width: 100%; padding: 7px 9px; border: 1px solid var(--c-border); border-radius: var(--radius);
    font-size: 13.5px; font-family: inherit; background: #fff; color: var(--c-text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--c-primary); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; }
.form-hint { font-size: 11.5px; color: var(--c-text-muted); margin-top: 3px; }
.form-error { color: var(--c-red); font-size: 12px; margin-top: 4px; }
fieldset { border: 1px solid var(--c-border); border-radius: var(--radius); margin: 14px 0; padding: 12px 14px; }
legend { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--c-text-muted); padding: 0 6px; }

/* ---- Buttons ------------------------------------------------------- */
button, .btn {
    display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
    padding: 7px 14px; border-radius: var(--radius); border: 1px solid var(--c-border);
    background: #fff; color: var(--c-text); font-size: 13px; font-weight: 600; font-family: inherit;
}
button:hover, .btn:hover { background: #f8fafc; }
button.primary, .btn.primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--c-primary-dark); }
button.danger, .btn.danger { background: #fff; border-color: var(--c-red); color: var(--c-red); }
button.danger:hover { background: #fef2f2; }
button.success { background: var(--c-green); border-color: var(--c-green); color: #fff; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.small, .btn.small { padding: 4px 9px; font-size: 12px; }
button.icon-only { padding: 6px 8px; }
.link-btn { background: none; border: none; color: var(--c-primary); padding: 0; font-weight: 600; }
.link-btn:hover { text-decoration: underline; background: none; }

/* ---- Tabs ------------------------------------------------------------ */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--c-border); margin-bottom: 16px; flex-wrap: wrap; }
.tab-btn { padding: 9px 14px; background: none; border: none; border-bottom: 2px solid transparent; font-size: 13px; font-weight: 600; color: var(--c-text-muted); border-radius: 0; }
.tab-btn.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }
.tab-btn:hover { background: #eef2f7; }

/* ---- Modal ----------------------------------------------------------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; overflow-y: auto; padding: 40px 16px; }
.modal { background: #fff; border-radius: 8px; width: 100%; max-width: 640px; box-shadow: 0 20px 40px rgba(0,0,0,.2); }
.modal.wide { max-width: 920px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--c-border); }
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-body { padding: 16px 18px; max-height: 70vh; overflow-y: auto; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close { background: none; border: none; font-size: 20px; line-height: 1; color: var(--c-text-muted); padding: 2px 6px; }

/* ---- Toasts ----------------------------------------------------------- */
#toast-stack { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.toast { padding: 10px 14px; border-radius: var(--radius); background: #1f2937; color: #fff; font-size: 13px; box-shadow: 0 6px 16px rgba(0,0,0,.2); }
.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }
.toast.warn { background: #b45309; }

/* ---- Alerts / exception feed ------------------------------------------ */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 8px; border: 1px solid transparent; }
.alert.high { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert.medium { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert .alert-badge { flex-shrink: 0; font-weight: 700; font-size: 11px; text-transform: uppercase; }

/* ---- Progress bar ------------------------------------------------------ */
.progress-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.progress-row .label { width: 130px; font-size: 12.5px; color: var(--c-text-muted); flex-shrink: 0; }
.progress-track { flex: 1; background: #eef1f5; border-radius: 999px; height: 10px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--c-primary); border-radius: 999px; }
.progress-pct { width: 42px; text-align: right; font-size: 12px; font-weight: 600; flex-shrink: 0; }

/* ---- Login page -------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #0f172a, #1e3a8a); }
.login-card { background: #fff; padding: 32px; border-radius: 10px; width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-card h1 { font-size: 18px; margin: 0 0 2px; }
.login-card .subtitle { color: var(--c-text-muted); font-size: 12.5px; margin-bottom: 20px; }
.login-error { background: #fef2f2; color: #b91c1c; padding: 8px 10px; border-radius: var(--radius); font-size: 12.5px; margin-bottom: 12px; }
.login-demo-hint { margin-top: 16px; font-size: 11.5px; color: var(--c-text-muted); text-align: center; }

/* ---- Utility ------------------------------------------------------------ */
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.flex { display: flex; } .items-center { align-items: center; } .gap-8 { gap: 8px; } .gap-4 { gap: 4px; }
.spacer { flex: 1; }
.pill-input-group { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filter-bar select, .filter-bar input { width: auto; min-width: 140px; }
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 10px; font-size: 12.5px; }
.hidden { display: none !important; }

/* ---- Print --------------------------------------------------------- */
@media print {
    #sidebar, #topbar, .toolbar, .no-print { display: none !important; }
    #content { padding: 0; }
    body { background: #fff; }
    .card, .table-wrap { box-shadow: none; border: 1px solid #999; }
}
