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

:root{
  --bg:#F2EFE9;
  --surface:#FFFFFF;
  --surface-2:#FBF9F5;
  --ink:#211D1A;
  --muted:#756C63;
  --border:#E1DBD0;
  --wine:#7B1E3D;
  --wine-ink:#FFF7F9;
  --wine-soft:#F6E7EC;
  --honey:#B8862E;
  --honey-soft:#F6EDDB;
  --good:#2F7D4F;
  --good-soft:#E4F1E8;
  --warn:#C77A1F;
  --warn-soft:#FBEEDD;
  --bad:#B23A3A;
  --bad-soft:#FAE7E5;
  --shadow: 0 1px 2px rgba(33,29,26,0.04), 0 6px 20px -8px rgba(33,29,26,0.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#19140F; --surface:#221C17; --surface-2:#2A2319; --ink:#F1E9DE; --muted:#B2A493;
    --border:#3B3226; --wine:#E0708C; --wine-ink:#241017; --wine-soft:#3A1E28;
    --honey:#E0AA55; --honey-soft:#3B2E16; --good:#5FBE84; --good-soft:#1B2E22;
    --warn:#E0AA55; --warn-soft:#3B2E16; --bad:#E2685F; --bad-soft:#3A1E1A;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 10px 24px -10px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"]{
  --bg:#19140F; --surface:#221C17; --surface-2:#2A2319; --ink:#F1E9DE; --muted:#B2A493;
  --border:#3B3226; --wine:#E0708C; --wine-ink:#241017; --wine-soft:#3A1E28;
  --honey:#E0AA55; --honey-soft:#3B2E16; --good:#5FBE84; --good-soft:#1B2E22;
  --warn:#E0AA55; --warn-soft:#3B2E16; --bad:#E2685F; --bad-soft:#3A1E1A;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 10px 24px -10px rgba(0,0,0,0.5);
}

*{box-sizing:border-box;}
body{ background:var(--bg); color:var(--ink); font-family:'Inter',system-ui,-apple-system,sans-serif; -webkit-font-smoothing:antialiased; margin:0; }
h1,h2,h3,.display{ font-family:'Fraunces',Georgia,serif; text-wrap:balance; letter-spacing:-0.01em; }
.mono,.num{ font-family:'IBM Plex Mono',ui-monospace,monospace; font-variant-numeric:tabular-nums; }

.app{ display:flex; min-height:100vh; }

.topbar-fixed{ position:fixed; top:14px; right:18px; z-index:10; display:flex; align-items:center; gap:8px; }
.user-badge{ display:inline-flex; align-items:center; gap:7px; padding:6px 12px; border-radius:999px; background:var(--surface); border:1px solid var(--border); box-shadow:var(--shadow); font-size:0.74rem; color:var(--muted); }
.user-badge .dot{ width:7px; height:7px; border-radius:50%; background:var(--good); flex:0 0 auto; }
.theme-toggle-btn{ cursor:pointer; width:32px; height:32px; border-radius:50%; background:var(--surface); border:1px solid var(--border); box-shadow:var(--shadow); font-size:0.95rem; display:inline-flex; align-items:center; justify-content:center; padding:0; }
.theme-toggle-btn:hover{ border-color:var(--wine); }
@media (max-width:760px){ .topbar-fixed{ position:static; width:fit-content; margin:10px 16px 6px auto; } }

.sidebar{ position:relative; width:248px; flex:0 0 248px; padding:28px 18px; display:flex; flex-direction:column; gap:26px; border-right:1px solid var(--border); transition:width 0.15s ease, flex-basis 0.15s ease; }
.sidebar-toggle-btn{ position:absolute; top:24px; right:-13px; z-index:5; cursor:pointer; width:26px; height:26px; border-radius:50%; background:var(--surface); border:1px solid var(--border); box-shadow:var(--shadow); font-size:0.9rem; line-height:1; display:inline-flex; align-items:center; justify-content:center; padding:0; color:var(--muted); }
.sidebar-toggle-btn:hover{ border-color:var(--wine); color:var(--wine); }
:root[data-sidebar="collapsed"] .sidebar{ width:68px; flex-basis:68px; padding-left:10px; padding-right:10px; }
:root[data-sidebar="collapsed"] .sidebar .brand-text,
:root[data-sidebar="collapsed"] .sidebar .sub,
:root[data-sidebar="collapsed"] .sidebar .countdown,
:root[data-sidebar="collapsed"] .sidebar .label,
:root[data-sidebar="collapsed"] .sidebar .sidebar-foot{ display:none; }
:root[data-sidebar="collapsed"] .sidebar .brand{ padding:0; align-items:center; }
:root[data-sidebar="collapsed"] .sidebar nav a{ justify-content:center; padding:9px; }
.brand{ display:flex; flex-direction:column; gap:4px; padding:0 10px; }
.brand .mark{ font-family:'Fraunces',serif; font-weight:700; font-size:1.5rem; color:var(--wine); text-decoration:none; }
.brand .sub{ font-size:0.72rem; color:var(--muted); letter-spacing:0.04em; text-transform:uppercase; }
.countdown{ display:block; text-decoration:none; margin:0 10px; padding:10px 12px; background:var(--honey-soft); border-radius:10px; font-size:0.76rem; color:var(--ink); line-height:1.4; }
.countdown b{ font-family:'Fraunces',serif; font-size:1.05rem; }

nav{ display:flex; flex-direction:column; gap:2px; }
nav a{ text-decoration:none; display:flex; align-items:center; gap:10px; padding:9px 12px; border-radius:9px; font-size:0.87rem; color:var(--muted); font-weight:500; }
nav a:hover{ background:var(--surface-2); color:var(--ink); }
nav a.active{ background:var(--wine-soft); color:var(--wine); font-weight:600; }
nav .ico{ font-size:1rem; width:1.1em; text-align:center; }

.sidebar-foot{ margin-top:auto; padding:0 10px; font-size:0.72rem; color:var(--muted); border-top:1px solid var(--border); padding-top:14px; line-height:1.5; }

main{ flex:1; min-width:0; padding:28px 34px 60px; }
.topbar{ display:flex; justify-content:space-between; align-items:baseline; gap:16px; margin-bottom:22px; flex-wrap:wrap; }
.topbar h1{ font-size:1.6rem; font-weight:600; margin:0; }
.topbar .desc{ font-size:0.85rem; color:var(--muted); margin-top:2px; }

.kpis{ display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:14px; margin-bottom:26px; }
.kpi{ background:var(--surface); border:1px solid var(--border); border-radius:14px; padding:16px 18px; box-shadow:var(--shadow); }
.kpi .label{ font-size:0.72rem; text-transform:uppercase; letter-spacing:0.05em; color:var(--muted); }
.kpi .value{ font-family:'Fraunces',serif; font-size:1.7rem; font-weight:600; margin-top:6px; }
.kpi .delta{ font-size:0.76rem; margin-top:4px; }
.kpi .delta.good{ color:var(--good); }
.kpi .delta.warn{ color:var(--warn); }

.grid-2{ display:grid; grid-template-columns:1.4fr 1fr; gap:18px; align-items:start; }
@media (max-width:980px){ .grid-2{ grid-template-columns:1fr; } }

.card{ background:var(--surface); border:1px solid var(--border); border-radius:14px; box-shadow:var(--shadow); overflow:hidden; }
.card-head{ padding:16px 18px 12px; display:flex; justify-content:space-between; align-items:center; border-bottom:1px solid var(--border); }
.card-head h3{ font-size:1.02rem; font-weight:600; margin:0; }
.card-head .hint{ font-size:0.74rem; color:var(--muted); }
.card-body{ padding:14px 18px 18px; }

.progress-row{ display:flex; flex-direction:column; gap:6px; }
.bar{ height:10px; border-radius:6px; background:var(--surface-2); overflow:hidden; border:1px solid var(--border); }
.bar > span{ display:block; height:100%; background:var(--wine); border-radius:6px; }
.progress-legend{ display:flex; justify-content:space-between; font-size:0.76rem; color:var(--muted); }

.alert-list{ display:flex; flex-direction:column; gap:8px; }
.alert{ display:flex; align-items:flex-start; gap:10px; padding:10px 12px; border-radius:10px; font-size:0.84rem; background:var(--surface-2); border:1px solid var(--border); }
.alert .dot{ width:8px; height:8px; border-radius:50%; margin-top:5px; flex:0 0 auto; }
.alert.warn .dot{ background:var(--warn); }
.alert.bad .dot{ background:var(--bad); }
.alert .txt b{ font-weight:600; }
.alert .txt .meta{ display:block; color:var(--muted); font-size:0.76rem; margin-top:1px; }

table{ width:100%; border-collapse:collapse; font-size:0.86rem; }
thead th{ text-align:left; font-weight:600; font-size:0.72rem; text-transform:uppercase; letter-spacing:0.04em; color:var(--muted); padding:0 10px 8px; border-bottom:1px solid var(--border); }
tbody td{ padding:10px 10px; border-bottom:1px solid var(--border); vertical-align:middle; }
tbody tr:last-child td{ border-bottom:none; }
td.num, th.num{ text-align:right; }
.table-wrap{ overflow-x:auto; }

.pill{ display:inline-flex; align-items:center; gap:5px; padding:3px 9px; border-radius:999px; font-size:0.72rem; font-weight:600; }
.pill.good{ background:var(--good-soft); color:var(--good); }
.pill.warn{ background:var(--warn-soft); color:var(--warn); }
.pill.bad{ background:var(--bad-soft); color:var(--bad); }
.pill.neutral{ background:var(--surface-2); color:var(--muted); border:1px solid var(--border); }

.mini-bar{ width:64px; height:6px; border-radius:4px; background:var(--surface-2); border:1px solid var(--border); overflow:hidden; display:inline-block; vertical-align:middle; margin-right:6px; }
.mini-bar > span{ display:block; height:100%; background:var(--wine); }

.btn{ cursor:pointer; display:inline-flex; align-items:center; gap:6px; padding:6px 12px; border-radius:8px; font-size:0.78rem; font-weight:600; background:var(--wine); color:var(--wine-ink); border:none; text-decoration:none; }
.btn:hover{ opacity:0.92; }
.btn.ghost{ background:transparent; color:var(--ink); border:1px solid var(--border); }

.avatar{ width:30px; height:30px; border-radius:50%; background:var(--wine-soft); color:var(--wine); display:inline-flex; align-items:center; justify-content:center; font-family:'Fraunces',serif; font-weight:600; font-size:0.8rem; margin-right:8px; flex:0 0 auto; }
.who{ display:flex; align-items:center; }

.pallet{ display:flex; flex-direction:column-reverse; gap:4px; }
.pallet-piso{ display:grid; grid-template-columns:100px 1fr auto; align-items:center; gap:12px; }
.pallet-label{ text-align:right; font-family:'Fraunces',serif; font-weight:600; color:var(--wine); font-size:0.86rem; }
.pallet-stack{ min-width:0; }
.pallet-bar{ padding:3px; border-radius:5px; background:var(--surface-2); border:1px solid var(--border); }
.pallet-row{ display:flex; gap:2px; height:32px; }
.pallet-caja{ min-width:4px; border-radius:2px; box-shadow:inset 0 6px 8px -4px rgba(255,255,255,0.35), inset 0 -8px 10px -6px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.25); position:relative; }
.pallet-caja::after{ content:""; position:absolute; left:2px; right:2px; top:50%; height:1px; background:rgba(0,0,0,0.18); }
.pallet-detalle{ display:flex; flex-wrap:wrap; gap:3px 14px; padding:6px 2px 0; }
.pallet-detalle-item{ display:inline-flex; align-items:center; gap:5px; font-size:0.76rem; font-weight:600; }
.pallet-detalle-item .dot{ width:9px; height:9px; border-radius:2px; flex:0 0 auto; }
.pallet-nota{ font-size:0.72rem; color:var(--muted); padding:3px 2px 0; }
.pallet-quitar{ align-self:start; }
.pallet-base{ height:20px; margin-top:8px; border-radius:4px; background:repeating-linear-gradient(90deg, #8a6236, #8a6236 14px, #7a5530 14px, #7a5530 18px); border:1px solid var(--border); }
.pallet-legend{ display:flex; flex-wrap:wrap; gap:10px 16px; margin-top:16px; padding-top:12px; border-top:1px solid var(--border); }
.pallet-legend-item{ display:inline-flex; align-items:center; gap:6px; font-size:0.76rem; color:var(--muted); }
.pallet-legend .dot{ width:10px; height:10px; border-radius:3px; flex:0 0 auto; }

.msg-card{ background:var(--surface-2); border:1px solid var(--border); border-radius:12px; padding:14px 16px; font-size:0.82rem; white-space:pre-wrap; line-height:1.5; max-height:260px; overflow-y:auto; }
.msg-card b{ color:var(--wine); }

.tag-row{ display:flex; flex-wrap:wrap; gap:6px; margin-top:8px;}
.tag{ font-size:0.72rem; padding:3px 8px; border-radius:6px; background:var(--honey-soft); color:var(--honey); font-weight:600; }

.empty-note{ font-size:0.78rem; color:var(--muted); padding:10px 0; }

.filter-row{ display:flex; gap:8px; flex-wrap:wrap; margin-bottom:16px; }
.filter-chip{
  display:inline-flex; align-items:center; gap:6px;
  padding:6px 12px; border-radius:999px; font-size:0.82rem; font-weight:500;
  background:var(--surface); border:1px solid var(--border); color:var(--muted); text-decoration:none;
}
.filter-chip:hover{ border-color:var(--wine); color:var(--ink); }
.filter-chip.active{ background:var(--wine-soft); border-color:var(--wine); color:var(--wine); font-weight:600; }
.filter-chip.bad.active{ background:var(--bad-soft); border-color:var(--bad); color:var(--bad); }
.filter-chip.warn.active{ background:var(--warn-soft); border-color:var(--warn); color:var(--warn); }
.filter-chip.good.active{ background:var(--good-soft); border-color:var(--good); color:var(--good); }

.form-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(200px,1fr)); gap:16px; }
.field{ display:flex; flex-direction:column; gap:5px; }
.field.wide{ grid-column:1 / -1; }
.field label{ font-size:0.76rem; font-weight:600; color:var(--muted); text-transform:uppercase; letter-spacing:0.03em; }
.field input, .field select, .field textarea{
  font-family:'Inter',sans-serif; font-size:0.88rem; color:var(--ink);
  background:var(--surface-2); border:1px solid var(--border); border-radius:8px;
  padding:8px 10px; width:100%;
}
.field input:focus, .field select:focus, .field textarea:focus{ outline:2px solid var(--wine); outline-offset:1px; }
.form-actions{ display:flex; gap:10px; margin-top:20px; }
.btn-link{ background:none; border:none; padding:0; color:var(--bad); font-size:0.78rem; font-weight:600; cursor:pointer; text-decoration:underline; }

@media (max-width:760px){
  .app{ flex-direction:column; }
  .sidebar{ width:100%; flex:none; flex-direction:row; overflow-x:auto; border-right:none; border-bottom:1px solid var(--border); padding:14px; }
  .brand,.countdown,.sidebar-foot{ display:none; }
  nav{ flex-direction:row; }
  main{ padding:20px 16px 40px; }
  .pallet-piso{ grid-template-columns:1fr; row-gap:4px; }
  .pallet-label{ text-align:left; }
  .pallet-quitar{ justify-self:start; }
}
