/* ==========================================
   Admin dashboard — panel chrome
   Inherits all tokens/components from styles.css
   ========================================== */

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--s6);
}
.login-view .form-card { text-align: center; }
.login-view .field { text-align: start; }
.form-error {
  margin-top: var(--s3);
  font-size: 0.875rem;
  font-weight: 600;
  color: #b42318;
}
[data-theme="dark"] .form-error { color: #ff6961; }

/* ---------- App frame ---------- */
.dash-app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 0 0 auto; /* RTL: sidebar pinned to the right */
  z-index: 40;
  width: 232px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
  padding: var(--s6) var(--s4);
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}
.sidebar.open { transform: none; }
.side-logo { padding-inline: var(--s3); margin-bottom: var(--s8); }

.side-nav { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s1); }
.side-link {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 0.625rem var(--s3);
  border-radius: 10px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ink-soft);
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.side-link:hover { background: var(--hover-fill); color: var(--ink); }
.side-link[aria-current="page"] {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  color: var(--accent-text);
  font-weight: 600;
}
.side-foot {
  margin-top: auto;
  padding: var(--s3);
  border-top: 1px solid var(--line);
}
.health { display: inline-flex; align-items: center; gap: var(--s2); font-size: 0.8125rem; color: var(--ink-muted); }
.health-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-muted); }
.health.ok .health-dot { background: var(--ok-text); }
.health.bad .health-dot { background: #d92d20; }

.dash-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.dash-top {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--s4);
  height: var(--nav-h);
  padding-inline: var(--s6);
  background: color-mix(in srgb, var(--paper) 78%, transparent);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
}
.dash-top h1 { font-size: 1.125rem; }
.top-actions { margin-inline-start: auto; display: flex; align-items: center; gap: var(--s3); }
.user-chip {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#dash-main { padding: var(--s8) var(--s6) var(--s16); max-width: 1200px; width: 100%; }
.dash-sec { display: grid; gap: var(--s6); }

/* Inline text-button used inside tables */
.linkish {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent-text);
  cursor: pointer;
  text-align: start;
}
.linkish:hover { text-decoration: underline; }

@media (min-width: 900px) {
  .sidebar { transform: none; }
  .dash-body { margin-inline-start: 232px; }
  .dash-top .nav-toggle { display: none; }
}
@media (max-width: 899.98px) {
  .sidebar { box-shadow: 0 0 60px rgb(0 0 0 / 0.35); }
  .dash-top .nav-toggle { display: grid; } /* styles.css only shows it below 768px */
}

