/* =========================================================================
   SASHA Crawler v2 — Dashboard styles
   - Design tokens (light + dark)
   - Layout: topbar + tabs + responsive widget grid
   - Components: cards, KPIs, table, kanban, skeletons, toasts
   - WCAG 2.2 AA: focus rings, ≥4.5:1 contrast, motion-safe
   ========================================================================= */

/* ----- Tokens ----------------------------------------------------------- */
:root {
  --brand: #5643c9;
  --brand-600: #4837b3;
  --brand-700: #3a2d96;
  --mint: #00dcbb;
  --mint-700: #00a690;
  --danger: #ff3333;
  --danger-700: #c62828;
  --warn: #f5a524;

  /* Surfaces (light) */
  --bg: #f7f7fb;
  --bg-elev: #ffffff;
  --bg-soft: #f1f0f7;
  --border: #e6e4ee;
  --border-strong: #d0cce0;

  --text: #14122b;
  --text-muted: #5b5872;
  --text-faint: #8c89a3;

  --shadow-sm: 0 1px 2px rgba(20, 18, 43, 0.06);
  --shadow-md: 0 4px 14px rgba(20, 18, 43, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 18, 43, 0.12);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --gap: 18px;
  --gap-lg: 24px;

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --gradient-brand: linear-gradient(135deg, var(--brand) 0%, #8e72ff 60%, var(--mint) 130%);

  --focus-ring: 0 0 0 3px rgba(86, 67, 201, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0a1f;
    --bg-elev: #14112c;
    --bg-soft: #1a1735;
    --border: #2a2549;
    --border-strong: #3a3460;

    --text: #f0eefc;
    --text-muted: #b6b1cf;
    --text-faint: #807ba0;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
  }
}

/* explicit overrides via [data-theme] attribute on <body> */
body[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7fb;
  --bg-elev: #ffffff;
  --bg-soft: #f1f0f7;
  --border: #e6e4ee;
  --border-strong: #d0cce0;
  --text: #14122b;
  --text-muted: #5b5872;
  --text-faint: #8c89a3;
}
body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0a1f;
  --bg-elev: #14112c;
  --bg-soft: #1a1735;
  --border: #2a2549;
  --border-strong: #3a3460;
  --text: #f0eefc;
  --text-muted: #b6b1cf;
  --text-faint: #807ba0;
}

/* ----- Reset / base ---------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: transparent;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: 6px;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 12px;
  background: var(--brand);
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  z-index: 100;
}
.skip-link:focus {
  top: 12px;
}

/* ----- Topbar ---------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 22px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: saturate(160%) blur(6px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.brand-name {
  font-size: 16px;
  font-weight: 800;
}
.brand-sub {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13px;
}
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--gradient-brand);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: var(--shadow-sm);
}
.brand-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  margin: 1px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  justify-content: center;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--text-muted);
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.tab[aria-selected="true"] {
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.tab[aria-selected="true"]:hover {
  background: var(--brand-600);
}
.tab i {
  width: 16px;
  height: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.icon-btn i {
  width: 18px;
  height: 18px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--gradient-brand);
  color: #fff;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}
.pill i {
  width: 13px;
  height: 13px;
}
.pill-demo {
  background: rgba(245, 165, 36, 0.14);
  color: #b6791a;
  border-color: rgba(245, 165, 36, 0.35);
}
@media (prefers-color-scheme: dark) {
  .pill-demo {
    color: #ffc56e;
  }
}

/* ----- Main / panels --------------------------------------------------- */
main {
  flex: 1;
  padding: 22px clamp(16px, 3vw, 32px) 60px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

.panel-head {
  margin-bottom: 18px;
}
.panel-head h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.muted {
  color: var(--text-muted);
  margin: 4px 0 0;
}

/* ----- Grid layout ----------------------------------------------------- */
.grid {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(12, 1fr);
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 200px;
  position: relative;
}
.card-hero {
  grid-column: span 5;
}
#widget-velocity {
  grid-column: span 7;
}
.card-wide {
  grid-column: span 12;
}
.card-full {
  grid-column: span 12;
}

@media (max-width: 1100px) {
  .card-hero,
  #widget-velocity {
    grid-column: span 12;
  }
}
@media (max-width: 768px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .card,
  .card-hero,
  .card-wide,
  .card-full,
  #widget-velocity {
    grid-column: 1 / -1;
  }
  .topbar {
    flex-wrap: wrap;
    padding: 10px 14px;
  }
  .tabs {
    order: 3;
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }
  .brand-sub {
    display: none;
  }
}

