/* ==========================================================================
   Vento Admin — Design system + responsive shell
   Used by the server-rendered HTMX admin console (templates/).
   Breakpoints: 1200 (desk) / 1024 (nav collapses) / 768 (tables stack) / 480
   ========================================================================== */

:root {
  --bg-base: #090a0f;
  --bg-surface: #121520;
  --bg-elevated: #1a1e2e;
  --bg-hover: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #7c6af7;
  --accent-soft: rgba(124, 106, 247, 0.15);
  --accent-light: #a78bfa;
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.15);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.15);

  --sidebar-w: 260px;
  --topbar-h: 60px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --gap: clamp(14px, 2vw, 22px);
  --pad-page: clamp(16px, 3vw, 40px);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.37);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background-color: var(--bg-base);
  color: var(--text-primary);
  min-height: 100dvh;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

img { max-width: 100%; }

/* ---------- App shell ---------------------------------------------------- */

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
  z-index: 60;
}

.sidebar-brand {
  padding: 22px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
}
.sidebar-brand img { width: 34px; height: 34px; border-radius: 10px; object-fit: contain; flex-shrink: 0; }
.sidebar-brand span { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }

.sidebar-nav { padding: 20px 14px; flex: 1; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  min-height: 44px;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.is-active { background: rgba(255, 255, 255, 0.06); color: var(--text-primary); }

.sidebar-footer { padding: 18px 20px; border-top: 1px solid var(--border); }
.sidebar-footer .who { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 10px; overflow-wrap: anywhere; }

.app-main { flex: 1; min-width: 0; padding: var(--pad-page); }
.page { max-width: 1200px; margin: 0 auto; }

/* Mobile top bar + off-canvas nav (CSS only — checkbox toggle in layout) */
#nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.topbar { display: none; }
.nav-scrim { display: none; }

/* ---------- Typography --------------------------------------------------- */

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--gap);
  flex-wrap: wrap;
  margin-bottom: clamp(20px, 3vw, 32px);
}
h1.page-title { font-size: clamp(22px, 3.2vw, 32px); font-weight: 800; letter-spacing: -0.02em; margin-bottom: 6px; }
.page-sub { color: var(--text-muted); font-size: 14px; }
h2.section-title { font-size: clamp(16px, 2vw, 19px); font-weight: 800; }
h3.card-title { font-size: 15px; font-weight: 700; }
.muted { color: var(--text-muted); }
.label { font-size: 12px; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 6px; }

/* ---------- Surfaces ----------------------------------------------------- */

.panel {
  background: rgba(18, 21, 32, 0.75);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(16px, 2.2vw, 24px);
  box-shadow: var(--shadow);
}
.panel-flush { padding: 0; overflow: hidden; }
.tile { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }

.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------- Responsive grids --------------------------------------------- */

.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--gap); }
/* Compact counters that must stay on one row even inside a narrow column. */
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: var(--gap); }
.grid-pricing { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--gap); align-items: stretch; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--gap); }
.grid-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: var(--gap); align-items: start; }
.grid-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; }

.kpi-label { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; color: var(--text-muted); text-transform: uppercase; margin-bottom: 6px; }
.kpi-value { font-size: clamp(24px, 3.4vw, 30px); font-weight: 800; letter-spacing: -0.02em; }

/* ---------- Controls ----------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { opacity: 0.9; }
.btn:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 2px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%); color: #fff; }
.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--border-strong); background: #212637; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(239, 68, 68, 0.5); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 7px 14px; min-height: 34px; font-size: 12.5px; }
.btn-block { width: 100%; }

.input-field {
  width: 100%;
  padding: 11px 14px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input-field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-field::placeholder { color: var(--text-muted); }
textarea.input-field { min-height: 130px; resize: vertical; }
select.input-field { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 36px; }

.field { margin-bottom: 14px; }

.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .search { flex: 1 1 260px; max-width: 380px; min-width: 200px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 14px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-secondary);
  cursor: pointer; font-family: inherit; min-height: 34px;
}
.chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip.is-active { background: var(--accent-soft); border-color: rgba(124, 106, 247, 0.45); color: var(--accent-light); }

/* ---------- Badges ------------------------------------------------------- */

.badge { padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; display: inline-block; white-space: nowrap; }
.badge-active { background: var(--success-soft); color: var(--success); border: 1px solid rgba(34, 197, 94, 0.3); }
.badge-suspended { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.3); }
.badge-accent { background: var(--accent-soft); color: var(--accent-light); border: 1px solid rgba(124, 106, 247, 0.3); }
.badge-neutral { background: rgba(255, 255, 255, 0.05); color: var(--text-secondary); border: 1px solid var(--border); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border: 1px solid rgba(245, 158, 11, 0.3); }

.avatar {
  width: 38px; height: 38px; border-radius: 10px; object-fit: contain; flex-shrink: 0;
  background: var(--bg-elevated); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}

/* ---------- Tables (stack into cards under 768px) ------------------------- */

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; padding: 12px 16px; font-size: 11px; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.15s ease; }
tbody tr:hover { background: var(--bg-hover); }

