/* ============================================================
   ChemStorage — design system
   Technical / industrial dark theme. Mono for data, sans for UI.
   All classes prefixed cs- to avoid collision with canvas chrome.
   ============================================================ */

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

:root {
  /* surfaces (dark slate) */
  --cs-bg:        oklch(0.165 0.012 248);
  --cs-s1:        oklch(0.205 0.014 248);
  --cs-s2:        oklch(0.245 0.016 248);
  --cs-s3:        oklch(0.290 0.018 248);
  --cs-line:      oklch(0.320 0.016 248);
  --cs-line-2:    oklch(0.400 0.018 248);
  /* ink */
  --cs-ink:       oklch(0.965 0.004 248);
  --cs-ink-2:     oklch(0.745 0.012 248);
  --cs-ink-3:     oklch(0.560 0.014 248);
  --cs-ink-4:     oklch(0.440 0.014 248);
  /* accent (cyan) */
  --cs-acc:       oklch(0.815 0.125 205);
  --cs-acc-2:     oklch(0.660 0.110 205);
  --cs-acc-ink:   oklch(0.205 0.040 240);
  --cs-acc-tint:  oklch(0.815 0.125 205 / 0.13);
  /* status */
  --cs-ok:        oklch(0.800 0.150 158);
  --cs-ok-tint:   oklch(0.800 0.150 158 / 0.14);
  --cs-warn:      oklch(0.840 0.140 82);
  --cs-warn-tint: oklch(0.840 0.140 82 / 0.15);
  --cs-bad:       oklch(0.690 0.190 25);
  --cs-bad-tint:  oklch(0.690 0.190 25 / 0.16);

  --cs-r:    6px;
  --cs-r-sm: 4px;
  --cs-r-lg: 10px;
  --cs-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --cs-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

/* ---- root frame ------------------------------------------------ */
.cs-app, .cs-app * { box-sizing: border-box; }
.cs-app {
  width: 100%; height: 100%;
  display: flex;
  background: var(--cs-bg);
  color: var(--cs-ink);
  font-family: var(--cs-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* faint technical grid */
  background-image:
    linear-gradient(var(--cs-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--cs-line) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%;
  background-blend-mode: normal;
  position: relative;
}
.cs-app::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(oklch(1 0 0 / 0.012) 1px, transparent 1px),
    linear-gradient(90deg, oklch(1 0 0 / 0.012) 1px, transparent 1px);
  background-size: 40px 40px, 40px 40px;
}

/* ---- micro / mono labels -------------------------------------- */
.cs-micro {
  font-family: var(--cs-mono);
  font-size: 10.5px; font-weight: 500;
  letter-spacing: 0.11em; text-transform: uppercase;
  color: var(--cs-ink-3);
}
.cs-mono { font-family: var(--cs-mono); font-variant-numeric: tabular-nums; }
.cs-num  { font-family: var(--cs-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---- sidebar -------------------------------------------------- */
.cs-side {
  width: 224px; flex-shrink: 0;
  background: var(--cs-s1);
  border-right: 1px solid var(--cs-line);
  display: flex; flex-direction: column;
  position: relative; z-index: 1;
}
.cs-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid var(--cs-line);
}
.cs-brand-mark {
  width: 26px; height: 26px; border-radius: var(--cs-r-sm);
  background: var(--cs-acc); color: var(--cs-acc-ink);
  display: grid; place-items: center; flex-shrink: 0;
  font-family: var(--cs-mono); font-weight: 600; font-size: 14px;
}
.cs-brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.cs-brand-name span { color: var(--cs-ink-3); font-weight: 500; }

.cs-loc {
  margin: 12px 12px 6px; padding: 9px 11px;
  background: var(--cs-s2); border: 1px solid var(--cs-line);
  border-radius: var(--cs-r); cursor: pointer;
  display: flex; align-items: center; gap: 9px;
}
.cs-loc:hover { border-color: var(--cs-line-2); }
.cs-loc-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--cs-acc); flex-shrink: 0; }
.cs-loc-name { font-weight: 500; font-size: 13px; flex: 1; white-space: nowrap; }
.cs-loc-sub  { font-size: 10.5px; color: var(--cs-ink-3); font-family: var(--cs-mono); }

.cs-nav { padding: 8px 12px; display: flex; flex-direction: column; gap: 1px; }
.cs-nav-label { padding: 12px 8px 5px; }
.cs-nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: var(--cs-r-sm);
  color: var(--cs-ink-2); font-weight: 500; font-size: 13.5px;
  cursor: pointer; position: relative;
}
.cs-nav-item:hover { background: var(--cs-s2); color: var(--cs-ink); }
.cs-nav-item.is-active { background: var(--cs-s2); color: var(--cs-ink); }
.cs-nav-item.is-active::before {
  content: ''; position: absolute; left: -12px; top: 6px; bottom: 6px;
  width: 2.5px; border-radius: 0 2px 2px 0; background: var(--cs-acc);
}
.cs-nav-item svg { color: var(--cs-ink-3); flex-shrink: 0; }
.cs-nav-item.is-active svg { color: var(--cs-acc); }
.cs-nav-badge {
  margin-left: auto; font-family: var(--cs-mono); font-size: 10.5px; font-weight: 600;
  background: var(--cs-s3); color: var(--cs-ink-2);
  padding: 1px 6px; border-radius: 20px; min-width: 18px; text-align: center;
}
.cs-nav-badge.warn { background: var(--cs-warn-tint); color: var(--cs-warn); }

