/* IDEA pakowania 2.0 - dashboard pakowni. Czytany z 3 metrów, dark mode domyślny. */

@font-face {
  font-family: 'Montserrat';
  src: url('/static/fonts/Montserrat-VariableFont_wght.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0A0A0B;
  --surface: #141416;
  --surface-2: #1A1A1D;
  --surface-hover: rgba(244, 244, 245, 0.06);
  --border: #1F1F23;
  --border-strong: #2A2A30;
  --fg: #F4F4F5;
  --fg-secondary: rgba(244, 244, 245, 0.62);
  --fg-tertiary: rgba(244, 244, 245, 0.4);
  --fg-quaternary: rgba(244, 244, 245, 0.2);
  --accent: #3B82F6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --accent-ring: rgba(59, 130, 246, 0.4);
  --success: #10B981;
  --success-soft: rgba(16, 185, 129, 0.15);
  --warning: #F59E0B;
  --warning-soft: rgba(245, 158, 11, 0.15);
  --danger: #EF4444;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --overlay: rgba(0, 0, 0, 0.6);
  --font-sans: 'Montserrat', 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Mono', 'Consolas', 'JetBrains Mono', Menlo, monospace;
  --radius: 12px;
  --radius-sm: 6px;
  --radius-pill: 999px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

:root[data-theme="light"] {
  --bg: #FAFAFA; --surface: #FFFFFF; --surface-2: #F4F4F5; --surface-hover: rgba(10,10,11,0.05);
  --border: #E4E4E7; --border-strong: #D4D4D8;
  --fg: #09090B; --fg-secondary: rgba(9,9,11,0.65); --fg-tertiary: rgba(9,9,11,0.45); --fg-quaternary: rgba(9,9,11,0.2);
  --overlay: rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font-sans); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.ico-sm { width: 16px; height: 16px; }

.mono, .mono-num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.fg { color: var(--fg); }
.meta { color: var(--fg-tertiary); font-size: 13px; }
.sep { color: var(--fg-quaternary); margin: 0 8px; }
.t-label { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--fg-secondary); line-height: 1.2; }

/* --- layout ------------------------------------------------------------- */
.app { height: 100vh; display: flex; flex-direction: column; padding: 0 16px 16px; gap: 12px; overflow: hidden; }

.topbar { height: 52px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; border-bottom: 1px solid var(--border); flex: none; }
.topbar-title { font-weight: 700; letter-spacing: 0.02em; color: var(--fg-secondary); font-size: 14px; text-transform: uppercase; }
.topbar-actions { display: flex; justify-content: flex-end; align-items: center; gap: 6px; }
.live { display: flex; align-items: center; font-size: 14px; color: var(--fg-secondary); white-space: nowrap; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--success); margin-right: 8px; box-shadow: 0 0 0 3px var(--success-soft); }
.live-dot.stale { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.live-dot.err { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.live-dot.busy { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.icon-btn { position: relative; display: inline-flex; align-items: center; gap: 6px; background: transparent; border: 0; border-radius: var(--radius-sm); padding: 8px; color: var(--fg-secondary); transition: background 120ms, color 120ms; }
.icon-btn:hover { background: var(--surface-hover); color: var(--fg); }
.icon-btn.alert-active { color: var(--danger); }
.icon-btn.alert-muted { color: var(--warning); }
.alert-chip { font-family: var(--font-mono); font-size: 12px; font-weight: 700; background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-pill); padding: 2px 8px; }
.alert-muted .alert-chip { background: var(--warning-soft); color: var(--warning); }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.12); opacity: 0.7; } }
.alert-active:not(.alert-muted) svg { animation: pulse 1.6s ease-in-out infinite; }

.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); padding: 8px 14px; font-weight: 600; font-size: 14px; transition: background 120ms, border-color 120ms; }
.btn:hover { background: var(--surface-2); border-color: var(--fg-quaternary); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #2f6fd6; border-color: #2f6fd6; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn .ico { width: 18px; height: 18px; }
.btn.busy .ico { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 16px; border-radius: var(--radius-sm); font-size: 14px; flex: none; }
.banner-info { background: var(--accent-soft); color: var(--fg); border: 1px solid rgba(59,130,246,0.35); }
.banner-danger { background: var(--danger-soft); color: var(--fg); border: 1px solid rgba(239,68,68,0.4); }

.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; }
.empty-title { font-size: 32px; font-weight: 700; }
.empty-sub { color: var(--fg-secondary); max-width: 640px; }