/* ----- Card subcomponents --------------------------------------------- */
.card h2 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.card-head .actions {
  display: flex;
  gap: 6px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13.5px;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  transition: background 0.15s, transform 0.05s;
}
.btn:hover {
  background: var(--border);
}
.btn:active {
  transform: translateY(1px);
}
.btn i {
  width: 15px;
  height: 15px;
}
.btn-primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.btn-primary:hover {
  background: var(--brand-600);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger-700);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
  border-radius: 8px;
}

/* ----- Revenue hero widget -------------------------------------------- */
.revenue {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}
.revenue-figure {
  font-size: clamp(40px, 5.5vw, 60px);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.05;
}
.revenue-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12.5px;
}
.delta-up {
  background: rgba(0, 220, 187, 0.16);
  color: var(--mint-700);
}
.delta-down {
  background: rgba(255, 51, 51, 0.14);
  color: var(--danger-700);
}
.delta i {
  width: 13px;
  height: 13px;
}
.revenue-mini {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}
.mini-stat {
  display: flex;
  flex-direction: column;
}
.mini-stat .v {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}
.mini-stat .l {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ----- Velocity chart -------------------------------------------------- */
.chart-host {
  flex: 1;
  min-height: 220px;
  width: 100%;
}

/* ----- Top offenders --------------------------------------------------- */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.tbl th,
.tbl td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.tbl th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  background: var(--bg-soft);
  position: sticky;
  top: 0;
}
.tbl tbody tr:hover {
  background: var(--bg-soft);
}
.tbl tbody tr.selected {
  background: rgba(86, 67, 201, 0.08);
}
.tbl input[type="checkbox"] {
  accent-color: var(--brand);
  width: 16px;
  height: 16px;
}
.tbl .num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.tbl .domain {
  font-weight: 600;
  color: var(--text);
}
.bulk-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  font-size: 13px;
}
.bulk-bar.hidden {
  display: none;
}

/* ----- Kanban ---------------------------------------------------------- */
.kanban {
  display: grid;
  grid-template-columns: repeat(7, minmax(220px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-top: 8px;
}
@media (max-width: 1280px) {
  .kanban {
    grid-template-columns: repeat(7, 240px);
  }
}
.kcol {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 320px;
}
.kcol-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.kcount {
  background: var(--bg-elev);
  color: var(--text);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  border: 1px solid var(--border);
}
.kcol[data-state="new"] .kcol-head { color: var(--brand); }
.kcol[data-state="reviewing"] .kcol-head { color: #b6791a; }
.kcol[data-state="licensed"] .kcol-head { color: #1a8870; }
.kcol[data-state="takedown_sent"] .kcol-head { color: #c8362f; }
.kcol[data-state="settlement"] .kcol-head { color: #6b3fbb; }
.kcol[data-state="court"] .kcol-head { color: #8a1717; }
.kcol[data-state="resolved"] .kcol-head { color: var(--mint-700); }

.kcol.drag-over {
  background: rgba(86, 67, 201, 0.10);
  border-color: var(--brand);
  outline: 2px dashed var(--brand);
  outline-offset: -2px;
}

.kcard {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: grab;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, transform 0.1s;
}
.kcard:hover {
  box-shadow: var(--shadow-md);
}
.kcard:active {
  cursor: grabbing;
}
.kcard.dragging {
  opacity: 0.45;
  transform: rotate(-1deg);
}
.kcard-id {
  font-size: 11.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.kcard-domain {
  font-weight: 600;
  font-size: 13.5px;
  margin: 2px 0 6px;
  word-break: break-all;
}
.kcard-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
}
.kcard-eur {
  font-weight: 700;
  color: var(--text);
}

/* ----- Skeletons ------------------------------------------------------- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-soft) 0%,
    var(--border) 50%,
    var(--bg-soft) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-md);
}
.skeleton-hero {
  height: 100%;
  min-height: 220px;
}
.skeleton-chart {
  height: 220px;
}
.skeleton-table {
  height: 320px;
}
.skeleton-kanban {
  height: 360px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

/* ----- Empty + error states ------------------------------------------- */
.empty,
.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty i,
.error i {
  width: 36px;
  height: 36px;
  margin-bottom: 8px;
  color: var(--brand);
}
.empty h3,
.error h3 {
  color: var(--text);
  margin: 4px 0;
}
.error i { color: var(--danger); }

/* ----- Toasts ---------------------------------------------------------- */
.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  max-width: 360px;
  animation: toast-in 0.18s ease-out;
}
.toast.success { border-left-color: var(--mint); }
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ----- Utility --------------------------------------------------------- */
[hidden] { display: none !important; }
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
