/* Cadenza Admin — modern, premium, alive */

:root {
  /* Backgrounds */
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-elevated: #ffffff;
  --sidebar: #0f172a;
  --sidebar-hover: rgba(255, 255, 255, 0.05);
  --sidebar-active-bg: rgba(99, 102, 241, 0.14);
  --sidebar-active-border: #6366f1;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #f8fafc;

  /* Text */
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #64748b;

  /* Brand accent */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-ring: rgba(79, 70, 229, 0.2);

  /* Semantic colors */
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-hover: #15803d;
  --success-soft: #f0fdf4;
  --warning: #d97706;
  --warning-hover: #b45309;
  --warning-soft: #fffbeb;
  --info: #2563eb;
  --info-soft: #eff6ff;

  /* Borders */
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  /* Radius & shadows */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.05);

  /* Typography */
  --font-sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Transitions */
  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* ─── Layout ─── */
.admin-app {
  display: flex;
  min-height: 100vh;
  opacity: 0;
  animation: pageFadeIn 360ms ease-out forwards;
}

@keyframes pageFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .admin-app { animation: none; opacity: 1; }
}

/* ─── Sidebar ─── */
.admin-sidebar {
  width: 244px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid rgba(255,255,255,0.06);
}

.admin-sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 22px;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  letter-spacing: -0.3px;
}

.admin-sidebar .brand::before {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.45);
}

.admin-sidebar nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}

.admin-sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  margin: 2px 0;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  border-left: 0;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

.admin-sidebar nav a:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
  transform: translateX(2px);
}

.admin-sidebar nav a.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.25);
}

.admin-sidebar nav a.active::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--sidebar-active-border);
  box-shadow: 0 0 8px var(--sidebar-active-border);
}

.admin-sidebar nav .group {
  padding: 16px 14px 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #64748b;
}

/* ─── Main / Topbar ─── */
.admin-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.admin-topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 26px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
  background: rgba(255,255,255,0.92);
}

.admin-topbar .title {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.3px;
  color: var(--text);
}

.admin-topbar .user {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.admin-topbar form { display: inline; }

/* ─── Content ─── */
.admin-content {
  padding: 26px;
  flex: 1;
}

/* ─── Flash messages ─── */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  animation: flashSlide 240ms ease-out;
}

