/* =========================================
   1. BASE THEME & VARIABLES
   ========================================= */
:root {
  --bg: #0d1420; --card: #161f33; --card2: #1b2540; --border: #263354; --text: #eef1f7; --muted: #8b96ac;
  --accent: #3b82f6; --danger: #f87171;
  --C: #17b8e0; --M: #e0177a; --Y: #e0c517; --K: #4b5468;
  --LC: #8fe0f0; --LM: #f0a8cc; --LK: #7a8296; --LLK: #a8afbf;
  --F1: #34d399; --F2: #a78bfa; --F3: #f59e0b;
  --STD: #34d399; --XL: #a78bfa;
}
html.light {
  --bg: #f3f5fa; --card: #ffffff; --card2: #ffffff; --border: #e1e6ef; --text: #111827; --muted: #6b7280;
}
* { box-sizing: border-box; }
body {
  background: radial-gradient(circle at 15% 0%, #14203a 0%, var(--bg) 45%);
  color: var(--text); font-family: system-ui, -apple-system, sans-serif; margin: 0; display: flex; min-height: 100vh;
}
html.light body { background: radial-gradient(circle at 15% 0%, #e9edf7 0%, var(--bg) 45%); }

/* =========================================
   2. SIDEBAR & GLOBAL LAYOUT
   ========================================= */
.sidebar { width: 220px; min-height: 100vh; background: var(--card); border-right: 1px solid var(--border); padding: 20px 0; flex-shrink: 0; }
.sidebar .logo { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 18px; padding: 0 20px 22px; letter-spacing: -0.02em; }
.logo-badge { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #7c3aed); color: white; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; flex-shrink: 0; }
.sidebar a { display: block; padding: 10px 20px; color: var(--muted); text-decoration: none; font-size: 14px; border-left: 3px solid transparent; transition: background .15s; }
.sidebar a.active { color: var(--text); background: rgba(59,130,246,.12); border-left-color: var(--accent); font-weight: 600; }
.sidebar a:hover { color: var(--text); }

.main { flex: 1; padding: 32px 36px; max-width: 1200px; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.01em; }
p.sub { color: var(--muted); margin: 0 0 26px; font-size: 14px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 26px; }

/* Global Tables (Inventory & Logs) */
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
th { text-align: left; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 13px 18px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.02); }
td { padding: 13px 18px; border-bottom: 1px solid var(--border); font-size: 14px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.015); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 10px; vertical-align: middle; box-shadow: 0 0 0 1px rgba(255,255,255,.15); }

/* =========================================
   3. INK & FILM PAGE (index.html)
   ========================================= */
.group-head { display: flex; align-items: center; gap: 10px; margin: 30px 0 14px; }
.group-head:first-of-type { margin-top: 0; }
.group-dot { width: 9px; height: 9px; border-radius: 50%; }
.group-head h2 { font-size: 13px; margin: 0; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.group-head .film-tag { font-size: 11px; padding: 2px 9px; border-radius: 20px; font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 8px; }
.printer-card { background: linear-gradient(160deg, var(--card2), var(--card)); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: 0 6px 20px rgba(0,0,0,.25); position: relative; border-top: 3px solid var(--group-color, var(--accent)); transition: transform .15s, box-shadow .15s; }
.printer-card:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(0,0,0,.32); }
.printer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.printer-head h2 { font-size: 16px; margin: 0; font-weight: 700; }

.menu-wrap { position: relative; }
.menu-btn { background: transparent; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 2px 8px; border-radius: 6px; line-height: 1; }
.menu-btn:hover { background: rgba(255,255,255,.08); color: var(--text); }
.menu-dropdown { display: none; position: absolute; right: 0; top: 28px; background: var(--card2); border: 1px solid var(--border); border-radius: 8px; min-width: 190px; z-index: 10; box-shadow: 0 8px 24px rgba(0,0,0,.4); overflow: hidden; }
.menu-dropdown.open { display: block; }
.menu-dropdown div { padding: 10px 14px; font-size: 13px; cursor: pointer; color: var(--text); }
.menu-dropdown div:hover { background: rgba(59,130,246,.15); }

.ink-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.ink-btn { border: none; border-radius: 7px; padding: 11px 0; font-weight: 700; font-size: 12px; cursor: pointer; color: #0b1220; letter-spacing: .01em; transition: filter .15s, transform .1s; position: relative; }
.ink-btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.ink-btn.selected { box-shadow: 0 0 0 3px var(--accent), 0 0 0 5px rgba(59,130,246,.35); }
.ink-btn.selected::after { content: '✓'; position: absolute; top: -6px; right: -6px; background: var(--accent); color: white; width: 16px; height: 16px; border-radius: 50%; font-size: 10px; display: flex; align-items: center; justify-content: center; }

.film-row { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--border); }
.film-row .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.film-current { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 5px 12px; border-radius: 20px; background: rgba(255,255,255,.05); border: 1px solid var(--border); }
.film-current:hover { background: rgba(255,255,255,.09); }
.film-current .dot { width: 8px; height: 8px; border-radius: 50%; }
.film-current span.type { font-size: 13px; font-weight: 600; }

.ms-toggle { flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--card2); color: var(--text); cursor: pointer; font-size: 13px; font-weight: 600; }
.ms-toggle.active { border-color: var(--accent); background: rgba(59,130,246,.14); color: var(--accent); }

.float-bar { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--card2); border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; display: none; align-items: center; gap: 14px; box-shadow: 0 14px 40px rgba(0,0,0,.5); z-index: 15; }
.float-bar.show { display: flex; }
.float-bar .count { font-size: 13px; color: var(--muted); }
.float-bar .count b { color: var(--text); }
.float-bar button { padding: 9px 16px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; font-size: 13px; }
.float-bar .btn-clear { background: rgba(255,255,255,.08); color: var(--text); }
.float-bar .btn-clear:hover { background: rgba(255,255,255,.14); }
.float-bar .btn-review { background: var(--accent); color: white; }
.float-bar .btn-review:hover { background: #2f6fe0; }

.modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); align-items: center; justify-content: center; z-index: 20; }
.modal-bg.open { display: flex; }
.modal { background: var(--card2); border: 1px solid var(--border); border-radius: 12px; padding: 26px; width: 360px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p, .modal #modalBody { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions button { flex: 1; padding: 10px; border-radius: 8px; border: none; cursor: pointer; font-weight: 600; font-size: 14px; }
.btn-cancel { background: rgba(255,255,255,.08); color: var(--text); }
.btn-cancel:hover { background: rgba(255,255,255,.14); }
.btn-confirm { background: var(--accent); color: white; }
.btn-confirm:hover { background: #2f6fe0; }
.summary-list { text-align: left; margin: 0 0 20px; max-height: 240px; overflow-y: auto; }
.summary-list div { font-size: 14px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.summary-list div:last-child { border-bottom: none; }
.summary-list b { color: var(--text); }

/* =========================================
   4. TRENDS & ANALYTICS PAGE
   ========================================= */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: linear-gradient(160deg, var(--card2), var(--card)); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; box-shadow: 0 4px 16px rgba(0,0,0,.15); }
.stat-card .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.stat-card .value { font-size: 26px; font-weight: 800; }
.stat-card .sub-value { font-size: 12px; color: var(--muted); margin-top: 4px; }
.top-list { list-style: none; margin: 4px 0 0; padding: 0; }
.top-list li { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; }
.top-list li b { font-weight: 700; }

.panel { background: linear-gradient(160deg, var(--card2), var(--card)); border: 1px solid var(--border); border-radius: 12px; padding: 20px 22px; margin-bottom: 20px; box-shadow: 0 4px 16px rgba(0,0,0,.15); }
.panel h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 16px; }
.alert-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.alert-row:last-child { border-bottom: none; }
.alert-row .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 8px; }
.alert-row .figs { color: var(--danger); font-weight: 700; font-size: 13px; }
.empty-note { color: var(--muted); font-size: 13px; padding: 6px 0; }

