/* Kapeleta — back office (admin.html) */

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.admin { background: var(--espresso-deep); }
.r { text-align: right; }

.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }

/* ---------- Sidebar ---------- */
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px; padding: 26px 18px 20px;
  border-right: 1px solid var(--line); background: var(--espresso-deep); overflow-y: auto;
}
.side .brand { padding: 0 8px; }
.side .brand__word { font-size: 1.45rem; }
.side .brand__mark { width: 30px; height: 30px; }
.side__tag { margin: 6px 0 22px 49px; font-size: var(--t-label); letter-spacing: 0.16em; text-transform: uppercase; color: var(--cream-3); font-weight: 600; }
.side__nav, .side__links { display: grid; gap: 2px; }
.side__links { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.side a:not(.brand) {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px; border-radius: 10px;
  font-size: 0.92rem; font-weight: 500; color: var(--cream-2); transition: background-color 0.2s, color 0.2s;
}
.side a:not(.brand) svg { width: 19px; height: 19px; flex: none; opacity: 0.85; }
.side a:not(.brand):hover { background: rgba(244, 231, 212, 0.05); color: var(--cream); }
.side__nav a.is-on { background: rgba(244, 231, 212, 0.08); color: var(--cream); }
.side__nav a.is-on::before { content: ''; position: absolute; left: -18px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--saffron); }
.side__nav a.is-on svg { color: var(--saffron); opacity: 1; }
.count { margin-left: auto; min-width: 24px; padding: 2px 7px; border-radius: 999px; background: rgba(244, 231, 212, 0.1); font-size: 0.72rem; font-weight: 700; text-align: center; color: var(--cream); }
.count--warn { background: var(--alert); color: var(--espresso); }
.side__user { display: flex; align-items: center; gap: 12px; margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--line); font-size: 0.88rem; }
.side__user b { display: block; font-weight: 600; }
.side__user small { color: var(--cream-3); }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--mocha); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em; flex: none; }

/* ---------- Main ---------- */
.main { min-width: 0; padding: 28px clamp(20px, 3vw, 44px) 40px; background: var(--espresso); }
.topbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 20px; padding-bottom: 26px; }
.topbar__date { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--cream-2); font-size: 0.9rem; }
.topbar__title { margin-top: 10px; font-family: var(--f-display); font-weight: 360; font-size: clamp(2rem, 1.5rem + 1.6vw, 2.9rem); line-height: 1; letter-spacing: -0.025em; font-variation-settings: 'opsz' 144, 'SOFT' 50; }
.topbar__title em { font-style: italic; font-weight: 300; color: var(--saffron); font-variation-settings: 'opsz' 144, 'SOFT' 100, 'WONK' 1; }
.topbar__actions { display: flex; gap: 10px; }
.topbar__actions .btn svg { width: 16px; height: 16px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line-2); font-size: 0.76rem; font-weight: 600; color: var(--cream-2); white-space: nowrap; }
.pill svg { width: 14px; height: 14px; }
.pill--accent { border-color: rgba(231, 164, 60, 0.5); background: var(--saffron-lo); color: var(--saffron); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { padding: 20px 22px; border-radius: var(--r); background: var(--roast); border: 1px solid var(--line); }
.kpi__label { font-size: var(--t-label); letter-spacing: 0.14em; text-transform: uppercase; color: var(--cream-3); font-weight: 600; }
.kpi__value { margin-top: 10px; font-family: var(--f-display); font-weight: 380; font-size: clamp(1.9rem, 1.5rem + 1vw, 2.5rem); line-height: 1; letter-spacing: -0.02em; font-variation-settings: 'opsz' 144, 'SOFT' 40; }
.kpi__note { margin-top: 10px; font-size: 0.85rem; color: var(--cream-2); }
.kpi__note b { color: var(--cream); font-weight: 600; }
.kpi__note .up { color: var(--ok); }

/* Panels */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.panel { min-width: 0; padding: 22px 24px 24px; border-radius: var(--r); background: var(--roast); border: 1px solid var(--line); }
.panel--orders { grid-column: 1 / span 8; grid-row: span 2; }
.panel--chart { grid-column: 9 / span 4; display: flex; flex-direction: column; }
.panel--subs { grid-column: 9 / span 4; }
.panel--roast { grid-column: span 12; }
.panel--stock { grid-column: span 12; }
.panel__head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 14px 20px; margin-bottom: 18px; }
.panel__title { font-family: var(--f-display); font-weight: 420; font-size: 1.4rem; line-height: 1.1; letter-spacing: -0.01em; font-variation-settings: 'opsz' 48, 'SOFT' 50; }
.panel__sub { margin-top: 4px; font-size: 0.85rem; color: var(--cream-3); }
.panel__sub b { color: var(--cream); font-weight: 600; }

