/* ============================================================
   ProdFlow Design System
   Display: Sora | Body: Inter | Data/Codes: IBM Plex Mono
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
    --ink: #0f172a;
    --panel: #ffffff;
    --bg: #eef1f6;
    --line: #dde3ec;
    --muted: #64748b;
    --faint: #94a3b8;

    --primary: #1d4ed8;
    --primary-ink: #1e3a8a;
    --primary-soft: #e8eefc;

    --accent: #ea580c;
    --accent-soft: #fef1e7;

    --success: #16a34a;
    --success-soft: #eafaf0;
    --danger: #dc2626;
    --danger-soft: #fdecec;
    --warn: #d97706;
    --warn-soft: #fef6e7;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 2px rgba(15,23,42,.04), 0 8px 24px -12px rgba(15,23,42,.12);
    --sidebar-w: 236px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand { font-family: 'Sora', sans-serif; }

code, .mono, .num, td.mono { font-family: 'IBM Plex Mono', monospace; }

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

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

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--ink);
    color: #cbd5e1;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar .brand {
    color: #fff;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: .2px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 20px;
}
.sidebar .brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(234,88,12,.25); }

.nav-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: #64748b;
    padding: 16px 10px 6px;
    font-weight: 600;
}

.sidebar a.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: #cbd5e1;
    font-size: 13.5px;
    font-weight: 500;
    margin-bottom: 2px;
}
.sidebar a.nav-item:hover { background: #1e293b; color: #fff; }
.sidebar a.nav-item.active { background: var(--primary); color: #fff; }
.sidebar a.nav-item .ic { width: 16px; text-align: center; opacity: .85; font-size: 13px; }

.main { flex: 1; min-width: 0; }

.topbar {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 14px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; }
.topbar .crumb { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.content { padding: 24px 26px 60px; }

/* ---------------- Card ---------------- */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
    gap: 12px;
    flex-wrap: wrap;
}
.card-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.card-body { padding: 18px; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow);
}
.stat .n { font-family: 'Sora', sans-serif; font-size: 26px; font-weight: 800; line-height: 1; }
.stat .l { color: var(--muted); font-size: 12px; margin-top: 6px; font-weight: 500; }
.stat.accent .n { color: var(--accent); }
.stat.primary .n { color: var(--primary); }
.stat.danger .n { color: var(--danger); }

/* ---------------- Table ---------------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 2px solid var(--line);
    white-space: nowrap; background: #fbfcfe;
}
table.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tbody tr:hover { background: #f8fafc; }
table.tbl tbody tr:last-child td { border-bottom: none; }
.td-actions { white-space: nowrap; text-align: right; }

/* ---------------- Badge / Pill ---------------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 100px;
    font-size: 11.5px; font-weight: 600; letter-spacing: .2px;
}
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.off { background: #f1f5f9; color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge .sw { width: 8px; height: 8px; border-radius: 50%; }

.swatch { display: inline-block; width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(0,0,0,.12); vertical-align: -3px; margin-right: 6px; }

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--panel);
    color: var(--ink); padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
    cursor: pointer; font-family: inherit; line-height: 1.2;
}
.btn:hover { border-color: #c6cfdb; background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-ink); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger-soft); border-color: #f6c3c3; color: var(--danger); }
.btn.danger:hover { background: #fbdada; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f1f5f9; color: var(--ink); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.icon { padding: 6px 9px; }

/* ---------------- Forms ---------------- */
.fld { margin-bottom: 14px; }
.lbl { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: #334155; }
.lbl .req { color: var(--danger); }
input[type=text], input[type=number], input[type=date], input[type=email],
input[type=tel], input[type=color], select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: var(--radius-sm);
    font-size: 13.5px; font-family: inherit; background: #fff; color: var(--ink);
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }
.hint { font-size: 11.5px; color: var(--faint); margin-top: 4px; }
.err-text { font-size: 11.5px; color: var(--danger); margin-top: 4px; }

/* toolbar / filter row */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=text] { width: 220px; }
.toolbar select { width: auto; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 100;
    align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal {
    background: #fff; border-radius: 12px; width: 100%; max-width: 560px; max-height: 90vh;
    overflow-y: auto; box-shadow: 0 24px 60px -12px rgba(15,23,42,.35);
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); line-height: 1; }

/* composition rows (fabric master) */
.comp-row { display: grid; grid-template-columns: 2fr 1fr auto; gap: 10px; align-items: center; margin-bottom: 8px; }
.comp-total { font-size: 12.5px; font-weight: 600; margin-top: 6px; }
.comp-total.bad { color: var(--danger); }
.comp-total.good { color: var(--success); }

/* ---------------- Toast ---------------- */
#toast-wrap { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500; box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px;
    animation: slidein .18s ease-out;
}
.toast.ok::before { content: "✓"; color: #4ade80; font-weight: 800; }
.toast.err::before { content: "!"; color: #f87171; font-weight: 800; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---------------- Tabs (order workspace) ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tab-btn {
    background: none; border: none; padding: 10px 16px; font-size: 13px; font-weight: 600; color: var(--muted);
    cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; font-family: inherit;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.order-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 14px; margin-bottom: 18px; }
.order-head .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.order-head .meta b { color: var(--ink); }

.calc-box { background: #fbfcfe; border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 14px 16px; }
.calc-line { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; border-bottom: 1px dashed var(--line); }
.calc-line:last-child { border-bottom: none; }
.calc-line.total { font-weight: 700; font-size: 15px; padding-top: 10px; }
.calc-line .v { font-family: 'IBM Plex Mono', monospace; }

.matrix-tbl input[type=number] { width: 72px; padding: 6px 8px; text-align: center; }
.matrix-tbl th, .matrix-tbl td { text-align: center; }
.matrix-tbl td:first-child, .matrix-tbl th:first-child { text-align: left; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty-state .ic { font-size: 30px; margin-bottom: 10px; opacity: .5; }

@media (max-width: 860px) {
    .sidebar { display: none; }
    .grid2, .grid3 { grid-template-columns: 1fr; }
}