.bar-row { display: grid; grid-template-columns: 110px 1fr 60px; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; }
.bar-row .name { display: flex; align-items: center; gap: 6px; }
.bar-track { background: rgba(255,255,255,.06); border-radius: 5px; height: 10px; overflow: hidden; }
html.light .bar-track { background: rgba(0,0,0,.06); }
.bar-fill { height: 100%; border-radius: 5px; }
.bar-row .months { text-align: right; color: var(--muted); }

.trend-chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.trend-bars { display: flex; gap: 2px; align-items: flex-end; height: 130px; width: 100%; justify-content: center; }
.trend-bar { width: 40%; border-radius: 3px 3px 0 0; min-height: 2px; }
.trend-label { font-size: 10px; color: var(--muted); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend .dot { width: 9px; height: 9px; border-radius: 3px; }

.trend-bar-stack { display: flex; flex-direction: column; justify-content: flex-end; width: 40%; }
.trend-segment { width: 100%; min-height: 2px; transition: height 0.3s ease; }
.trend-segment:first-child { border-radius: 3px 3px 0 0; }
.yoy-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 20px; }
.yoy-card { background: rgba(255,255,255,0.03); border: 1px solid var(--border); padding: 12px; border-radius: 8px; }
html.light .yoy-card { background: rgba(0,0,0,0.02); }
.yoy-card .ink-name { font-weight: 700; font-size: 14px; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.yoy-card .compare { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }

/* =========================================
   5. INVENTORY & SETTINGS
   ========================================= */
td[contenteditable] { cursor: text; outline: none; border-radius: 6px; transition: background .15s; }
td[contenteditable]:hover { background: rgba(59,130,246,.1); }
td[contenteditable]:focus { background: rgba(59,130,246,.16); box-shadow: inset 0 0 0 1px var(--accent); }
td[contenteditable].low { color: #f87171; font-weight: 700; }
.low-pill { display: inline-block; font-size: 10px; padding: 2px 7px; border-radius: 20px; background: rgba(248,113,113,.15); color: #f87171; margin-left: 8px; font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.card h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 14px; }
.theme-options { display: flex; gap: 10px; }
.theme-btn { flex: 1; padding: 12px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer; font-size: 14px; font-weight: 600; }
.theme-btn.active { border-color: var(--accent); background: rgba(59,130,246,.12); color: var(--accent); }

/* =========================================
   6. HISTORY LOG PAGE
   ========================================= */
.type-badge { font-size: 11px; padding: 3px 8px; border-radius: 12px; font-weight: 700; text-transform: uppercase; }
.type-ink { background: rgba(59,130,246,.15); color: var(--accent); }
.type-film { background: rgba(167,139,250,.15); color: var(--F2); }
.smart-trigger-input {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text); /* Solid color if manually typed */
  font-weight: 700;
  width: 60px;
  padding: 4px;
  text-align: center;
}

/* Greys out the number if it's the live system placeholder */
.smart-trigger-input::placeholder {
  color: var(--muted);
  font-weight: 400;
  opacity: 0.7;
}