.search { position: relative; display: flex; align-items: center; min-width: min(280px, 100%); }
.search svg { position: absolute; left: 12px; width: 17px; height: 17px; color: var(--cream-3); pointer-events: none; }
.search input { width: 100%; min-height: 40px; padding: 0 14px 0 38px; border-radius: 999px; border: 1px solid var(--line-2); background: rgba(244, 231, 212, 0.04); font-size: 0.88rem; transition: border-color 0.2s, box-shadow 0.2s; }
.search input::placeholder { color: var(--cream-3); }
.search input:hover { border-color: var(--cream-3); }
.search input:focus-visible { outline: none; border-color: var(--saffron); box-shadow: 0 0 0 3px var(--saffron-lo); }

.tabs { display: flex; gap: 4px; margin-bottom: 8px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { position: relative; display: inline-flex; align-items: center; gap: 7px; flex: none; padding: 10px 12px 12px; font-size: 0.88rem; font-weight: 500; color: var(--cream-3); transition: color 0.2s; }
.tabs button:hover { color: var(--cream); }
.tabs button span { padding: 1px 7px; border-radius: 999px; background: rgba(244, 231, 212, 0.08); font-size: 0.72rem; font-weight: 700; }
.tabs button[aria-pressed='true'] { color: var(--cream); }
.tabs button[aria-pressed='true']::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--saffron); }

/* Tables */
.table-wrap { position: relative; }
.table { width: 100%; font-size: 0.88rem; }
.table th, .table td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th.r, .table td.r { text-align: right; }
.table thead th { font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--cream-3); font-weight: 600; padding-top: 8px; }
.table tbody tr { transition: background-color 0.2s, opacity 0.28s, transform 0.28s var(--ease); }
.table tbody tr:hover { background: rgba(244, 231, 212, 0.03); }
.table tbody tr.is-leaving { opacity: 0; transform: translateX(12px); }
.table th:first-child, .table td:first-child { padding-left: 4px; }
.table th:last-child, .table td:last-child { padding-right: 4px; }
.table.is-empty thead { display: none; }
.t-id { color: var(--cream-3); font-weight: 600; }
.t-name { font-weight: 600; white-space: nowrap; }
.t-items { color: var(--cream-2); min-width: 13em; }
.t-channel { color: var(--cream-3); white-space: nowrap; }
.t-total { font-weight: 600; white-space: nowrap; }
.t-act { width: 1%; white-space: nowrap; text-align: right; }
.row-btn { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-2); font-size: 0.78rem; font-weight: 600; color: var(--cream); transition: background-color 0.2s, border-color 0.2s, transform 0.15s; }
.row-btn:hover { background: var(--cream); color: var(--espresso); border-color: var(--cream); }
.row-btn:active { transform: scale(0.96); }
.table-empty { display: flex; flex-wrap: wrap; align-items: center; gap: 16px 20px; padding: 28px 8px 12px; color: var(--cream-2); font-size: 0.9rem; }
.table-empty svg { width: 54px; height: 54px; color: var(--cream-3); flex: none; }
.table-empty p { flex: 1; min-width: 200px; }
.table-empty b { color: var(--cream); font-weight: 600; }

.status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 7px; border-radius: 999px; font-size: 0.76rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.status svg { width: 14px; height: 14px; }
.status--pack, .status--warn { color: var(--saffron); background: var(--saffron-lo); border-color: rgba(231, 164, 60, 0.3); }
.status--roast, .status--muted { color: var(--cream-2); background: rgba(244, 231, 212, 0.06); border-color: var(--line); }
.status--ship, .status--ok { color: var(--ok); background: rgba(159, 178, 122, 0.1); border-color: rgba(159, 178, 122, 0.28); }
.status--alert { color: var(--alert); background: rgba(217, 120, 90, 0.12); border-color: rgba(217, 120, 90, 0.35); }

