/* =====================================================
   CASA License Monitor — Premium Dark Mode SPA Styles
   ===================================================== */

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

:root {
  --bg:         #0d0f17;
  --surface:    #13172a;
  --surface2:   #1a1f38;
  --border:     rgba(255,255,255,0.07);
  --text:       #e8eaf6;
  --text-muted: #7b82a8;
  --accent:     #5b8dee;
  --accent2:    #7c5cfc;
  --green:      #34d399;
  --yellow:     #fbbf24;
  --red:        #f87171;
  --radius:     12px;
  --radius-sm:  8px;
  --shadow:     0 8px 32px rgba(0,0,0,.45);
  --sidebar-w:  230px;
  --transition: .2s cubic-bezier(.4,0,.2,1);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  /* Allow page-level horizontal scroll as a fallback. Per-table scroll
     still wins via .table-wrapper{overflow-x:auto} + .main-content
     min-width:0 (flex children default to auto, which lets wide tables
     blow out the layout). */
  overflow-x: auto;
}

/* Glass morphism */
.glass {
  background: rgba(26,31,56,.7);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
}

/* ---- Login Overlay ---- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 60% 30%, rgba(91,141,238,.18) 0%, transparent 60%),
              var(--bg);
  z-index: 100;
}

.login-card {
  width: 380px;
  border-radius: 20px;
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.logo-ring {
  width: 72px; height: 72px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.2rem;
  box-shadow: 0 0 40px rgba(91,141,238,.35);
}

.login-card h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: .25rem; }
.subtitle { color: var(--text-muted); font-size: .85rem; margin-bottom: 2rem; }

.field { text-align: left; margin-bottom: 1.2rem; }
.field label { display: block; font-size: .78rem; color: var(--text-muted); margin-bottom: .4rem; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.field input {
  width: 100%; padding: .7rem 1rem;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text); font-size: .95rem; font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,141,238,.2); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  border: none; cursor: pointer; font-family: inherit; font-weight: 500;
  border-radius: var(--radius-sm); transition: all var(--transition);
  padding: .6rem 1.2rem; font-size: .875rem;
}
.btn-primary {
  width: 100%; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 4px 20px rgba(91,141,238,.4);
}
.btn-primary:hover { filter: brightness(1.1); box-shadow: 0 6px 28px rgba(91,141,238,.5); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,.06); }
.btn-danger { background: rgba(248,113,113,.15); color: var(--red); border: 1px solid rgba(248,113,113,.3); }
.btn-danger:hover { background: rgba(248,113,113,.25); }
.btn-success { background: rgba(52,211,153,.15); color: var(--green); border: 1px solid rgba(52,211,153,.3); }
.btn-success:hover { background: rgba(52,211,153,.25); }
.btn-sm { padding: .35rem .8rem; font-size: .8rem; }

.error { color: var(--red); font-size: .84rem; margin-top: .8rem; }

/* ---- Layout ---- */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0;
  padding: 1.5rem 1rem;
  z-index: 10;
}

.sidebar-brand {
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem .5rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  font-weight: 700; font-size: 1rem; letter-spacing: -.02em;
}

.brand-icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.nav-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem .85rem; border-radius: var(--radius-sm);
  color: var(--text-muted); text-decoration: none;
  font-size: .875rem; font-weight: 500;
  transition: all var(--transition);
  margin-bottom: .25rem;
}
.nav-link:hover { color: var(--text); background: rgba(255,255,255,.06); }
.nav-link.active { color: var(--text); background: rgba(91,141,238,.15); }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: .4rem; }

.main-content { margin-left: var(--sidebar-w); flex: 1; padding: 2rem; min-width: 0; }

/* ---- Page header ---- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.75rem; flex-wrap: wrap; gap: 1rem;
}
.page-header h2 { font-size: 1.5rem; font-weight: 700; }
.page-sub { color: var(--text-muted); font-size: .82rem; margin-top: .2rem; }
.header-badges { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---- Badges ---- */
.badge {
  padding: .3rem .75rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
}
.badge-ok { background: rgba(52,211,153,.15); color: var(--green); }
.badge-warn { background: rgba(251,191,36,.15); color: var(--yellow); }
.badge-danger { background: rgba(248,113,113,.15); color: var(--red); }

