/* Moon Valley OS — design system */
:root {
  --bg: #0a0a0d;
  --bg-2: #100e16;
  --panel: #16131f;
  --panel-2: #1e1a2c;
  --border: #2a2440;
  --border-2: #3b3358;
  --text: #f1edf7;
  --text-dim: #b3a9c8;
  --text-faint: #82789a;
  --accent: #ffd23f;          /* yellow — primary */
  --accent-2: #e0a500;        /* gold */
  --accent-soft: rgba(255, 210, 63, 0.13);
  --purple: #a06bff;          /* purple — secondary */
  --purple-2: #7d3ff0;
  --purple-soft: rgba(160, 107, 255, 0.15);
  --amber: #ffc24d;
  --red: #ff6b6b;
  --blue: #a06bff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.30);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 .8em; }
small { color: var(--text-faint); }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--bg-2);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 20px 16px; display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--purple), var(--accent));
  display: grid; place-items: center; color: #14040a; font-weight: 800; font-size: 15px;
}
.brand .name { font-weight: 700; font-size: 15px; letter-spacing: -0.02em; }
.brand .sub { font-size: 11px; color: var(--text-faint); }
.nav { padding: 6px 12px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 500; margin-bottom: 2px; text-decoration: none;
}
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a svg { width: 17px; height: 17px; opacity: .9; }
.nav .section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); padding: 14px 12px 6px; }
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--panel-2); display: grid; place-items: center; font-weight: 600; color: var(--accent); font-size: 13px; }
.user-chip .meta { line-height: 1.2; overflow: hidden; }
.user-chip .meta .n { font-weight: 600; font-size: 13px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.user-chip .meta .r { font-size: 11px; color: var(--text-faint); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; border-bottom: 1px solid var(--border); display: flex; align-items: center;
  justify-content: space-between; padding: 0 28px; position: sticky; top: 0; background: rgba(10,10,13,.85);
  backdrop-filter: blur(8px); z-index: 10;
}
.topbar .page-title { font-size: 15px; font-weight: 600; }
.content { padding: 24px 28px 48px; max-width: 1240px; width: 100%; }

/* Cards & grid */
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1000px) { .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2,1fr);} }

/* Mobile navigation (off-canvas drawer) */
.menu-btn { display: none; background: transparent; border: none; color: var(--text); padding: 4px; cursor: pointer; }
.menu-btn svg { width: 22px; height: 22px; }
.scrim { display: none; }
@media (max-width: 820px) {
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh; z-index: 50;
    transform: translateX(-100%); transition: transform .22s ease;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40;
  }
  .content { padding: 18px 16px 40px; }
  .form-row, .form-row.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .grid[style] { grid-template-columns: 1fr !important; }
  table { font-size: 13px; }
  td, th { padding: 8px 8px; }
}

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card.tight { padding: 14px 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head > svg { width: 20px; height: 20px; color: var(--text-faint); flex-shrink: 0; }

/* KPI tiles */
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi .label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.kpi .value.sm { font-size: 22px; }
.kpi .foot { font-size: 12px; color: var(--text-faint); }
.kpi-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 4px; }
.kpi-icon svg { width: 18px; height: 18px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 600; color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 12px; border-bottom: 1px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--text-dim); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em; white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge-green { background: rgba(79,209,161,.12); color: #57d6a6; }
.badge-amber { background: rgba(230,180,80,.13); color: var(--amber); }
.badge-red { background: rgba(232,115,94,.13); color: var(--red); }
.badge-blue { background: rgba(107,168,230,.13); color: var(--blue); }
.badge-gray { background: rgba(157,179,168,.1); color: var(--text-dim); }

.pill { display:inline-block; padding: 2px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); font-size: 11.5px; color: var(--text-dim); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-2); background: var(--panel-2); color: var(--text); font-weight: 600;
  font-size: 13px; cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--border); text-decoration: none; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a1200; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: rgba(232,115,94,.3); }
.btn svg { width: 15px; height: 15px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Forms */
label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 5px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-sm); border: 1px solid var(--border-2);
  background: var(--bg-2); color: var(--text); font-size: 13.5px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 70px; }
.field { margin-bottom: 12px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }

/* Details / disclosure */
details.panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); margin-bottom: 16px; }
details.panel > summary { padding: 14px 18px; cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before { content: "+"; color: var(--accent); font-weight: 700; }
details.panel[open] > summary::before { content: "–"; }
details.panel > .panel-body { padding: 0 18px 18px; }

/* Flash */
.flashes { margin-bottom: 16px; }
.flash { padding: 11px 15px; border-radius: var(--radius-sm); margin-bottom: 8px; font-weight: 500; font-size: 13px; border: 1px solid; }
.flash.success { background: rgba(79,209,161,.1); border-color: rgba(79,209,161,.3); color: #6fe0b4; }
.flash.error { background: rgba(232,115,94,.1); border-color: rgba(232,115,94,.3); color: #f0937f; }

/* Bars */
.bar { height: 7px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--purple), var(--accent)); }

/* Misc */
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.right { text-align: right; }
.center { text-align: center; }
.stack > * + * { margin-top: 10px; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex.between { justify-content: space-between; }
.flex.wrap { flex-wrap: wrap; }
.gap-sm { gap: 6px; }
.empty { text-align: center; padding: 40px 20px; color: var(--text-faint); }
.empty svg { width: 34px; height: 34px; opacity: .4; margin-bottom: 8px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 12px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 13px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.timeline .t { font-family: ui-monospace, monospace; font-size: 12px; color: var(--text-dim); }
.subtabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.subtabs a { padding: 8px 14px; color: var(--text-dim); font-weight: 500; border-bottom: 2px solid transparent; }
.subtabs a:hover { color: var(--text); text-decoration: none; }
.subtabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.chip:hover { border-color: var(--accent-2); color: var(--text); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background:
  radial-gradient(900px 500px at 70% -10%, rgba(160,107,255,.22), transparent),
  radial-gradient(700px 500px at 10% 110%, rgba(255,210,63,.12), transparent), var(--bg); }
.login-card { width: 380px; max-width: 92vw; }
.login-card .brand { padding: 0 0 20px; }
.demo-users { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; font-size: 12.5px; color: var(--text-dim); }
.demo-users code { background: var(--panel-2); padding: 1px 6px; border-radius: 4px; font-size: 12px; }

/* Scan fields + camera modal */
.scan-field { display: flex; gap: 6px; align-items: stretch; }
.scan-field > input, .scan-field > textarea { flex: 1; }
.scan-btn { white-space: nowrap; }
.scan-modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.72); z-index: 100; align-items: center; justify-content: center; }
.scan-box { background: var(--panel); border: 1px solid var(--border-2); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.scan-head { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 12px; font-weight: 600; }
#scan-reader { border-radius: 8px; overflow: hidden; background: #000; }