/* Bar chart */
.bars { position: relative; height: 240px; display: grid; grid-template-rows: 1fr; padding: 8px 0 28px 26px; }
.bars__grid { position: absolute; inset: 8px 0 28px 26px; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.bars__grid span { position: relative; border-top: 1px solid var(--line); }
.bars__grid span:last-child { border-top-color: var(--line-2); }
.bars__grid i { position: absolute; right: calc(100% + 8px); top: -8px; font-style: normal; font-size: 0.68rem; color: var(--cream-3); }
.bars__plot { position: relative; display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; align-items: end; height: 100%; }
.bar { position: relative; display: flex; justify-content: center; align-items: flex-end; height: 100%; padding: 0 18%; border-radius: 6px; -webkit-tap-highlight-color: transparent; }
.bar__fill { width: 100%; max-width: 30px; height: var(--h); border-radius: 4px 4px 0 0; background: rgba(231, 164, 60, 0.42); transition: background-color 0.2s, opacity 0.2s, transform 0.8s var(--ease-out); transform-origin: bottom; transition-delay: 0s, 0s, calc(var(--i) * 60ms); }
.js .panel--chart:not(.is-in) .bar__fill { transform: scaleY(0); }
.bar--today .bar__fill { background: var(--saffron); }
.bar:hover .bar__fill, .bar:focus-visible .bar__fill { background: var(--saffron-hi); }
.bar.is-dim .bar__fill { opacity: 0.45; }
.bar:focus-visible { outline-offset: 0; }
.bar__day { position: absolute; top: calc(100% + 8px); font-size: 0.72rem; color: var(--cream-3); white-space: nowrap; }
.bar--today .bar__day { color: var(--cream); font-weight: 600; }
.bar__val { position: absolute; bottom: calc(var(--h) + 6px); font-size: 0.78rem; font-weight: 700; }
.bars__tip {
  position: absolute; z-index: 3; transform: translateX(-50%); display: grid; gap: 1px; padding: 9px 12px; border-radius: 10px; min-width: 120px;
  background: var(--cream); color: var(--espresso); font-size: 0.8rem; pointer-events: none; box-shadow: 0 12px 24px -10px rgba(0, 0, 0, 0.6); margin-left: 26px;
}
.bars__tip small { color: rgba(29, 21, 17, 0.62); font-size: 0.72rem; }
.chart-foot { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding-top: 16px; border-top: 1px solid var(--line); }
.mini-stat { display: grid; gap: 2px; font-size: 0.75rem; color: var(--cream-3); }
.mini-stat b { font-size: 1.05rem; color: var(--cream); font-weight: 600; }

/* Subscriptions */
.subs-hero { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 22px; }
.subs-hero p { display: grid; gap: 4px; padding: 14px 16px; border-radius: 12px; background: rgba(244, 231, 212, 0.04); font-size: 0.8rem; color: var(--cream-2); }
.subs-hero b { font-family: var(--f-display); font-weight: 380; font-size: 2rem; line-height: 1; color: var(--cream); font-variation-settings: 'opsz' 144, 'SOFT' 40; }
.hbars { display: grid; gap: 12px; }
.hbars li { display: grid; grid-template-columns: 7.2em 1fr 2.2em; gap: 12px; align-items: center; font-size: 0.85rem; color: var(--cream-2); }
.hbars b { text-align: right; color: var(--cream); font-weight: 600; }
.hbar { height: 10px; border-radius: 0 4px 4px 0; background: rgba(244, 231, 212, 0.06); overflow: hidden; }
.hbar i { display: block; height: 100%; width: var(--w); background: var(--saffron); border-radius: 0 4px 4px 0; transform-origin: left; transition: transform 0.8s var(--ease-out) 0.2s; }
.js .panel--subs:not(.is-in) .hbar i { transform: scaleX(0); }
.subs-moves { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.subs-moves dt { font-size: 0.7rem; color: var(--cream-3); }
.subs-moves dd { font-weight: 600; font-size: 1.05rem; margin-top: 2px; }

/* Roast timeline */
.timeline { margin-bottom: 18px; }
.timeline__axis { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--cream-3); padding-bottom: 6px; }
.timeline__axis span { width: 0; display: flex; justify-content: center; white-space: nowrap; }
.timeline__axis span:first-child { justify-content: flex-start; }
.timeline__axis span:last-child { justify-content: flex-end; }
.timeline__track {
  position: relative; height: 56px; border-radius: 10px;
  background: repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px 25%), rgba(244, 231, 212, 0.03);
  border: 1px solid var(--line);
}
.batch {
  position: absolute; top: 8px; bottom: 8px; left: var(--x); width: var(--w); border-radius: 4px; background: var(--c);
  box-shadow: 0 0 0 1px rgba(244, 231, 212, 0.18) inset; display: grid; place-items: center; cursor: default;
  transition: transform 0.2s var(--ease), box-shadow 0.2s; animation: rise 0.5s var(--ease-out) both; animation-delay: calc(var(--i) * 40ms);
}
.batch:hover, .batch:focus-visible { transform: translateY(-2px); box-shadow: 0 0 0 2px var(--saffron); outline: none; }
.batch__code { font-size: 0.66rem; font-weight: 700; color: var(--ink); letter-spacing: 0.04em; }
.batch__tip {
  position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translate(-50%, 4px); z-index: 2; display: grid; gap: 1px; padding: 8px 11px; border-radius: 9px; white-space: nowrap;
  background: var(--cream); color: var(--espresso); font-size: 0.76rem; box-shadow: 0 12px 24px -10px rgba(0, 0, 0, 0.6);
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity 0.2s, transform 0.2s var(--ease), visibility 0.2s;
}
.batch:first-child .batch__tip { left: 0; transform: translate(0, 4px); }
.batch:nth-last-child(-n + 2) .batch__tip { left: auto; right: 0; transform: translate(0, 4px); }
.batch:hover .batch__tip, .batch:focus-visible .batch__tip { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.batch:first-child:hover .batch__tip, .batch:first-child:focus-visible .batch__tip,
.batch:nth-last-child(-n + 2):hover .batch__tip, .batch:nth-last-child(-n + 2):focus-visible .batch__tip { transform: none; }
.table--plan tbody th { font-weight: 600; white-space: nowrap; }
.table--plan tfoot th, .table--plan tfoot td { border-bottom: 0; font-weight: 700; color: var(--cream); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 10px; vertical-align: -1px; background: var(--c); box-shadow: 0 0 0 1px rgba(244, 231, 212, 0.25) inset; }

/* Stock */
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 0.76rem; color: var(--cream-3); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend__bar, .legend__after { width: 16px; height: 8px; border-radius: 2px; background: rgba(231, 164, 60, 0.35); }
.legend__after { background: var(--saffron); }
.legend__line { width: 2px; height: 12px; background: var(--cream); }
.lots { display: grid; }
.lot { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.4fr) 7.5em 9.5em 6.5em; gap: 20px; align-items: center; padding: 16px 0; border-top: 1px solid var(--line); }
.lot:first-child { border-top: 0; padding-top: 4px; }
.lot__name b { display: block; font-weight: 600; }
.lot__name small { color: var(--cream-3); font-size: 0.8rem; }
.lot__bar { position: relative; height: 12px; border-radius: 0 4px 4px 0; background: rgba(244, 231, 212, 0.06); }
.lot__bar i { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 0 4px 4px 0; }
.lot__bar .now { width: var(--now); background: rgba(231, 164, 60, 0.35); }
.lot__bar .after { width: var(--after); background: var(--saffron); z-index: 1; }
.lot__bar .line { left: var(--reorder); width: 2px; top: -5px; bottom: -5px; border-radius: 1px; background: var(--cream); z-index: 2; }
.lot__bar i.now, .lot__bar i.after { transform-origin: left; transition: transform 0.9s var(--ease-out) 0.15s; }
.js .panel--stock:not(.is-in) .lot__bar i.now, .js .panel--stock:not(.is-in) .lot__bar i.after { transform: scaleX(0); }
.lot--low .lot__bar .after { background: var(--alert); }
.lot__bar--empty { display: flex; align-items: center; height: 26px; padding-left: 12px; border-radius: 6px; background: repeating-linear-gradient(135deg, rgba(244, 231, 212, 0.05) 0 6px, transparent 6px 12px); border: 1px dashed var(--line-2); font-size: 0.72rem; color: var(--cream-3); font-weight: 600; letter-spacing: 0.04em; }
.lot__kg { display: grid; text-align: right; font-size: 0.82rem; }
.lot__kg b { font-size: 1rem; font-weight: 600; }
.lot__kg small { color: var(--cream-3); }
.lot .status { justify-self: start; }
.lot__act { justify-self: end; }
.lot:not(:has(.lot__act))::after { content: ''; }