.cs-side-foot {
  margin-top: auto; padding: 12px;
  border-top: 1px solid var(--cs-line);
  display: flex; align-items: center; gap: 10px;
}
.cs-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: var(--cs-s3); border: 1px solid var(--cs-line-2);
  display: grid; place-items: center;
  font-family: var(--cs-mono); font-size: 11px; font-weight: 600; color: var(--cs-ink-2);
}

/* ---- main column ---------------------------------------------- */
.cs-main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; z-index: 1; }
.cs-topbar {
  height: 56px; flex-shrink: 0;
  border-bottom: 1px solid var(--cs-line);
  background: oklch(0.185 0.013 248 / 0.7);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
}
.cs-title-wrap { display: flex; flex-direction: column; gap: 1px; }
.cs-h1 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; display: flex; align-items: center; gap: 9px; }
.cs-crumb { color: var(--cs-ink-3); font-weight: 500; }

.cs-search {
  display: flex; align-items: center; gap: 9px;
  background: var(--cs-s1); border: 1px solid var(--cs-line);
  border-radius: var(--cs-r); padding: 8px 12px; min-width: 240px;
}
.cs-search:focus-within { border-color: var(--cs-acc-2); }
.cs-search input {
  background: none; border: none; outline: none; color: var(--cs-ink);
  font-family: var(--cs-sans); font-size: 13px; width: 100%;
}
.cs-search input::placeholder { color: var(--cs-ink-4); }
.cs-search kbd {
  font-family: var(--cs-mono); font-size: 10px; color: var(--cs-ink-3);
  border: 1px solid var(--cs-line-2); border-radius: 3px; padding: 1px 4px;
}

.cs-scroll { flex: 1; overflow: auto; padding: 20px; }

