/* Grip ERP — Illumify-inspired theme (dark purple chrome, light workspace) */
:root {
  --brand: #5b21b6;
  --brand-2: #7c3aed;
  --brand-ink: #2e1065;
  --topbar: #1e1b2e;
  --sidebar: #14121f;
  --sidebar-hover: #241f37;
  --sidebar-active: #3b2d63;
  --ink: #1f2330;
  --ink-soft: #5b6172;
  --line: #e6e8ee;
  --bg: #f4f5f8;
  --card: #ffffff;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --chip: #ede9fe;
  --chip-ink: #6d28d9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,18,28,.06), 0 4px 16px rgba(16,18,28,.05);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ---- App shell ---------------------------------------------------------- */
#app { display: grid; grid-template-columns: 232px 1fr; grid-template-rows: 52px 1fr; height: 100vh; }
.topbar {
  grid-column: 1 / 3;
  background: linear-gradient(90deg, var(--topbar), #221d36);
  color: #fff; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  box-shadow: 0 1px 0 rgba(255,255,255,.05);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .2px; }
.brand .logo { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--brand-2), #a78bfa); display: grid; place-items: center; font-size: 13px; }
.facility-pick {
  margin-left: 6px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14);
  color: #fff; border-radius: 8px; padding: 6px 10px; font-size: 13px;
}
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: 8px; opacity: .9; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: linear-gradient(135deg,#f0abfc,#c084fc); }

/* ---- Sidebar ------------------------------------------------------------ */
.sidebar { background: var(--sidebar); color: #cdd0db; overflow-y: auto; padding: 8px 0 40px; }
.sidebar .sec { padding: 14px 18px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6b6e80; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 18px; color: #c7cad6;
  border-left: 3px solid transparent; font-size: 13.5px;
}
.nav-item:hover { background: var(--sidebar-hover); }
.nav-item.active { background: var(--sidebar-active); border-left-color: var(--brand-2); color: #fff; font-weight: 600; }
.nav-item .ic { width: 16px; text-align: center; opacity: .85; }

/* ---- Workspace ---------------------------------------------------------- */
.work { overflow-y: auto; padding: 22px 26px 60px; }
.page-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.page-head h1 { font-size: 20px; margin: 0; }
.page-sub { color: var(--ink-soft); margin: 2px 0 18px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.input, .select { border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; background: #fff; font-size: 13px; min-width: 220px; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 13px; font-weight: 600; color: var(--ink); }
.btn:hover { border-color: #c9cdd8; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }

/* ---- Cards / KPIs ------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--ink-soft); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.kpi .delta { font-size: 12px; font-weight: 600; margin-top: 2px; }
.kpi .delta.up { color: var(--good); } .kpi .delta.down { color: var(--bad); } .kpi .delta.flat { color: var(--ink-soft); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-h { padding: 13px 16px; border-bottom: 1px solid var(--line); font-weight: 600; display:flex; justify-content:space-between; align-items:center; }
.card .card-b { padding: 14px 16px; }

/* ---- Tables ------------------------------------------------------------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th { text-align: left; padding: 11px 14px; color: var(--ink-soft); font-weight: 600; background: #fafbfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid td { padding: 11px 14px; border-bottom: 1px solid #f0f1f5; }
table.grid tbody tr:hover { background: #faf9ff; cursor: pointer; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-soft); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* ---- Chips / badges ----------------------------------------------------- */
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--chip); color: var(--chip-ink); }
.chip.green { background: var(--good-bg); color: var(--good); }
.chip.amber { background: var(--warn-bg); color: var(--warn); }
.chip.red { background: var(--bad-bg); color: var(--bad); }
.chip.grey { background: #eef0f4; color: #555c6b; }
.cell-good { color: var(--good); font-weight: 600; }
.cell-warn { color: var(--warn); font-weight: 600; }
.cell-bad { color: var(--bad); font-weight: 600; }

/* ---- Rooms tree --------------------------------------------------------- */
.room { border-bottom: 1px solid #f0f1f5; }
.room-h { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.room-h:hover { background: #faf9ff; }
.room-h .twist { width: 14px; color: var(--ink-soft); transition: transform .15s; }
.room.open .twist { transform: rotate(90deg); }
.room-name { font-weight: 600; flex: 1; }
.room-plants { display: none; background: #fbfbfe; }
.room.open .room-plants { display: block; }
.plant-row { display: flex; gap: 12px; padding: 8px 14px 8px 38px; border-top: 1px solid #f0f1f5; align-items: center; }

/* ---- Detail drawer ------------------------------------------------------ */
.drawer-mask { position: fixed; inset: 0; background: rgba(20,18,31,.4); display: none; z-index: 40; }
.drawer-mask.open { display: block; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 94vw); background: #fff; box-shadow: -8px 0 30px rgba(0,0,0,.18); transform: translateX(100%); transition: transform .22s ease; z-index: 50; overflow-y: auto; }
.drawer.open { transform: translateX(0); }
.drawer-h { padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; display:flex; justify-content:space-between; align-items:flex-start; }
.drawer-h h2 { margin: 0; font-size: 16px; }
.drawer-b { padding: 16px 20px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 10px 0 18px; }
.kv dt { color: var(--ink-soft); } .kv dd { margin: 0; font-weight: 500; }
.section-title { font-weight: 700; margin: 18px 0 8px; font-size: 13px; }
.x { border: none; background: #f1f2f6; border-radius: 8px; width: 30px; height: 30px; font-size: 16px; color: #555; }

/* ---- Modal -------------------------------------------------------------- */
.modal-mask { position: fixed; inset: 0; background: rgba(20,18,31,.45); display: none; place-items: center; z-index: 60; }
.modal-mask.open { display: grid; }
.modal { background: #fff; border-radius: 12px; width: min(440px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); overflow: hidden; }
.modal .m-h { padding: 16px 18px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.modal .m-h .warn-ic { width: 30px; height: 30px; border-radius: 50%; background: var(--warn-bg); color: var(--warn); display: grid; place-items: center; font-weight: 700; }
.modal .m-b { padding: 16px 18px; color: var(--ink-soft); }
.modal .m-f { padding: 12px 18px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--line); }
.credit-line { display: flex; justify-content: space-between; padding: 6px 0; }
.credit-line b.over { color: var(--bad); }

/* ---- Charts ------------------------------------------------------------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.bars .bar { flex: 1; background: linear-gradient(180deg, var(--brand-2), #a78bfa); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .bar span { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 10px; color: var(--ink-soft); }
.chart-foot { height: 18px; }

/* ---- Facility map ------------------------------------------------------- */
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.map-tile { background: var(--card); border: 1px solid var(--line); border-top: 4px solid #c7cad6; border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); cursor: pointer; transition: transform .1s, box-shadow .1s; }
.map-tile:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(16,18,28,.1); }
.map-tile.green { border-top-color: var(--good); }
.map-tile.amber { border-top-color: var(--warn); }
.map-tile.grey { border-top-color: #c7cad6; opacity: .8; }
.map-tile-h { font-weight: 700; margin-bottom: 6px; }
.map-count { font-size: 30px; font-weight: 800; line-height: 1; }
.map-count-u { font-size: 11px; font-weight: 500; color: var(--ink-soft); margin-left: 6px; }
.map-badges { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; min-height: 20px; }
.map-fill { height: 6px; background: #eef0f4; border-radius: 999px; overflow: hidden; }
.map-fill span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-2), #a78bfa); }
.map-foot { font-size: 11px; margin-top: 6px; }

/* ---- Production schedule grid ------------------------------------------- */
table.grid.sched td.sched-cell { text-align: center; color: var(--ink-soft); }
table.grid.sched td.sched-cell.on { background: #ede9fe; color: var(--brand-ink); font-weight: 700; }
table.grid.sched tr.sched-sec td { background: var(--brand-ink); color: #fff; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
table.grid.sched tbody tr:not(.sched-sec):hover { background: #faf9ff; cursor: default; }

/* ---- Product menu gallery ----------------------------------------------- */
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.menu-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.menu-thumb { height: 110px; display: grid; place-items: center; font-size: 44px; background: linear-gradient(135deg, #ede9fe, #ddd6fe); }
.menu-thumb.catbuds { background: linear-gradient(135deg, #dcfce7, #bbf7d0); }
.menu-thumb.catconcentrate { background: linear-gradient(135deg, #fef3c7, #fde68a); }
.menu-thumb.catricepreroll { background: linear-gradient(135deg, #ede9fe, #ddd6fe); }
.menu-body { padding: 12px 14px; }
.menu-brand { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--brand-2); font-weight: 700; }
.menu-name { font-weight: 600; margin: 2px 0; }
.menu-meta { font-size: 12px; }
.menu-row { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.menu-price { font-size: 18px; font-weight: 800; }

.empty { padding: 40px; text-align: center; color: var(--ink-soft); }
.demo-banner { background: var(--chip); color: var(--chip-ink); font-size: 12px; padding: 6px 26px; text-align: center; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 52px auto 1fr; }
  .sidebar { display: none; }
  .grid2 { grid-template-columns: 1fr; }
}
