/* ─── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  --primary:        #2563EB;
  --primary-dark:   #1D4ED8;
  --primary-light:  #EFF6FF;
  --secondary:      #3B82F6;
  --cta:            #F97316;
  --bg:             #F8FAFC;
  --bg-white:       #FFFFFF;
  --surface:        #FFFFFF;
  --border:         #E2E8F0;
  --border-hover:   #CBD5E1;
  --text:           #1E293B;
  --text-muted:     #64748B;
  --text-light:     #94A3B8;
  --success:        #16A34A;
  --danger:         #DC2626;
  --warning:        #D97706;
  --info:           #0284C7;
  --radius-sm:      6px;
  --radius:         10px;
  --radius-lg:      16px;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:         0 4px 12px rgba(0,0,0,.08);
  --shadow-md:      0 8px 24px rgba(0,0,0,.10);
  --transition:     150ms ease;
  --transition-md:  250ms ease;
  --sidebar-width:  240px;
  --topbar-height:  56px;
}

/* ─── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { font-size: 16px; scroll-behavior: smooth; }

input, textarea, select, button, .form-control, .form-select,
.modal, .badge, .list-group-item, .card { font-family: inherit; }

body {
  font-family: 'Lato', system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  margin: 0;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Lato', system-ui, sans-serif;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  margin-bottom: .5rem;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ─── Focus ──────────────────────────────────────────────────────────────── */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
.btn:focus-visible, .form-control:focus, .form-select:focus {
  box-shadow: 0 0 0 3px rgba(37,99,235,.25);
  border-color: var(--primary);
  outline: none;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  font-family: 'Lato', sans-serif;
  font-weight: 600;
  font-size: .875rem;
  border-radius: var(--radius-sm);
  padding: .5rem 1.25rem;
  transition: all var(--transition);
  cursor: pointer;
  border-width: 1.5px;
  letter-spacing: .01em;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37,99,235,.3);
}

.btn-outline-secondary {
  border-color: var(--border);
  color: var(--text-muted);
  background: var(--bg-white);
}
.btn-outline-secondary:hover, .btn-outline-secondary.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.btn-outline-primary {
  border-color: var(--primary);
  color: var(--primary);
  background: transparent;
}
.btn-outline-primary:hover {
  background: var(--primary);
  color: #fff;
  transform: translateY(-1px);
}

.btn-sm { padding: .35rem .875rem; font-size: .8125rem; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-label {
  font-size: .8125rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: .375rem;
}

.form-control, .form-select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  font-size: .9375rem;
  color: var(--text);
  background: var(--bg-white);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:hover, .form-select:hover { border-color: var(--border-hover); }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.card-body { padding: 1.25rem; }

/* ─── Alerts ─────────────────────────────────────────────────────────────── */
.alert { border-radius: var(--radius); border-width: 1.5px; font-size: .9375rem; }
.alert-danger  { background: #FEF2F2; border-color: #FECACA; color: var(--danger); }
.alert-success { background: #F0FDF4; border-color: #BBF7D0; color: var(--success); }
.alert-info    { background: #EFF6FF; border-color: #BFDBFE; color: #1E40AF; }
.alert-warning { background: #FFFBEB; border-color: #FDE68A; color: var(--warning); }

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.table { color: var(--text); font-size: .9rem; }
.table thead.table-dark th {
  background: var(--text);
  color: rgba(255,255,255,.9);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  border-color: transparent;
  padding: .75rem 1rem;
}
.table tbody tr { transition: background var(--transition); }
.table-hover tbody tr:hover { background: var(--primary-light); }
.table td, .table th { vertical-align: middle; padding: .625rem 1rem; border-color: var(--border); }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  font-size: .7rem;
  letter-spacing: .03em;
  border-radius: var(--radius-sm);
  padding: .3em .65em;
}

/* ══════════════════════════════════════════════════════════════════════════
   APP LAYOUT
   ══════════════════════════════════════════════════════════════════════════ */

/* Sidebar */
.app-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--text);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}
.app-sidebar::-webkit-scrollbar { display: none; }

.sidebar-logo {
  display: flex;
  align-items: center;
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  text-decoration: none;
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-family: 'Lato', system-ui, sans-serif;
  font-size: 1.375rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.5px;
  line-height: 1;
}
.sidebar-logo-text span { color: var(--cta); }

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  list-style: none;
  margin: 0;
}

.sidebar-section-label {
  font-size: .625rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(255,255,255,.35);
  padding: .5rem 1.25rem .25rem;
  margin-top: .5rem;
  display: block;
}

.sidebar-nav-item { margin: 0; }

.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem 1rem;
  margin: .1rem .5rem;
  color: rgba(255,255,255,.55);
  font-size: .875rem;
  font-weight: 500;
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color var(--transition-md), background var(--transition-md);
  cursor: pointer;
  border: none;
  background: transparent;
  width: calc(100% - 1rem);
  text-align: left;
}
.sidebar-nav-link svg {
  flex-shrink: 0;
  opacity: .55;
  transition: opacity var(--transition-md);
}
.sidebar-nav-link:hover {
  color: rgba(255,255,255,.9);
  background: rgba(255,255,255,.07);
}
.sidebar-nav-link:hover svg { opacity: .9; }
.sidebar-nav-link.active {
  color: #fff;
  font-weight: 600;
  background: rgba(37,99,235,.35);
}
.sidebar-nav-link.active svg { opacity: 1; }