/* ---- Stat cards ---- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  border-radius: var(--radius); padding: 1.25rem;
  display: flex; align-items: center; gap: 1rem;
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon { width: 48px; height: 48px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon-blue  { background: rgba(91,141,238,.2); color: var(--accent); }
.stat-icon-green { background: rgba(52,211,153,.2); color: var(--green); }
.stat-icon-yellow { background: rgba(251,191,36,.2); color: var(--yellow); }
.stat-icon-red   { background: rgba(248,113,113,.2); color: var(--red); }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .78rem; color: var(--text-muted); margin-top: .3rem; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }

/* ---- Table ---- */
.table-card { border-radius: var(--radius); overflow: hidden; }
.table-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.table-header h3 { font-size: 1rem; font-weight: 600; }
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
thead { background: rgba(255,255,255,.03); }
th { padding: .7rem 1rem; text-align: left; color: var(--text-muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

.pill {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .2rem .65rem; border-radius: 999px; font-size: .75rem; font-weight: 600;
}
.pill-ok       { background: rgba(52,211,153,.12); color: var(--green); }
.pill-warn     { background: rgba(251,191,36,.12); color: var(--yellow); }
.pill-danger   { background: rgba(248,113,113,.12); color: var(--red); }
.pill-expiring { background: rgba(251,191,36,.12); color: var(--yellow); }
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---- Search ---- */
.search-input {
  padding: .55rem 1rem; background: rgba(255,255,255,.06);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: .875rem; font-family: inherit;
  outline: none; width: 260px;
  transition: border-color var(--transition);
}
.search-input:focus { border-color: var(--accent); }

/* ---- Toast ---- */
/* The legacy single `#toast` element stays in the DOM as a no-op
   fallback. The new flow renders into `#toast-stack` so multiple
   messages stack instead of overwriting. */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .75rem 1.25rem;
  font-size: .875rem; box-shadow: var(--shadow);
  animation: slideIn .25s ease;
  z-index: 200;
}
.toast-stack {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: .5rem;
  z-index: 200; pointer-events: none;
  max-width: min(420px, 92vw);
}
.toast-stack .toast {
  position: static; pointer-events: auto;
  animation: slideIn .25s ease;
  display: flex; align-items: flex-start; gap: .75rem;
  border-left: 3px solid var(--border);
}
.toast-stack .toast .toast-msg { flex: 1; line-height: 1.4; }
.toast-stack .toast .toast-close {
  background: none; border: 0; color: var(--text-muted);
  font-size: 1rem; cursor: pointer; padding: 0; line-height: 1;
}
.toast-stack .toast .toast-close:hover { color: var(--text); }
.toast-stack .toast.toast-leaving { animation: slideOut .2s ease forwards; }
@keyframes slideIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes slideOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(8px); } }

/* ---- Reveal-key modal ---- */
.reveal-card {
  width: 100%;
  max-width: 640px;
  border-radius: var(--radius);
  padding: 1.75rem;
  background: linear-gradient(180deg, rgba(91,141,238,.06), rgba(255,255,255,.02));
  border: 1px solid rgba(91,141,238,.25);
}
.reveal-header {
  display: flex; align-items: flex-start; gap: 1rem;
  margin-bottom: 1.25rem;
}
.reveal-icon {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  box-shadow: 0 6px 22px rgba(91,141,238,.35);
}
.reveal-title { font-size: 1.2rem; font-weight: 700; margin: 0 0 .25rem; letter-spacing: -.01em; }
.reveal-sub { font-size: .82rem; color: var(--text-muted); line-height: 1.4; margin: 0; }
.reveal-key-card {
  background: rgba(0,0,0,.35);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.1rem;
  margin-bottom: 1.25rem;
}
.reveal-key-label {
  font-size: .68rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .12em;
  margin-bottom: .55rem; font-weight: 600;
}
.reveal-key-text {
  font-family: 'Courier New', monospace;
  font-size: .82rem; line-height: 1.5;
  color: var(--accent);
  margin: 0;
  white-space: pre-wrap; word-break: break-all;
  max-height: 220px; overflow-y: auto;
}
.reveal-key-text::-webkit-scrollbar { width: 6px; }
.reveal-key-text::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.15); border-radius: 3px;
}
.reveal-actions {
  display: flex; gap: .6rem; justify-content: flex-end;
}
.reveal-actions .btn { padding: .6rem 1.5rem; }
.reveal-actions .btn-ghost { display: inline-flex; align-items: center; gap: .4rem; }

