/* COB — App + component styles
   Built on tokens. Utility-ish where useful; semantic class names everywhere else.
*/

/* Layout shell ---------------------------------------------- */
.app {
  display: grid;
  grid-template-rows: var(--band-h) auto 1fr var(--footer-h);
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-areas:
    "band band"
    "topbar topbar"
    "sidebar main"
    "footer footer";
  min-height: 100vh;
  min-width: 1280px;
}
.sidebar a.nav-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app[data-sidebar="collapsed"] { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

.state-band {
  grid-area: band;
  background: var(--state-idle);
  position: relative;
  overflow: hidden;
}
.app[data-state="active"] .state-band { background: var(--state-active); }
.app[data-state="manual"] .state-band { background: var(--state-manual); }
.app[data-state="rollback"] .state-band {
  background: var(--danger);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* Topbar ---------------------------------------------------- */
.topbar {
  grid-area: topbar;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: stretch;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-right: 1px solid var(--line);
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  transition: width 160ms ease;
}
.app[data-sidebar="collapsed"] .topbar-logo {
  width: var(--sidebar-w-collapsed);
  min-width: var(--sidebar-w-collapsed);
  padding: 0;
  justify-content: center;
}
.topbar-logo .mark {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--r-2);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: var(--tr-loud);
}
.topbar-logo .word {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--t-sm);
  letter-spacing: var(--tr-loud);
}
.topbar-state {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  flex: 1;
  min-width: 0;
}
.topbar-state .state-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 8px;
  border-radius: var(--r-full);
  font-size: var(--t-2xs);
  font-family: var(--font-mono);
  letter-spacing: var(--tr-shout);
  font-weight: 600;
  background: var(--state-idle-bg);
  color: var(--state-idle);
}
.app[data-state="active"] .topbar-state .state-pill {
  background: var(--state-active-bg);
  color: var(--state-active);
}
.app[data-state="manual"] .topbar-state .state-pill {
  background: var(--state-manual-bg);
  color: var(--state-manual);
}
.app[data-state="rollback"] .topbar-state .state-pill {
  background: var(--danger-bg);
  color: var(--danger);
}
.state-pill .dot {
  width: 8px; height: 8px;
  border-radius: 999px;
  background: currentColor;
}
.app[data-state="active"] .state-pill .dot,
.app[data-state="rollback"] .state-pill .dot {
  animation: heartbeat 1.4s ease-in-out infinite;
}
@keyframes heartbeat {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.35); opacity: 0.7; }
}
.topbar-state .run-id {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  color: var(--muted);
  letter-spacing: var(--tr-wide);
}
.topbar-state .run-id strong { color: var(--ink); font-weight: 500; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px 0 0;
}

/* Sidebar ---------------------------------------------------- */
.sidebar {
  grid-area: sidebar;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 16px 12px 24px;
  overflow-y: auto;
  position: sticky;
  top: calc(var(--band-h) + var(--topbar-h));
  height: calc(100vh - var(--band-h) - var(--topbar-h) - var(--footer-h));
}
.sidebar-section {
  margin-bottom: 14px;
}
.sidebar-section-label {
  padding: 6px 10px;
  font-size: var(--t-3xs);
  font-family: var(--font-mono);
  letter-spacing: var(--tr-shout);
  color: var(--muted-2);
  text-transform: uppercase;
}
.app[data-sidebar="collapsed"] .sidebar-section-label { display: none; }
.sidebar a.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--r-3);
  color: var(--ink-2);
  font-size: var(--t-sm);
  font-weight: 500;
  position: relative;
  cursor: pointer;
}
.sidebar a.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.sidebar a.nav-item.active {
  background: var(--accent-soft);
  color: var(--ink);
}
.sidebar a.nav-item.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--accent);
  border-radius: 2px;
}
.sidebar a.nav-item .ic { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.75; }
.sidebar a.nav-item.active .ic { opacity: 1; }
.sidebar a.nav-item .badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--t-3xs);
  letter-spacing: var(--tr-wide);
  color: var(--muted);
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: var(--r-full);
}
.sidebar a.nav-item.urgent {
  color: var(--state-active);
}
.app[data-state="active"] .sidebar a.nav-item.urgent .badge,
.app[data-state="rollback"] .sidebar a.nav-item.urgent .badge {
  background: var(--state-active-bg);
  color: var(--state-active);
}
.sidebar .user-card {
  margin-top: auto;
  padding: 10px 10px;
  border-top: 1px solid var(--line-2);
  display: flex;
  align-items: center;
  gap: 10px;
}
.app[data-sidebar="collapsed"] .sidebar a.nav-item { justify-content: center; padding: 0; }
.app[data-sidebar="collapsed"] .sidebar a.nav-item span:not(.ic):not(.badge) { display: none; }
.app[data-sidebar="collapsed"] .sidebar a.nav-item .badge { display: none; }