/* --- siatka główna ------------------------------------------------------- */
.main { flex: 1; min-height: 0; display: grid; gap: 12px;
  grid-template-columns: 2fr 1fr 1fr;
  grid-template-rows: minmax(220px, 1.25fr) minmax(170px, 0.9fr) minmax(0, 1.35fr);
  grid-template-areas: "hero hero today" "packed new balance" "packers packers packers"; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 22px; min-height: 0; display: flex; flex-direction: column; }
.hero { grid-area: hero; justify-content: center; }
.today { grid-area: today; justify-content: center; }
.tile-packed { grid-area: packed; }
.tile-new { grid-area: new; }
.tile-balance { grid-area: balance; }
.packers { grid-area: packers; }

.hero-value { font-size: clamp(96px, 15vh, 180px); font-weight: 800; line-height: 1; letter-spacing: -0.04em; margin: 6px 0 10px; }
.chips { display: flex; gap: 10px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: var(--radius-pill); background: var(--surface-2); border: 1px solid var(--border); font-size: 15px; }
.chip-label { color: var(--fg-secondary); }
.chip-val { font-family: var(--font-mono); font-weight: 700; font-size: 18px; }

.today-row { display: flex; align-items: baseline; gap: 12px; margin: 8px 0 6px; }
.today-val { font-size: clamp(48px, 7vh, 80px); font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.today-unit { color: var(--fg-secondary); font-size: 18px; }
.today-meta { color: var(--fg-secondary); font-size: 14px; display: flex; flex-direction: column; gap: 2px; }

.tile-line { display: flex; align-items: baseline; gap: 10px; margin-top: 8px; }
.tile-val { font-size: clamp(56px, 8.5vh, 96px); font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.tile-unit { color: var(--fg-secondary); font-size: 18px; }
.tile-sub { color: var(--fg-tertiary); font-size: 13px; margin-top: auto; }
.tile-val.pos { color: var(--success); }
.tile-val.neg { color: var(--danger); }
.tile-val.zero { color: var(--fg-secondary); }

.tile-packed { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto 1fr; column-gap: 20px; }
.tile-packed .t-label { grid-column: 1 / 3; }
.spark-wrap { position: relative; align-self: end; min-width: 0; }
.spark { width: 100%; height: 64px; display: block; overflow: visible; }
.spark rect.bar { fill: var(--accent); opacity: 0.85; }
.spark rect.bar.partial { opacity: 0.45; }
.spark rect.hit { fill: transparent; }
.spark rect.hit:hover + rect.bar, .spark g:hover rect.bar { opacity: 1; }
.spark-axis { display: flex; justify-content: space-between; color: var(--fg-quaternary); font-size: 11px; margin-top: 4px; font-family: var(--font-mono); }
.spark-tip, .heat-tip { position: absolute; pointer-events: none; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 6px 10px; font-size: 13px; white-space: nowrap; z-index: 5; box-shadow: 0 8px 24px rgba(0,0,0,0.5); }

/* --- pakowacze ---------------------------------------------------------- */
.packers-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.packers-body { flex: 1; min-height: 0; overflow: auto; margin-top: 12px; }
.packers-empty { color: var(--fg-secondary); padding: 24px 0; max-width: 900px; line-height: 1.6; }
.packers-empty strong { color: var(--fg); }
.packer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.packer { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto auto; column-gap: 12px; }
.packer.idle { opacity: 0.55; }
.packer-name { grid-column: 1 / 3; display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; overflow: hidden; }
.packer-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.packer-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--success); flex: none; box-shadow: 0 0 0 3px var(--success-soft); }
.packer.idle .packer-dot { background: var(--fg-quaternary); box-shadow: none; }
.packer-rate { font-size: 56px; font-weight: 800; line-height: 1; letter-spacing: -0.03em; margin-top: 8px; }
.packer-rate small { font-size: 14px; font-weight: 500; color: var(--fg-secondary); letter-spacing: 0; margin-left: 6px; }
.packer-today { align-self: end; text-align: right; color: var(--fg-secondary); font-size: 13px; line-height: 1.3; }
.packer-today b { display: block; color: var(--fg); font-size: 20px; font-family: var(--font-mono); }
.packer-last { grid-column: 1 / 3; color: var(--fg-tertiary); font-size: 13px; margin-top: 6px; }
.packer-bar { grid-column: 1 / 3; height: 4px; background: var(--border); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.packer-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* --- modale --------------------------------------------------------------- */
.overlay { position: fixed; inset: 0; background: var(--overlay); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px; }
.modal { width: min(720px, 100%); max-height: 92vh; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 16px; box-shadow: 0 24px 64px -16px rgba(0,0,0,0.7); display: flex; flex-direction: column; overflow: hidden; }
.modal-wide { width: min(1320px, 100%); }
.modal-head { display: flex; align-items: center; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 20px; font-weight: 600; flex: 1; }
.modal-body { padding: 20px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.section-h { margin: 8px 0 0; font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-secondary); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; color: var(--fg-secondary); }
.field-row { display: flex; align-items: center; gap: 8px; }
.field-check label { display: flex; align-items: center; gap: 10px; color: var(--fg); }
.field-hint { font-size: 12px; color: var(--fg-tertiary); }
.field-suffix { color: var(--fg-tertiary); font-size: 13px; }
.input { background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 12px; min-width: 0; flex: 1; outline: none; }
.input:focus { box-shadow: 0 0 0 2px var(--accent-ring); border-color: var(--accent); }
.input[readonly] { color: var(--fg-secondary); }
.num-input { max-width: 160px; font-family: var(--font-mono); font-size: 18px; font-weight: 600; flex: none; }
.secret { user-select: none; -webkit-user-select: none; }
.lock { color: var(--fg-tertiary); }
.conn-status { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.conn-ok { color: var(--success); } .conn-err { color: var(--danger); }
.form-error { background: var(--danger-soft); border: 1px solid rgba(239,68,68,0.4); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; }
.sync-log summary { cursor: pointer; color: var(--fg-secondary); font-size: 14px; }
.sync-log table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; font-family: var(--font-mono); }
.sync-log td { padding: 4px 6px; border-top: 1px solid var(--border); vertical-align: top; }
.sync-log td.err { color: var(--danger); white-space: normal; }

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button { background: transparent; border: 0; padding: 6px 14px; font-size: 13px; font-weight: 600; color: var(--fg-secondary); }
.segmented button.on { background: var(--accent-soft); color: var(--fg); }

/* --- historia --------------------------------------------------------------- */
.history-section { display: flex; flex-direction: column; gap: 10px; }
.heatmap-wrap, .barchart-wrap { position: relative; }
.heatmap { display: grid; grid-template-columns: 92px repeat(24, 1fr); gap: 3px; font-size: 11px; }
.heat-corner { }
.heat-h { text-align: center; color: var(--fg-quaternary); font-family: var(--font-mono); }
.heat-day { display: flex; justify-content: space-between; align-items: center; padding-right: 8px; color: var(--fg-secondary); font-family: var(--font-mono); white-space: nowrap; }
.heat-day b { color: var(--fg); font-weight: 600; }
.heat-cell { aspect-ratio: 1.9 / 1; min-height: 14px; border-radius: 3px; background: rgba(255,255,255,0.03); }
.heat-cell:hover { outline: 2px solid var(--fg); outline-offset: -1px; }
.heat-legend { display: flex; align-items: center; gap: 8px; margin-top: 6px; color: var(--fg-tertiary); font-size: 12px; }
.heat-grad { width: 140px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, rgba(59,130,246,0.1), #3B82F6); }
.barchart { width: 100%; height: 200px; display: block; overflow: visible; }
.barchart rect.bar { fill: var(--accent); }
.barchart rect.bar:hover { fill: #74a7ff; }
.barchart text { fill: var(--fg-tertiary); font-size: 11px; font-family: var(--font-mono); }
.barchart line.grid { stroke: var(--border); }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.summary-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.summary-val { font-size: 36px; font-weight: 800; line-height: 1.1; margin-top: 6px; font-variant-numeric: tabular-nums; }
.summary-unit { color: var(--fg-secondary); font-size: 13px; }

@media (max-width: 1100px) {
  .main { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto auto auto;
    grid-template-areas: "hero hero" "today packed" "new balance" "packers packers"; }
  .app { overflow: auto; height: auto; min-height: 100vh; }
  .hero-value { font-size: 96px; }
}
@media (max-width: 700px) {
  .main { grid-template-columns: 1fr; grid-template-areas: "hero" "today" "packed" "new" "balance" "packers"; }
  .topbar { grid-template-columns: 1fr auto; } .topbar-title { display: none; }
  .tile-packed { grid-template-columns: 1fr; }
}