/* Sidebar submenus */
.sidebar-submenu {
  list-style: none;
  margin: .15rem 0 .25rem;
  padding: 0 0 0 2.5rem;
}
.sidebar-submenu .sidebar-nav-link {
  font-size: .8125rem;
  padding: .35rem .75rem;
  color: rgba(255,255,255,.4);
}
.sidebar-submenu .sidebar-nav-link:hover {
  color: rgba(255,255,255,.8);
  background: rgba(255,255,255,.06);
}
.sidebar-submenu .sidebar-nav-link.active {
  color: rgba(255,255,255,.95);
  background: rgba(37,99,235,.25);
}

/* Sidebar user footer */
.sidebar-user {
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 1rem 1.25rem;
  flex-shrink: 0;
}
.sidebar-user-info { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.sidebar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(37,99,235,.5);
  display: flex; align-items: center; justify-content: center;
  font-size: .875rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.sidebar-user-name {
  font-size: .875rem; font-weight: 600; color: #fff;
  line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-email {
  font-size: .75rem; color: rgba(255,255,255,.45);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-logout {
  display: flex; align-items: center; gap: .5rem;
  width: 100%; padding: .5rem .75rem;
  background: rgba(220,38,38,.15);
  border: 1px solid rgba(220,38,38,.25);
  border-radius: var(--radius-sm);
  color: #FCA5A5; font-size: .8125rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition); text-align: left;
}
.sidebar-logout:hover { background: rgba(220,38,38,.28); color: #FECACA; border-color: rgba(220,38,38,.4); }

/* Topbar */
.app-topbar {
  position: fixed; top: 0;
  left: var(--sidebar-width); right: 0;
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 1.5rem;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.topbar-title {
  font-family: 'Lato', system-ui, sans-serif;
  font-size: 1.125rem; font-weight: 600;
  color: var(--text); margin: 0;
}

/* Main content */
.app-main { margin-left: var(--sidebar-width); padding-top: var(--topbar-height); min-height: 100vh; }
.app-content { padding: 2rem 1.5rem; }

/* Mobile */
.sidebar-toggle {
  display: none; background: none; border: none;
  cursor: pointer; padding: .5rem; color: var(--text);
  margin-right: .75rem; border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.sidebar-toggle:hover { background: var(--bg); }

.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.4); z-index: 150;
}

@media (max-width: 991px) {
  .app-sidebar { transform: translateX(-100%); transition: transform var(--transition-md); }
  .app-sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .app-topbar { left: 0; }
  .app-main { margin-left: 0; }
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  .app-content { padding: 1.25rem 1rem; }
}

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

/* ══════════════════════════════════════════════════════════════════════════
   KPI CARDS  (scraper dashboard overview)
   ══════════════════════════════════════════════════════════════════════════ */

.kpi-group-label {
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: .75rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-md), box-shadow var(--transition-md);
}
.kpi-card:hover { border-color: var(--border-hover); box-shadow: var(--shadow); }

.kpi-card-label {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: .5rem;
}
.kpi-card-value {
  font-family: 'Lato', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}
.kpi-card-value.kpi-success { color: var(--success); }
.kpi-card-value.kpi-danger  { color: var(--danger); }
.kpi-card-value.kpi-warning { color: var(--warning); }
.kpi-card-value.kpi-primary { color: var(--primary); }
.kpi-card-value.kpi-muted   { color: var(--text-muted); }
.kpi-card-value.kpi-info    { color: var(--info); }

/* ══════════════════════════════════════════════════════════════════════════
   DATATABLES  — aligned with design tokens
   ══════════════════════════════════════════════════════════════════════════ */

/* Card wrapper */
.dt-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1rem .875rem;
}

/* Top controls row */
.dt-layout-row:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .875rem;
  flex-wrap: wrap;
}

/* Length select */
.dt-length label {
  font-size: .8125rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: .4rem;
}
.dt-length select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .3rem .5rem;
  font-size: .8125rem;
  color: var(--text);
  background: var(--bg-white);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.dt-length select:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

/* Search input */
.dt-search {
  display: flex;
  align-items: center;
  gap: .4rem;
}
.dt-search label { font-size: .8125rem; color: var(--text-muted); }
.dt-search input {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .35rem .75rem;
  font-size: .875rem;
  color: var(--text);
  background: var(--bg-white);
  min-width: 180px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.dt-search input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

/* Table area — rounded */
.dt-layout-cell.dt-full {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}
.dt-layout-cell.dt-full table { margin-bottom: 0 !important; }
.dt-layout-cell.dt-full .table-responsive { border: none; overflow: visible; }

/* thead first/last th round top corners */
.dt-container table.dataTable thead.table-dark tr:first-child th:first-child {
  border-top-left-radius: calc(var(--radius-sm) - 1px);
}
.dt-container table.dataTable thead.table-dark tr:first-child th:last-child {
  border-top-right-radius: calc(var(--radius-sm) - 1px);
}

/* Bottom row */
.dt-layout-row:last-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-top: .75rem;
  padding-top: .75rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* Info text */
.dt-info { font-size: .8125rem; color: var(--text-muted); margin: 0; }

/* Pagination */
.dt-paging .pagination { margin: 0; gap: .2rem; display: flex; }
.dt-paging .page-link {
  border: 1.5px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--text-muted) !important;
  font-size: .8125rem;
  font-weight: 600;
  padding: .3rem .65rem;
  background: var(--bg-white) !important;
  transition: all var(--transition);
  line-height: 1.5;
}
.dt-paging .page-link:hover {
  border-color: var(--primary) !important;
  color: var(--primary) !important;
  background: var(--primary-light) !important;
}
.dt-paging .page-item.active .page-link {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
}
.dt-paging .page-item.disabled .page-link { opacity: .4; pointer-events: none; }

/* Sort arrows */
table.dataTable th.dt-orderable-asc,
table.dataTable th.dt-orderable-desc { cursor: pointer; }
table.dataTable th span.dt-column-order { opacity: .35; }
table.dataTable th.dt-ordering-asc span.dt-column-order,
table.dataTable th.dt-ordering-desc span.dt-column-order { opacity: 1; color: var(--cta); }

/* ══════════════════════════════════════════════════════════════════════════
   AUTH LAYOUT
   ══════════════════════════════════════════════════════════════════════════ */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 2rem 1rem;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2rem;
  width: 100%; max-width: 420px;
}
.auth-logo {
  font-family: 'Lato', system-ui, sans-serif;
  font-size: 1.875rem; font-weight: 700;
  color: var(--text); letter-spacing: -.5px;
  display: block; margin-bottom: 1.75rem; text-align: center;
}
.auth-logo span { color: var(--cta); }
.auth-title { font-size: 1.375rem; font-weight: 700; color: var(--text); margin-bottom: .375rem; text-align: center; }
.auth-subtitle { font-size: .875rem; color: var(--text-muted); text-align: center; margin-bottom: 1.75rem; }
