:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --accent: #06b6d4;
  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --sidebar: #0f172a;
  --sidebar-client: #0d9488;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Auth / Login ── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 45%, #0e7490 100%);
  position: relative;
  overflow: hidden;
}

.auth-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(6, 182, 212, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(37, 99, 235, 0.2) 0%, transparent 50%);
  pointer-events: none;
}

.auth-wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
}

.auth-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.auth-logo {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -1px;
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
}

.auth-card .auth-subtitle {
  margin: 0 0 28px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.feature-list {
  margin: 24px 0 0;
  padding: 16px 0 0;
  border-top: 1px solid var(--border);
  list-style: none;
  display: grid;
  gap: 8px;
}

.feature-list li {
  color: var(--text-muted);
  font-size: 0.88rem;
  padding-left: 22px;
  position: relative;
}

.feature-list li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--success);
  font-weight: 700;
}

/* ── Forms ── */
.form-group { margin-bottom: 18px; }

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  color: #334155;
}

.form-control {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: #fff;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

textarea.form-control { min-height: 120px; resize: vertical; }

select.form-control { cursor: pointer; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
  color: #fff;
}

.btn-secondary { background: #64748b; color: #fff; }
.btn-secondary:hover { background: #475569; color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: 0.82rem; }
.btn-block { width: 100%; }

/* ── Alerts ── */
.alert {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 18px;
  font-size: 0.9rem;
  font-weight: 500;
}

.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ── App Shell ── */
.app-body { background: var(--bg); }

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

.sidebar {
  width: 250px;
  background: var(--sidebar);
  color: #fff;
  padding: 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-client { background: var(--sidebar-client); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-decoration: none;
  color: #fff;
}

.sidebar-brand:hover { color: #fff; opacity: 0.95; }

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  flex-shrink: 0;
}

.brand-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.brand-x {
  color: var(--accent);
  font-weight: 800;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 10px;
  flex: 1;
}

.sidebar-nav a {
  color: #94a3b8;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.topbar strong { font-size: 1rem; color: var(--text); }

.topbar nav { display: flex; align-items: center; gap: 4px; }

.topbar nav a {
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.88rem;
  transition: background 0.12s, color 0.12s;
}

.topbar nav a:hover {
  background: var(--bg);
  color: var(--text);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
  width: 100%;
}

.page-title {
  margin: 0 0 20px;
  font-size: 1.5rem;
  font-weight: 700;
}

/* ── Grid & Cards ── */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card h3 {
  margin: 0 0 16px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.stat-value {
  font-size: 30px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
}

.stat-label {
  color: var(--text-muted);
  margin-top: 6px;
  font-size: 0.88rem;
  font-weight: 500;
}

/* ── Tables ── */
.table-wrap { overflow: auto; border-radius: 8px; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.9rem;
}

th {
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:hover td { background: #f8fafc; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* ── Utilities ── */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.checkbox-label input { width: auto; }

.actions-cell { white-space: nowrap; }
.actions-cell .btn { margin-right: 4px; margin-bottom: 4px; }

.edit-row td { background: #f8fafc; padding: 16px !important; }
.edit-form .grid { margin-bottom: 12px; }

.api-creds code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.78rem;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 8px;
  }
  .sidebar-nav a { flex: 1 1 auto; text-align: center; font-size: 0.82rem; }
  .auth-card { padding: 28px 22px; }
}