/* Main ------------------------------------------------------ */
.main {
  grid-area: main;
  min-width: 0;
  background: var(--bg);
}
.page-h {
  padding: 24px 32px 16px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.page-h h1 {
  margin: 0;
  font-size: var(--t-3xl);
  font-weight: 600;
  letter-spacing: var(--tr-tight);
  line-height: 1.1;
}
.page-h .crumbs {
  font-size: var(--t-xs);
  font-family: var(--font-mono);
  color: var(--muted);
  letter-spacing: var(--tr-wide);
  margin-bottom: 6px;
  text-transform: uppercase;
}
.page-h .sub {
  color: var(--muted);
  font-size: var(--t-md);
  margin-top: 4px;
}
.page-h .actions { display: flex; gap: 8px; align-items: center; }
.page-body { padding: 24px 32px 80px; }

/* Footer ---------------------------------------------------- */
.footer {
  grid-area: footer;
  border-top: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-family: var(--font-mono);
  font-size: var(--t-3xs);
  letter-spacing: var(--tr-wide);
  color: var(--muted);
  height: var(--footer-h);
}
.footer .dotline { display: flex; gap: 14px; align-items: center; }
.footer .dotline > * { display: flex; gap: 5px; align-items: center; }
.footer .led { width: 6px; height: 6px; border-radius: 999px; background: var(--success); }
.footer .led.warn { background: var(--warning); }
.footer .led.bad  { background: var(--danger); }

/* ============================================================
   Primitives
   ============================================================ */

/* Button ---------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--ctl-h);
  padding: 0 12px;
  border-radius: var(--r-3);
  font-size: var(--t-sm);
  font-weight: 500;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  white-space: nowrap;
  transition: background 100ms ease, border-color 100ms ease, transform 80ms ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn.btn-lg { height: var(--ctl-h-lg); padding: 0 16px; font-size: var(--t-md); }
.btn.btn-sm { height: 24px; padding: 0 8px; font-size: var(--t-xs); border-radius: var(--r-2); }
.btn.primary {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
}
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .ic { width: 14px; height: 14px; }
.btn.icon-only { width: var(--ctl-h); padding: 0; justify-content: center; }
.btn.icon-only.btn-sm { width: 24px; }

/* Chip / tag ------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-2);
  font-size: var(--t-2xs);
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: var(--tr-wide);
  background: var(--surface-2);
  color: var(--ink-2);
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1.4;
}
.chip.lg { font-size: var(--t-xs); padding: 3px 10px; }
.chip.alloc    { background: var(--alloc-bg); color: var(--alloc); }
.chip.alloc-2  { background: var(--alloc-2-bg); color: var(--alloc-2); }
.chip.alloc-3  { background: var(--alloc-3-bg); color: var(--alloc-3); }
.chip.bilan    { background: var(--bilan-bg); color: var(--bilan); border: 1px dashed var(--bilan); padding: 1px 7px; }
.chip.bilan-2  { background: var(--bilan-2-bg); color: var(--bilan-2); border: 1px dashed var(--bilan-2); padding: 1px 7px; }
.chip.idle     { background: var(--state-idle-bg); color: var(--state-idle); }
.chip.active   { background: var(--state-active-bg); color: var(--state-active); }
.chip.manual   { background: var(--state-manual-bg); color: var(--state-manual); }
.chip.danger   { background: var(--danger-bg); color: var(--danger); }
.chip.success  { background: var(--success-bg); color: var(--success); }

/* Card ------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-4);
  box-shadow: var(--shadow-sm);
}
.card.flat { box-shadow: none; }
.card-h {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-h .title {
  font-size: var(--t-2xs);
  font-family: var(--font-mono);
  letter-spacing: var(--tr-shout);
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 500;
}
.card-body { padding: var(--pad-card); }

/* KPI ------------------------------------------------------- */
.kpi {
  padding: 16px 16px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-4);
  display: flex; flex-direction: column;
  gap: 2px;
}
.kpi .label {
  font-size: var(--t-2xs);
  font-family: var(--font-mono);
  letter-spacing: var(--tr-shout);
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 500;
}
.kpi .value {
  font-family: var(--font-mono);
  font-size: var(--t-3xl);
  font-weight: 500;
  letter-spacing: var(--tr-tight);
  font-feature-settings: "tnum";
  line-height: 1.15;
}
.kpi .value .unit { font-size: var(--t-md); color: var(--muted); margin-left: 4px; }
.kpi .delta {
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  color: var(--muted);
  margin-top: 6px;
}
.kpi .delta.up { color: var(--success); }
.kpi .delta.down { color: var(--danger); }
.kpi .spark { margin-top: 10px; height: 22px; }