/* ---- Sortable column headers ---- */
th.sortable { cursor: pointer; user-select: none; position: relative; }
th.sortable:hover { color: var(--text); }
th.sortable .sort-ind {
  margin-left: .35rem; font-size: .7rem; opacity: .5;
}
th.sortable.sort-active .sort-ind { opacity: 1; color: var(--accent); }

/* ---- Pagination ---- */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,.02);
  font-size: .8rem; color: var(--text-muted);
}
.pagination .page-info { font-variant-numeric: tabular-nums; }
.pagination .page-controls { display: flex; align-items: center; gap: .35rem; }
.pagination .page-controls button {
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .3rem .65rem; border-radius: var(--radius-sm);
  font-size: .8rem; cursor: pointer;
}
.pagination .page-controls button:hover:not(:disabled) { background: rgba(255,255,255,.1); }
.pagination .page-controls button:disabled { opacity: .35; cursor: not-allowed; }
.pagination .page-controls select {
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .25rem .4rem; border-radius: var(--radius-sm);
  font-size: .78rem; font-family: inherit;
}

/* ---- Generate License Form ---- */
.generate-card { border-radius: var(--radius); padding: 2rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field-full { grid-column: 1 / -1; }

.generate-card .field input,
.generate-card .field select,
.generate-card .field textarea {
  width: 100%; padding: .7rem 1rem;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text); font-size: .9rem; font-family: inherit;
  transition: border-color var(--transition);
  outline: none;
  resize: vertical;
}
.generate-card .field input:focus,
.generate-card .field select:focus,
.generate-card .field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91,141,238,.15);
}
/* Custom chevron + dark <option> palette for every <select> in the
   dashboard. `appearance: none` strips OS chrome on the field; the
   native option dropdown can't be fully styled, but background-color
   on <option> keeps it dark on Chromium/Firefox. Scoped to .app so
   external embeds (none today) wouldn't be affected. */
#app select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  cursor: pointer;
  padding-right: 2.4rem;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%2394a3b8' stroke-width='2'><polyline points='1 1 6 6 11 1'/></svg>");
  background-repeat: no-repeat;
  background-position: right .9rem center;
}
#app select::-ms-expand { display: none; }
#app select option {
  background-color: #1a1f2e;
  color: var(--text);
}
/* Compact pagination select: tighter padding so the chevron + label
   don't fight inside the small per-page picker. */
.pagination .page-controls select { padding-right: 1.8rem; background-position: right .55rem center; }
/* Search-input-styled selects (audit-action-filter etc.) — give them
   room for the chevron without exploding their width. */
.search-input select, select.search-input { padding-right: 2.2rem; }

/* Generated key result */
.gen-result {
  margin-top: 1.5rem; padding: 1.25rem;
  background: rgba(52,211,153,.06);
  border: 1px solid rgba(52,211,153,.2);
  border-radius: var(--radius-sm);
}
.gen-result-header {
  display: flex; align-items: center; gap: .5rem;
  font-weight: 600; font-size: 1rem; margin-bottom: .5rem;
  color: var(--green);
}
.gen-warning {
  font-size: .82rem; color: var(--yellow); margin-bottom: .75rem;
}
.gen-key-box {
  display: flex; gap: .5rem; align-items: flex-start;
}
.gen-key-box textarea {
  flex: 1; padding: .6rem .8rem;
  background: rgba(0,0,0,.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent); font-family: 'Courier New', monospace;
  font-size: .78rem; resize: none;
}

/* ---- Security banner ---- */
.security-banner {
  display: flex; gap: .9rem;
  background: rgba(248,113,113,.08);
  border: 1px solid rgba(248,113,113,.35);
  border-left: 4px solid var(--red);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  font-size: .88rem; line-height: 1.5;
}
.security-banner svg { color: var(--red); flex-shrink: 0; margin-top: .15rem; }
.security-banner code {
  background: rgba(0,0,0,.35);
  padding: .05rem .35rem;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: .82rem;
  color: var(--yellow);
}
.security-banner strong { color: var(--red); }

/* ---- Field hint ---- */
.field-hint {
  font-size: .72rem; color: var(--text-muted);
  margin-top: .35rem; line-height: 1.4;
}

/* ---- Utilities ---- */
.hidden { display: none !important; }
.mono { font-family: 'Courier New', monospace; font-size: .8rem; }