/* ---------- Tiles (stat tiles: hero number + label, text tokens) ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s4);
}
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4) var(--s6);
}
.tile .tile-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: normal;
  color: var(--ink-muted);
}
.tile .tile-value {
  margin-top: var(--s1);
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.tile .tile-sub { margin-top: var(--s1); font-size: 0.75rem; color: var(--ink-muted); }

/* ---------- Panels & tables ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s4) var(--s6);
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 1rem; }
.panel-body { padding: var(--s6); display: grid; gap: var(--s4); }
.panel-foot {
  padding: var(--s3) var(--s6);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s4);
  font-size: 0.875rem;
  color: var(--ink-muted);
}
.panel-foot:empty { display: none; }

.toolbar { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }
.toolbar .field-inline { margin-top: 0; flex: 1; min-width: 180px; max-width: 320px; }
.toolbar .btn-primary { margin-inline-start: auto; }

.table-wrap { overflow-x: auto; }
.d-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; min-width: 640px; }
.d-table th, .d-table td {
  text-align: start;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.d-table th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: normal;
  color: var(--ink-muted);
  background: color-mix(in srgb, var(--paper) 60%, var(--surface));
  white-space: nowrap;
}
.d-table tbody tr:last-child td { border-bottom: 0; }
.d-table tbody tr:hover td { background: var(--hover-fill); }
.d-table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.d-table .cell-main { font-weight: 600; color: var(--ink); }
.d-table .cell-sub { font-size: 0.75rem; color: var(--ink-muted); }
.d-table img.thumb {
  width: 36px; height: 36px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
}
.row-actions { display: flex; gap: var(--s2); justify-content: flex-end; }
.row-actions .btn { padding: 0.35rem 0.75rem; font-size: 0.8125rem; }
.btn-danger { color: #d92d20; border-color: color-mix(in srgb, #d92d20 40%, var(--line)); }
.btn-danger:hover { border-color: #d92d20; background: color-mix(in srgb, #d92d20 8%, transparent); }

/* Status badges — text always present, color is never the only cue */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.good { color: #15803d; border-color: color-mix(in srgb, #15803d 35%, transparent); }
.badge.warn { color: #b54708; border-color: color-mix(in srgb, #b54708 35%, transparent); }
.badge.crit { color: #d92d20; border-color: color-mix(in srgb, #d92d20 35%, transparent); }
.badge.info { color: #175cd3; border-color: color-mix(in srgb, #175cd3 35%, transparent); }
[data-theme="dark"] .badge.good { color: #30d158; }
[data-theme="dark"] .badge.warn { color: #ff9f0a; }
[data-theme="dark"] .badge.crit { color: #ff6961; }
[data-theme="dark"] .badge.info { color: #64a8ff; }

.status-select {
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

/* States */
.empty, .errbox {
  padding: var(--s12) var(--s6);
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.9375rem;
}
.errbox strong { display: block; color: var(--ink); margin-bottom: var(--s2); }
.errbox .btn { margin-top: var(--s4); }
.skel {
  background: linear-gradient(90deg, var(--line) 25%, var(--hover-fill) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: skel 1.4s ease-in-out infinite;
  border-radius: var(--radius);
  border: 0;
  min-height: 84px;
}
.skel-row { min-height: 52px; border-radius: 8px; margin: var(--s3) var(--s4); }
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Settings ---------- */
.set-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(200px, 2fr);
  gap: var(--s4);
  align-items: center;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
}
.set-row:last-child { border-bottom: 0; }
.set-key { font-weight: 600; font-size: 0.875rem; word-break: break-all; }
.set-desc { font-size: 0.75rem; color: var(--ink-muted); margin-top: 2px; }
.set-row input {
  width: 100%;
  font: inherit;
  font-size: 0.9375rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}
.set-row input.dirty { border-color: var(--accent); }
@media (max-width: 640px) { .set-row { grid-template-columns: 1fr; } }

/* ---------- Bot & queue ---------- */
.bot-grid { display: grid; gap: var(--s6); }
@media (min-width: 1024px) {
  .bot-grid { grid-template-columns: 1fr 1fr; }
  .panel-wide { grid-column: 1 / -1; }
}
.bot-actions { justify-content: flex-start; flex-wrap: wrap; }
.bot-pre {
  margin: 0;
  padding: var(--s4);
  max-height: 260px;
  overflow: auto;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--paper) 55%, var(--surface));
  white-space: pre-wrap;
  word-break: break-word;
  direction: ltr; /* log lines are mixed LTR-first — keep line order stable */
  text-align: start;
}
.bot-state { display: flex; align-items: center; gap: var(--s3); font-size: 0.9375rem; }
.bot-state .badge { font-size: 0.8125rem; }

/* ---------- Product dialog ---------- */
.p-dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  width: min(560px, calc(100vw - 2rem));
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 64px -24px rgb(0 0 0 / 0.45);
}
.p-dialog::backdrop { background: rgb(0 0 0 / 0.45); backdrop-filter: blur(4px); }
.p-dialog form { display: flex; flex-direction: column; max-height: min(84vh, 720px); }
.p-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s4) var(--s6);
  border-bottom: 1px solid var(--line);
}
.p-dialog-head h2 { font-size: 1.0625rem; }
.p-close {
  border: 0;
  background: transparent;
  font-size: 1rem;
  color: var(--ink-muted);
  cursor: pointer;
  padding: var(--s2);
  border-radius: 8px;
}
.p-close:hover { background: var(--hover-fill); color: var(--ink); }
.p-dialog-body { padding: var(--s4) var(--s6) var(--s6); overflow-y: auto; display: grid; gap: var(--s2); }
.p-dialog-body .field { margin-top: var(--s3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.field-row .field { margin-top: var(--s3); }
.field-check { align-content: end; }
.field-check label { font-weight: 400; }
.p-dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--s3);
  padding: var(--s4) var(--s6);
  border-top: 1px solid var(--line);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: var(--s8);
  transform: translateX(-50%);
  z-index: 90;
  max-width: min(440px, calc(100vw - 2rem));
  background: var(--ink);
  color: var(--paper);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  box-shadow: 0 12px 32px -12px rgb(0 0 0 / 0.5);
  animation: fade-up 0.3s cubic-bezier(0.32, 0.72, 0, 1) both;
}
.toast.bad { background: #b42318; color: #fff; }

/* ---------- Small-screen hardening (≤559.98px) ---------- */
@media (max-width: 559.98px) {
  /* Product dialog: stack the paired fields — two inputs in
     min(560px, 100vw - 2rem) at 320px leaves each ~130px */
  .field-row { grid-template-columns: 1fr; }

  /* Top bar: title + chip + two buttons overflow 320px —
     drop the chip (identity stays visible in the sidebar footer) */
  .user-chip { display: none; }
  .dash-top { padding-inline: var(--s4); gap: var(--s3); }
  .dash-top h1 { font-size: 1rem; }

  /* Content: tighter gutters, keep bottom room for the toast */
  #dash-main { padding: var(--s6) var(--s4) var(--s12); }

  /* Dialog actions: stack full-width so neither button is a sliver */
  .p-dialog-foot { flex-direction: column-reverse; }
  .p-dialog-foot .btn { width: 100%; }

  /* Toolbar: the primary action takes its own row */
  .toolbar .btn-primary { width: 100%; }

  /* Order/status tables keep scrolling horizontally (min-width 640),
     but reduce the outer padding so more of the table is visible */
  .panel-head, .panel-body, .panel-foot { padding-inline: var(--s4); }
}

/* ---------- Opt out of full-page snap (styles.css sets it on html) ----------
   The dashboard scrolls freely with tables, dialogs and long panels. */
html { scroll-snap-type: none; }