/* ---- buttons -------------------------------------------------- */
.cs-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--cs-sans); font-size: 13px; font-weight: 600;
  padding: 8px 13px; border-radius: var(--cs-r);
  border: 1px solid var(--cs-line-2); background: var(--cs-s2); color: var(--cs-ink);
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.cs-btn:hover { background: var(--cs-s3); border-color: var(--cs-ink-4); }
.cs-btn svg { color: var(--cs-ink-2); }
.cs-btn-primary { background: var(--cs-acc); border-color: var(--cs-acc); color: var(--cs-acc-ink); }
.cs-btn-primary:hover { background: oklch(0.86 0.125 205); border-color: oklch(0.86 0.125 205); }
.cs-btn-primary svg { color: var(--cs-acc-ink); }
.cs-btn-ghost { background: transparent; border-color: transparent; color: var(--cs-ink-2); }
.cs-btn-ghost:hover { background: var(--cs-s2); border-color: var(--cs-line); }
.cs-btn-danger { background: rgb(220 38 38 / 0.16); border-color: rgb(220 38 38 / 0.65); color: #f87171; }
.cs-btn-danger:hover { background: rgb(220 38 38 / 0.32); border-color: #dc2626; color: #fca5a5; }
.cs-btn-sm { padding: 5px 9px; font-size: 12px; }
.cs-icon-btn {
  width: 34px; height: 34px; padding: 0; justify-content: center;
}

/* ---- panels --------------------------------------------------- */
.cs-panel {
  background: var(--cs-s1); border: 1px solid var(--cs-line);
  border-radius: var(--cs-r); overflow: hidden;
}
.cs-panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 15px; border-bottom: 1px solid var(--cs-line);
}
.cs-action-summary {
  cursor: pointer;
  list-style: none;
  transition: background .12s;
}
.cs-action-summary::-webkit-details-marker { display: none; }
.cs-action-summary:hover { background: var(--cs-s2); }
.cs-panel-title { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.cs-panel-head .cs-spacer { flex: 1; }
.cs-corner { position: relative; }
.cs-corner::before, .cs-corner::after {
  content: ''; position: absolute; width: 7px; height: 7px; pointer-events: none;
  border-color: var(--cs-line-2); border-style: solid; border-width: 0;
}
.cs-corner::before { top: 6px; left: 6px; border-top-width: 1px; border-left-width: 1px; }
.cs-corner::after  { bottom: 6px; right: 6px; border-bottom-width: 1px; border-right-width: 1px; }

/* ---- KPI stat ------------------------------------------------- */
.cs-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.cs-stat {
  background: var(--cs-s1); border: 1px solid var(--cs-line);
  border-radius: var(--cs-r); padding: 14px 15px; position: relative; overflow: hidden;
}
.cs-stat-label { display: flex; align-items: center; gap: 7px; margin-bottom: 11px; }
.cs-stat-num { font-family: var(--cs-mono); font-size: 27px; font-weight: 600; letter-spacing: -0.02em; line-height: 1; }
.cs-stat-unit { font-family: var(--cs-mono); font-size: 12px; color: var(--cs-ink-3); margin-left: 4px; }
.cs-stat-foot { margin-top: 9px; display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--cs-ink-3); }
.cs-trend { font-family: var(--cs-mono); font-weight: 600; }
.cs-trend.up { color: var(--cs-ok); }
.cs-trend.down { color: var(--cs-bad); }
.cs-stat-accent::after {
  content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 2px;
  background: var(--cs-acc);
}

/* ---- badges / status ------------------------------------------ */
.cs-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--cs-mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 2px 7px 2px 6px; border-radius: 4px;
  border: 1px solid transparent; white-space: nowrap;
}
.cs-badge .dot { width: 6px; height: 6px; border-radius: 50%; }
.cs-badge.ok   { background: var(--cs-ok-tint);   color: var(--cs-ok);   border-color: oklch(0.800 0.150 158 / 0.3); }
.cs-badge.ok   .dot { background: var(--cs-ok); }
.cs-badge.warn { background: var(--cs-warn-tint); color: var(--cs-warn); border-color: oklch(0.840 0.140 82 / 0.3); }
.cs-badge.warn .dot { background: var(--cs-warn); }
.cs-badge.bad  { background: var(--cs-bad-tint);  color: var(--cs-bad);  border-color: oklch(0.690 0.190 25 / 0.35); }
.cs-badge.bad  .dot { background: var(--cs-bad); }
.cs-badge.neutral { background: var(--cs-s2); color: var(--cs-ink-2); border-color: var(--cs-line); }
.cs-badge.acc  { background: var(--cs-acc-tint); color: var(--cs-acc); border-color: oklch(0.815 0.125 205 / 0.3); }

.cs-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 500; color: var(--cs-ink-2);
  background: var(--cs-s2); border: 1px solid var(--cs-line);
  padding: 2px 8px; border-radius: 20px;
}
.cs-tag .dot { width: 6px; height: 6px; border-radius: 2px; }

/* ---- data table ----------------------------------------------- */
.cs-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cs-table th {
  text-align: left; font-family: var(--cs-mono); font-weight: 500;
  font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--cs-ink-3); padding: 9px 14px;
  border-bottom: 1px solid var(--cs-line); background: var(--cs-s1);
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.cs-table th.r, .cs-table td.r { text-align: right; }
.cs-table td {
  padding: 11px 14px; border-bottom: 1px solid var(--cs-line);
  vertical-align: middle;
}
.cs-table tbody tr { transition: background .1s; }
.cs-table tbody tr:hover { background: var(--cs-s1); }
.cs-table tbody tr:last-child td { border-bottom: none; }
.cs-cell-main { display: flex; align-items: center; gap: 11px; }
.cs-thumb {
  width: 34px; height: 34px; border-radius: var(--cs-r-sm); flex-shrink: 0;
  background:
    repeating-linear-gradient(135deg, var(--cs-s2) 0 6px, var(--cs-s3) 6px 12px);
  border: 1px solid var(--cs-line); position: relative; overflow: hidden;
}
.cs-thumb.big { width: 46px; height: 46px; }
.cs-name { font-weight: 600; font-size: 13px; }
.cs-code { font-family: var(--cs-mono); font-size: 10.5px; color: var(--cs-ink-3); margin-top: 1px; }
.cs-qty { font-family: var(--cs-mono); font-weight: 600; font-size: 14px; }
.cs-qty small { color: var(--cs-ink-3); font-weight: 500; font-size: 11px; margin-left: 3px; }