.admin-foot { margin-top: 28px; font-size: 0.8rem; color: var(--cream-3); text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px) {
  .panel--orders { grid-column: span 12; grid-row: auto; }
  .panel--chart, .panel--subs { grid-column: span 6; }
  .panel--roast { grid-column: span 12; }
  .lot { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) 7em 9.5em 6.5em; }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { min-width: 0; }
  .side {
    position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0;
    padding: 12px var(--gutter) 0; border-right: 0; border-bottom: 1px solid var(--line); background: rgba(20, 14, 11, 0.94); backdrop-filter: blur(12px); overflow: visible;
  }
  .side__tag { margin: 0 0 0 10px; padding: 3px 9px; border: 1px solid var(--line-2); border-radius: 999px; letter-spacing: 0.08em; }
  .side__links { display: none; }
  .side__user { margin: 0 0 0 auto; padding: 0; border: 0; }
  .side__user > span:last-child { display: none; }
  .side__user .avatar { width: 34px; height: 34px; }
  .side__nav { order: 3; width: calc(100% + var(--gutter) * 2); margin: 10px calc(var(--gutter) * -1) 0; padding: 0 var(--gutter) 8px; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
  .side__nav::-webkit-scrollbar { display: none; }
  .side__nav a:not(.brand) { flex: none; min-height: 38px; padding: 0 12px; font-size: 0.86rem; }
  .side__nav a.is-on::before { left: 12px; right: 12px; top: auto; bottom: -8px; width: auto; height: 2px; border-radius: 2px; }
  .main { padding-top: 22px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .lot { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 16px; }
  .lot__bar { grid-column: 1 / -1; grid-row: 2; }
  .lot__kg { grid-column: 2; grid-row: 1; }
  .lot .status { grid-row: 3; }
  .lot__act { grid-row: 3; grid-column: 2; }
}
@media (max-width: 720px) {
  .panel--chart, .panel--subs { grid-column: 1 / -1; }
  .panel { padding: 18px 16px 20px; }
  .panel__head .search { width: 100%; }
  .topbar__actions { width: 100%; }
  .topbar__actions .btn { flex: 1; }
  .kpi { padding: 16px; }
  .kpi__note { font-size: 0.8rem; }
  /* Orders become cards */
  .table[data-orders] thead { display: none; }
  .table[data-orders], .table[data-orders] tbody { display: block; }
  .table[data-orders] tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 4px; border-bottom: 1px solid var(--line); }
  .table[data-orders] td { padding: 0; border: 0; }
  .table[data-orders] .t-name { grid-column: 1; grid-row: 1; }
  .table[data-orders] .t-total { grid-column: 2; grid-row: 1; }
  .table[data-orders] .t-items { grid-column: 1 / -1; grid-row: 2; font-size: 0.85rem; }
  .table[data-orders] .t-id { grid-column: 1; grid-row: 3; font-size: 0.8rem; }
  .table[data-orders] .t-id::after { content: ' · ' attr(data-channel); }
  .table[data-orders] .t-channel { display: none; }
  .table[data-orders] .t-status { grid-column: 1; grid-row: 4; margin-top: 6px; }
  .table[data-orders] .t-act { grid-column: 2; grid-row: 4; margin-top: 6px; width: auto; }
  .table--plan th, .table--plan td { padding: 10px 6px; font-size: 0.8rem; }
  .table--plan td:nth-child(2), .table--plan th:nth-child(2) { display: none; }
  .table--plan tbody th { white-space: normal; }
  .batch__code { display: none; }
  .subs-moves { grid-template-columns: 1fr 1fr; row-gap: 14px; }
  .legend { width: 100%; }
}