/* Table ----------------------------------------------------- */
.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--t-sm);
}
.tbl th, .tbl td {
  text-align: left;
  padding: var(--pad-cell);
  border-bottom: 1px solid var(--line-2);
  vertical-align: middle;
}
.tbl th {
  font-size: var(--t-2xs);
  font-family: var(--font-mono);
  letter-spacing: var(--tr-shout);
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr.selected { background: var(--accent-soft); }
.tbl td.mono { font-family: var(--font-mono); }
.tbl td.num  { font-family: var(--font-mono); text-align: right; font-feature-settings: "tnum"; }
.tbl th.num  { text-align: right; }

/* Input ----------------------------------------------------- */
.input, .select {
  height: var(--ctl-h);
  border-radius: var(--r-3);
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0 10px;
  font-size: var(--t-sm);
  width: 100%;
  outline: none;
}
.input:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field {
  display: flex; flex-direction: column; gap: 4px;
}
.field label {
  font-size: var(--t-2xs);
  font-family: var(--font-mono);
  letter-spacing: var(--tr-shout);
  text-transform: uppercase;
  color: var(--muted);
}

/* Toolbar --------------------------------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-2);
  background: var(--surface-2);
}
.toolbar .spacer { flex: 1; }
.search {
  display: flex; align-items: center; gap: 6px;
  height: var(--ctl-h);
  padding: 0 10px;
  border-radius: var(--r-3);
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: var(--t-sm);
  color: var(--muted);
  min-width: 200px;
}
.search input { border: 0; outline: none; background: transparent; flex: 1; padding: 0; }
.search .kbd {
  font-family: var(--font-mono);
  font-size: var(--t-3xs);
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted-2);
}

/* Bar / progress -------------------------------------------- */
.bar {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 200ms ease;
}
.bar.alloc > span { background: var(--alloc); }
.bar.bilan > span { background: var(--bilan); }
.bar.thick { height: 8px; }

/* Diagonal hatch (BILANCIAMENTO motif) ---------------------- */
.hatch {
  background-image: repeating-linear-gradient(
    45deg,
    currentColor 0 1px,
    transparent 1px 6px
  );
}

/* Dividers / lines ------------------------------------------ */
.label {
  font-size: var(--t-2xs);
  font-family: var(--font-mono);
  letter-spacing: var(--tr-shout);
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}
.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.tnum { font-feature-settings: "tnum"; }

/* Tab nav --------------------------------------------------- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  padding: 0 32px;
  background: var(--surface);
  margin: 0;
}
.tabs .tab {
  padding: 10px 14px 10px;
  font-size: var(--t-sm);
  color: var(--muted);
  font-weight: 500;
  position: relative;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
}
.tabs .tab:hover { color: var(--ink); }
.tabs .tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.tabs .tab .count {
  font-family: var(--font-mono);
  font-size: var(--t-3xs);
  margin-left: 6px;
  color: var(--muted);
}

/* Layout helpers ------------------------------------------- */
.row { display: flex; gap: var(--s-3); }
.col { display: flex; flex-direction: column; gap: var(--s-3); }
.between { justify-content: space-between; }
.center { align-items: center; }
.grow { flex: 1; min-width: 0; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.grid { display: grid; gap: var(--s-3); }

/* Empty state ----------------------------------------------- */
.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}
.empty .title { font-size: var(--t-lg); color: var(--ink); margin-bottom: 4px; }

/* Pulse / status indicators --------------------------------- */
.pulse-dot {
  width: 8px; height: 8px;
  border-radius: 999px;
  background: var(--state-active);
  position: relative;
}
.pulse-dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 999px;
  border: 2px solid var(--state-active);
  animation: ripple 1.4s ease-out infinite;
}
@keyframes ripple {
  0%   { opacity: 0.7; transform: scale(0.6); }
  100% { opacity: 0;   transform: scale(1.6); }
}