@keyframes flashSlide {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.flash.success { background: var(--success-soft); border-color: #bbf7d0; color: #166534; }
.flash.error { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.flash.info { background: var(--info-soft); border-color: #bfdbfe; color: #1e40af; }

/* ─── Cards ─── */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 22px;
  overflow: hidden;
  transition: box-shadow var(--transition), transform var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: linear-gradient(to bottom, #fff, #fafbfc);
}

.card-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

.card-body { padding: 20px; }

/* ─── Stats / Metric cards ─── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
  margin-bottom: 26px;
}

.stat {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}

.stat::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--stat-accent, var(--primary)), transparent);
  opacity: 0.85;
}

.stat:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.stat .icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  font-size: 16px;
  background: var(--stat-soft, var(--primary-soft));
  color: var(--stat-accent, var(--primary));
}

.stat .label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.stat .value {
  font-size: 26px;
  font-weight: 800;
  margin-top: 6px;
  letter-spacing: -0.6px;
  color: var(--text);
}

/* Stat color themes */
.stat.stat-paid { --stat-accent: var(--success); --stat-soft: var(--success-soft); }
.stat.stat-revenue { --stat-accent: var(--primary); --stat-soft: var(--primary-soft); }
.stat.stat-overdue { --stat-accent: var(--danger); --stat-soft: var(--danger-soft); }
.stat.stat-unpaid { --stat-accent: var(--warning); --stat-soft: var(--warning-soft); }
.stat.stat-trials { --stat-accent: var(--info); --stat-soft: var(--info-soft); }
.stat.stat-inventory { --stat-accent: #7c3aed; --stat-soft: #f3e8ff; }
.stat.stat-actions { --stat-accent: #ea580c; --stat-soft: #fff7ed; }
.stat.stat-neutral { --stat-accent: var(--muted); --stat-soft: #f1f5f9; }

.stat.stat-actions.has-actions .icon::after {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
  margin-left: 6px;
  box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5);
  animation: actionPulse 1.8s infinite;
}

@keyframes actionPulse {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .stat.stat-actions.has-actions .icon::after { animation: none; }
}

/* ─── Tables ─── */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}

th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

th {
  background: #f8fafc;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

tbody tr {
  transition: background var(--transition);
}

tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:hover td { background: #f1f5f9; }

tbody tr:last-child td { border-bottom: 0; }

/* ─── Badges ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  line-height: 1;
  white-space: nowrap;
  background: #f1f5f9;
  color: #475569;
}

.badge::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.badge.draft { background: #f1f5f9; color: #475569; }
.badge.pending { background: var(--warning-soft); color: #92400e; }
.badge.approved { background: var(--success-soft); color: #065f46; }
.badge.archived { background: #f1f5f9; color: #475569; }
.badge.paid { background: var(--success-soft); color: #065f46; }
.badge.unpaid { background: var(--warning-soft); color: #92400e; }
.badge.overdue { background: var(--danger-soft); color: #991b1b; }
.badge.refunded { background: #f1f5f9; color: #475569; }
.badge.active { background: var(--success-soft); color: #065f46; }
.badge.cooldown { background: var(--warning-soft); color: #92400e; }
.badge.disabled { background: var(--danger-soft); color: #991b1b; }
.badge.delivered { background: var(--info-soft); color: #1e40af; }
.badge.completed { background: var(--success-soft); color: #065f46; }
.badge.failed { background: var(--danger-soft); color: #991b1b; }
.badge.cancelled { background: #f1f5f9; color: #475569; }
.badge.trial_active { background: var(--info-soft); color: #1e40af; }
.badge.ready { background: var(--info-soft); color: #1e40af; }
.badge.overdue_invoice { background: var(--danger-soft); color: #991b1b; }
.badge.trial_expiring { background: var(--info-soft); color: #1e40af; }
.badge.low_inventory { background: var(--warning-soft); color: #92400e; }

/* ─── Forms ─── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.form-group input[type=text],
.form-group input[type=email],
.form-group input[type=number],
.form-group input[type=password],
.form-group input[type=url],
.form-group input[type=datetime-local],
.form-group input[type=file],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.form-group textarea { min-height: 90px; resize: vertical; }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-ring);
  transform: translateY(-1px);
}

.form-group input[type=file] { padding: 7px; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: #f1f5f9;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn:hover {
  background: #e2e8f0;
  color: var(--text);
  text-decoration: none;
  transform: translateY(-1px);
}

.btn:active { transform: translateY(0); }

.btn.primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.18);
}
.btn.primary:hover { background: var(--primary-hover); box-shadow: 0 4px 10px rgba(79, 70, 229, 0.22); }

.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: var(--danger-hover); }

.btn.small { padding: 5px 10px; font-size: 12px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ─── Login page ─── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.12) 0%, transparent 35%),
    radial-gradient(circle at 80% 80%, rgba(168, 85, 247, 0.10) 0%, transparent 35%),
    #f1f5f9;
  animation: pageFadeIn 400ms ease-out;
}

.login-box {
  background: var(--panel);
  padding: 36px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
  border: 1px solid var(--border);
}

.login-box h1 {
  margin: 0 0 22px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.6px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.login-box h1::before {
  content: "";
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  box-shadow: 0 0 14px rgba(99, 102, 241, 0.45);
}

.login-box .error {
  color: var(--danger);
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 500;
  background: var(--danger-soft);
  padding: 10px 12px;
  border-radius: var(--radius);
}

.login-box button[type=submit] {
  width: 100%;
  padding: 10px;
  font-size: 14px;
}

/* ─── Utility ─── */
.text-muted { color: var(--muted); }
.text-small { font-size: 12px; }
.mt { margin-top: 18px; }
.mb { margin-bottom: 18px; }

pre {
  background: #f8fafc;
  padding: 14px;
  border-radius: var(--radius);
  overflow: auto;
  font-size: 12px;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
}

.empty {
  color: var(--muted);
  padding: 32px;
  text-align: center;
  font-size: 13px;
  background: #fafbfc;
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}

.action-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.action-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.5;
}

.action-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.action-list li:first-child { padding-top: 0; }

/* ─── Chat ─── */
.chat-messages {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  padding: 16px;
  height: 420px;
  overflow-y: auto;
  margin-bottom: 14px;
  box-shadow: inset 0 1px 3px rgba(15,23,42,0.04);
}

.chat-message { margin-bottom: 14px; animation: messageIn 220ms ease-out; }
@keyframes messageIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message .meta {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.chat-message .text {
  padding: 10px 14px;
  border-radius: var(--radius);
  display: inline-block;
  max-width: 90%;
  line-height: 1.55;
  font-size: 13.5px;
}

.chat-message.user .text {
  background: var(--primary-soft);
  color: #312e81;
  border-bottom-left-radius: 3px;
}

.chat-message.assistant .text {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-right-radius: 3px;
}

/* ─── Pagination ─── */
.text-muted a {
  color: var(--primary);
  font-weight: 600;
}

/* ─── Tables in forms (settings) ─── */
form table {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
}
form table th { background: #f1f5f9; }
form table td { padding: 10px 14px; }

/* ─── Mobile ─── */
@media (max-width: 768px) {
  .admin-app { flex-direction: column; }
  .admin-sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    order: 2;
    border-right: 0;
    border-top: 1px solid rgba(255,255,255,0.06);
  }
  .admin-sidebar .brand { display: none; }
  .admin-sidebar nav {
    display: flex;
    padding: 8px 10px;
    width: 100%;
  }
  .admin-sidebar nav .group { display: none; }
  .admin-sidebar nav a {
    white-space: nowrap;
    border-bottom: 0;
    padding: 8px 12px;
    margin: 0 3px;
  }
  .admin-sidebar nav a.active {
    border-bottom-color: transparent;
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.3);
  }
  .admin-main { order: 1; }
  .admin-content { padding: 16px; }
  .stats { grid-template-columns: 1fr; }
  .admin-topbar { padding: 12px 16px; }
  .admin-topbar .title { font-size: 16px; }
}