/* ---- meter / bar ---------------------------------------------- */
.cs-meter { height: 5px; border-radius: 3px; background: var(--cs-s3); overflow: hidden; position: relative; }
.cs-meter > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; display: block; }
.cs-meter.ok > i   { background: var(--cs-ok); }
.cs-meter.warn > i { background: var(--cs-warn); }
.cs-meter.bad > i  { background: var(--cs-bad); }
.cs-meter-track { position: relative; }
.cs-meter-mark { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--cs-ink-4); }

/* ---- activity feed -------------------------------------------- */
.cs-feed { display: flex; flex-direction: column; }
.cs-feed-row { display: flex; gap: 11px; padding: 11px 15px; border-bottom: 1px solid var(--cs-line); }
.cs-feed-row:last-child { border-bottom: none; }
.cs-feed-ico {
  width: 28px; height: 28px; border-radius: var(--cs-r-sm); flex-shrink: 0;
  display: grid; place-items: center; background: var(--cs-s2); border: 1px solid var(--cs-line);
}
.cs-feed-ico.issue { color: var(--cs-warn); }
.cs-feed-ico.recv  { color: var(--cs-ok); }
.cs-feed-ico.xfer  { color: var(--cs-acc); }
.cs-feed-ico.adj   { color: var(--cs-ink-2); }
.cs-feed-body { flex: 1; min-width: 0; }
.cs-feed-line { font-size: 13px; line-height: 1.4; }
.cs-feed-line b { font-weight: 600; }
.cs-feed-meta { font-family: var(--cs-mono); font-size: 10.5px; color: var(--cs-ink-3); margin-top: 2px; display: flex; gap: 8px; }
.cs-delta { font-family: var(--cs-mono); font-weight: 600; font-size: 13px; }
.cs-delta.neg { color: var(--cs-warn); }
.cs-delta.pos { color: var(--cs-ok); }

/* ---- segmented / filters -------------------------------------- */
.cs-seg { display: inline-flex; background: var(--cs-s1); border: 1px solid var(--cs-line); border-radius: var(--cs-r); padding: 2px; gap: 2px; }
.cs-seg button {
  font-family: var(--cs-sans); font-size: 12.5px; font-weight: 500;
  padding: 5px 11px; border-radius: var(--cs-r-sm); border: none;
  background: transparent; color: var(--cs-ink-2); cursor: pointer;
}
.cs-seg button.is-active { background: var(--cs-s3); color: var(--cs-ink); }
.cs-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 500; color: var(--cs-ink-2);
  background: var(--cs-s1); border: 1px solid var(--cs-line);
  padding: 6px 11px; border-radius: var(--cs-r); cursor: pointer;
}
.cs-chip:hover { border-color: var(--cs-line-2); }
.cs-chip svg { color: var(--cs-ink-3); }

/* ---- fields --------------------------------------------------- */
.cs-field { display: flex; flex-direction: column; gap: 6px; }
.cs-label { font-size: 12px; font-weight: 600; color: var(--cs-ink-2); }
.cs-input {
  font-family: var(--cs-sans); font-size: 13.5px; color: var(--cs-ink);
  background: var(--cs-s1); border: 1px solid var(--cs-line);
  border-radius: var(--cs-r); padding: 9px 12px; outline: none; width: 100%;
}
.cs-input:focus { border-color: var(--cs-acc-2); }
.cs-input::placeholder { color: var(--cs-ink-4); }
textarea.cs-input { resize: none; line-height: 1.5; }

.cs-divider { height: 1px; background: var(--cs-line); margin: 16px 0;}
.cs-vline { width: 1px; align-self: stretch; background: var(--cs-line); }

/* scrollbars (thin, dark) */
.cs-scroll::-webkit-scrollbar, .cs-tablewrap::-webkit-scrollbar { width: 9px; height: 9px; }
.cs-scroll::-webkit-scrollbar-thumb, .cs-tablewrap::-webkit-scrollbar-thumb {
  background: var(--cs-s3); border-radius: 6px; border: 2px solid var(--cs-bg);
}