/* Drag handle, slot indicators ------------------------------ */
.drag-handle {
  width: 10px; height: 14px;
  display: inline-flex;
  flex-wrap: wrap;
  align-content: center;
  gap: 2px;
  cursor: grab;
  opacity: 0.4;
}
.drag-handle span {
  width: 2px; height: 2px; border-radius: 1px; background: currentColor;
}
.drag-handle:hover { opacity: 0.8; }

/* ── Warehouse-map drag-drop visual feedback ───────────────────────── */
/* Drives the after-drop confirmation glow (.slot-landed), reject shake
   (.slot-reject), and the accept-hover pulse (.wm-hover-accept). The
   inline styles in WarehouseMap.jsx set background, border, box-shadow,
   and cursor per state; the CSS layer only carries animations and the
   ⇄ swap glyph. `prefers-reduced-motion` stills all motion. */
.wm-hover-accept {
  animation: wm-drop-pulse 1.2s ease-in-out infinite;
}
@keyframes wm-drop-pulse {
  0%, 100% { box-shadow: inset 0 0 0 2px var(--success); }
  50%      { box-shadow: inset 0 0 0 3px var(--success), 0 0 0 3px var(--success-bg); }
}
.slot-landed {
  animation: wm-drop-land 480ms ease-out;
}
@keyframes wm-drop-land {
  0%   { box-shadow: 0 0 0 0 var(--success); }
  60%  { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.slot-reject {
  animation: wm-drop-reject 240ms ease;
}
@keyframes wm-drop-reject {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-3px); }
  40%, 80% { transform: translateX(3px); }
}
.wm-hover-swap { position: relative; }
.wm-hover-swap::after {
  content: "\21C4";              /* ⇄ */
  position: absolute;
  top: 1px; right: 3px;
  font-size: 10px;
  color: var(--warning);
  font-weight: 700;
  pointer-events: none;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.25);
}
@media (prefers-reduced-motion: reduce) {
  .wm-hover-accept,
  .slot-landed,
  .slot-reject { animation: none !important; }
}

/* ── Skeleton + top loading bar ─────────────────────────────────────── */
/* Shared primitives live in screens/_skeleton.jsx. Token swap (light/dark)
   is handled automatically by tokens.css. `prefers-reduced-motion` is
   respected — shimmer is stilled, top bar stops sliding. */

@keyframes cob-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
@keyframes cob-loadingbar {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(300%);  }
}

.cob-skeleton {
  display: inline-block;
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--line) 50%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  animation: cob-shimmer 1.4s ease-in-out infinite;
  border-radius: 4px;
  vertical-align: middle;
}

.cob-skeleton-card,
.cob-skeleton-chart {
  /* Card-shaped placeholders inherit surface/line tokens via inline style.
     This rule exists so callers can theme via class without inline style. */
  position: relative;
}

.cob-loadingbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  pointer-events: none;
  background: var(--line);
  overflow: hidden;
}
.cob-loadingbar > span {
  display: block;
  height: 100%;
  background: var(--ink-2);
  width: 0%;
  transition: width 0.25s ease;
}
.cob-loadingbar.indet > span {
  width: 33%;
  animation: cob-loadingbar 1.1s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .cob-skeleton {
    animation: none;
    opacity: 0.6;
  }
  .cob-loadingbar.indet > span {
    animation: none;
    width: 33%;
  }
}