.cell-company { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell-company .name { font-weight: 700; overflow-wrap: anywhere; }
.cell-company .ref { font-size: 11px; color: var(--text-muted); }

.empty-state { padding: 48px 24px; text-align: center; color: var(--text-muted); }
.empty-state .icon { font-size: 34px; margin-bottom: 10px; }

/* ---------- Tabs --------------------------------------------------------- */

.tabs {
  display: flex; gap: 4px; margin-bottom: var(--gap);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent; border: none; border-bottom: 2px solid transparent;
  color: var(--text-secondary); font-family: inherit; font-size: 14px; font-weight: 600;
  padding: 12px 16px; cursor: pointer; white-space: nowrap; min-height: 44px;
}
.tab:hover { color: var(--text-primary); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }

/* ---------- Banner / toasts ---------------------------------------------- */

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 13px 18px; border-radius: var(--radius); font-size: 13.5px; font-weight: 600;
  background: var(--accent-soft); border: 1px solid rgba(124, 106, 247, 0.3);
}
.banner-success { background: var(--success-soft); border-color: rgba(34, 197, 94, 0.4); }
.banner-warn { background: var(--warn-soft); border-color: rgba(245, 158, 11, 0.4); }
.banner-error { background: var(--danger-soft); border-color: rgba(239, 68, 68, 0.4); }
.banner .meta { font-size: 12px; color: var(--text-muted); font-weight: 500; }

#toast-stack {
  position: fixed; bottom: 20px; right: 20px; z-index: 12000;
  display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 13px 16px; border-radius: var(--radius);
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  font-size: 13.5px; font-weight: 600;
  animation: toast-in 0.22s ease-out;
}
.toast.is-leaving { animation: toast-out 0.2s ease-in forwards; }
.toast-success { border-color: rgba(34, 197, 94, 0.45); }
.toast-error { border-color: rgba(239, 68, 68, 0.45); }
.toast-warn { border-color: rgba(245, 158, 11, 0.45); }
.toast .msg { overflow-wrap: anywhere; }

@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------- Modals ------------------------------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 11000;
  background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow-y: auto;
  animation: fade-in 0.15s ease-out;
}
.modal {
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: clamp(20px, 3vw, 30px);
  box-shadow: var(--shadow);
}
.modal h3 { font-size: clamp(17px, 2.4vw, 20px); font-weight: 800; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Auth page ---------------------------------------------------- */

.auth-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  width: min(420px, 100%);
  padding: clamp(24px, 5vw, 40px);
  border-radius: 24px;
  background: rgba(18, 21, 32, 0.78);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* ---------- HTMX state --------------------------------------------------- */

.htmx-indicator { opacity: 0; transition: opacity 0.2s ease; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }
.htmx-request .btn { pointer-events: none; opacity: 0.65; }

.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25); border-top-color: #fff;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.swapping-out { opacity: 0.5; transition: opacity 0.12s ease; }

/* ==========================================================================
   Responsive breakpoints
   ========================================================================== */

/* Nav collapses to an off-canvas drawer */
@media (max-width: 1023px) {
  .app-shell { flex-direction: column; }

  .topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 70;
    height: var(--topbar-h); padding: 0 14px;
    background: var(--bg-surface); border-bottom: 1px solid var(--border);
  }
  .topbar img { width: 30px; height: 30px; border-radius: 9px; object-fit: contain; }
  .topbar .title { font-size: 16px; font-weight: 800; }

  .nav-burger {
    display: flex; align-items: center; justify-content: center;
    width: 42px; height: 42px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--bg-elevated);
    color: var(--text-primary); cursor: pointer; flex-shrink: 0;
  }
  .nav-burger span { display: block; width: 18px; height: 2px; background: currentColor; position: relative; }
  .nav-burger span::before, .nav-burger span::after { content: ''; position: absolute; left: 0; width: 18px; height: 2px; background: currentColor; }
  .nav-burger span::before { top: -6px; }
  .nav-burger span::after { top: 6px; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(280px, 82vw); height: 100dvh;
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.5);
  }
  #nav-toggle:checked ~ .app-shell .sidebar { transform: translateX(0); }

  .nav-scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, 0.6); opacity: 0; pointer-events: none; transition: opacity 0.24s ease; }
  #nav-toggle:checked ~ .nav-scrim { opacity: 1; pointer-events: auto; }

  .app-main { padding: clamp(16px, 3vw, 28px); }
}

@media (min-width: 1024px) {
  .nav-burger, .topbar { display: none; }
}

/* Tables stack into cards */
@media (max-width: 767px) {
  .table-stack thead { display: none; }
  .table-stack tbody tr {
    display: block;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 4px;
    margin-bottom: 12px;
  }
  .table-stack tbody tr:last-child { margin-bottom: 0; }
  .table-stack td {
    display: flex; justify-content: space-between; align-items: center; gap: 14px;
    padding: 9px 14px; border-bottom: none; text-align: right;
  }
  .table-stack td::before {
    content: attr(data-label);
    font-size: 11px; font-weight: 700; letter-spacing: 0.05em;
    color: var(--text-muted); text-transform: uppercase;
    text-align: left; flex-shrink: 0;
  }
  .table-stack td:has(.cell-company) { text-align: left; }
  .table-stack .cell-company { flex: 1; justify-content: flex-end; }
  .table-stack .panel-flush { padding: 10px; }

  .page-head .btn { width: 100%; }
  .modal-actions .btn { flex: 1; }
  #toast-stack { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}

@media (max-width: 479px) {
  .grid-kpi { grid-template-columns: 1fr 1fr; }
  .grid-kpi .kpi-value { font-size: 22px; }
  .grid-actions { grid-template-columns: 1fr; }
  .toolbar .search { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
