/* =========================================================
 * xDebt Admin Design System (DS)
 * Scope: admin.xdebt.com and /admin/*  — NOT customer / marketing.
 * Every rule is scoped under .admin-ds so importing this file
 * alongside Tailwind does not affect customer pages.
 * Source of truth: /var/www/xdebt-app/docs/design_system.md
 * ========================================================= */

.admin-ds {
  /* Surfaces */
  --bg:           #ECEEF2;
  --card:         #FFFFFF;
  --border:       #E2E5EC;

  /* Navigation shell (only place dark is allowed) */
  --nav:          #1E2328;
  --sidebar-bg:   #252B32;
  --nav-border:   #2E343B;

  /* Text */
  --text-primary:   #111827;
  --text-secondary: #6B7280;
  --text-muted:     #9CA3AF;

  /* Semantic accents */
  --blue:       #2A6EBB;
  --blue-light: #3B82D4;
  --blue-dim:   rgba(42,110,187,.10);
  --green:      #16A34A;
  --green-dim:  rgba(22,163,74,.10);
  --red:        #C53030;
  --red-dim:    rgba(197,48,48,.09);
  --amber:      #B45309;
  --amber-dim:  rgba(180,83,9,.09);
  --purple:     #7C3AED;
  --purple-dim: rgba(124,58,237,.10);

  /* Elevation — always shadow + hairline, never one without the other */
  --shadow:    0 1px 2px rgba(0,0,0,.05), 0 1px 4px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.09), 0 1px 3px rgba(0,0,0,.04);

  /* Geometry */
  --radius:    10px;
  --radius-sm: 7px;

  /* Density (comfortable is default) */
  --density-row-h: 44px;
  --density-pad-y: 14px;
  --density-pad-x: 18px;

  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, "Segoe UI", Inter, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.admin-ds[data-density="compact"] { --density-row-h: 36px; --density-pad-y: 10px; --density-pad-x: 14px; }
.admin-ds[data-density="dense"]   { --density-row-h: 30px; --density-pad-y: 8px;  --density-pad-x: 12px; }

/* ---------------- typography helpers ---------------- */
.admin-ds .ds-kpi-value  { font-size: 30px;   font-weight: 700; letter-spacing: -1px;    line-height: 1.1; font-variant-numeric: tabular-nums; }
.admin-ds .ds-identity   { font-size: 22px;   font-weight: 800; letter-spacing: -.4px;   line-height: 1.1; }
.admin-ds .ds-summary    { font-size: 17px;   font-weight: 800; letter-spacing: -.25px;  line-height: 1.2; }
.admin-ds .ds-card-title { font-size: 13.5px; font-weight: 700; color: var(--text-primary); }
.admin-ds .ds-body       { font-size: 12.5px; font-weight: 500; color: var(--text-primary); line-height: 1.5; }
.admin-ds .ds-meta       { font-size: 11.5px; font-weight: 600; color: var(--text-secondary); }
.admin-ds .ds-micro      { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }

/* ---------------- section card ---------------- */
.admin-ds .section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: ds-fadeUp .3s ease both;
}
.admin-ds .section-card + .section-card { margin-top: 16px; }

.admin-ds .section-card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.admin-ds .section-card-head-left { display: flex; align-items: center; gap: 10px; }
.admin-ds .section-card-icon {
  width: 28px; height: 28px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  background: var(--blue-dim); color: var(--blue);
}
.admin-ds .section-card-icon.blue   { background: var(--blue-dim);   color: var(--blue); }
.admin-ds .section-card-icon.green  { background: var(--green-dim);  color: var(--green); }
.admin-ds .section-card-icon.amber  { background: var(--amber-dim);  color: var(--amber); }
.admin-ds .section-card-icon.red    { background: var(--red-dim);    color: var(--red); }
.admin-ds .section-card-icon.purple { background: var(--purple-dim); color: var(--purple); }
.admin-ds .section-card-icon svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.admin-ds .section-card-title { font-size: 13.5px; font-weight: 700; color: var(--text-primary); }
.admin-ds .section-card-body { padding: 16px 18px; }
.admin-ds .section-card.compact .section-card-body { padding: 12px 14px; }

/* ---------------- KPI card ---------------- */
.admin-ds .kpi-card { padding: 14px 16px; }
.admin-ds .kpi-label { font-size: 11.5px; font-weight: 600; color: var(--text-secondary); text-transform: none; letter-spacing: 0; }
.admin-ds .kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -1px; line-height: 1.1; color: var(--text-primary); font-variant-numeric: tabular-nums; margin-top: 2px; }
.admin-ds .kpi-row   { display: flex; align-items: center; gap: 8px; }
.admin-ds .kpi-delta { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; line-height: 1; }
.admin-ds .kpi-delta.up   { background: var(--green-dim); color: var(--green); }
.admin-ds .kpi-delta.down { background: var(--red-dim);   color: var(--red); }
.admin-ds .kpi-spark { height: 40px; margin-top: 8px; }

/* ---------------- pills ---------------- */
.admin-ds .pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 20px;
  font-size: 11.5px; font-weight: 700; line-height: 1;
  background: #F3F4F6; color: var(--text-secondary);
  border: 1px solid var(--border);
}
.admin-ds .pill-ok   { background: var(--green-dim); color: var(--green); border-color: rgba(22,163,74,.2); }
.admin-ds .pill-warn { background: var(--amber-dim); color: var(--amber); border-color: rgba(180,83,9,.2); }
.admin-ds .pill-bad  { background: var(--red-dim);   color: var(--red);   border-color: rgba(197,48,48,.2); }
.admin-ds .pill-info { background: var(--blue-dim);  color: var(--blue);  border-color: rgba(42,110,187,.2); }
.admin-ds .pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------------- buttons ---------------- */
.admin-ds .btn,
.admin-ds .btn-primary,
.admin-ds .btn-danger,
.admin-ds .btn-ghost {
  height: 32px; padding: 0 14px; border-radius: var(--radius-sm);
  font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--card); color: var(--text-primary);
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
  text-decoration: none;
}
.admin-ds .btn:hover         { background: #F9FAFB; }
.admin-ds .btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(42,110,187,.18); border-color: var(--blue); }

.admin-ds .btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.admin-ds .btn-primary:hover { background: var(--blue-light); border-color: var(--blue-light); }

.admin-ds .btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.admin-ds .btn-danger:hover { filter: brightness(1.05); }

.admin-ds .btn-ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.admin-ds .btn-ghost:hover { background: rgba(0,0,0,.04); color: var(--text-primary); }

.admin-ds .btn-sm  { height: 26px; padding: 0 10px; font-size: 11.5px; }
.admin-ds .btn-lg  { height: 36px; padding: 0 16px; font-size: 13px; }
.admin-ds .btn-block { width: 100%; }

/* ---------------- inputs ---------------- */
.admin-ds .ds-label {
  display: block; font-size: 11.5px; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 6px;
}
.admin-ds .ds-input,
.admin-ds .ds-select,
.admin-ds .ds-textarea {
  width: 100%; height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); color: var(--text-primary);
  font: inherit; font-size: 13px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.admin-ds .ds-textarea { height: auto; padding: 10px 12px; line-height: 1.5; }
.admin-ds .ds-input:focus,
.admin-ds .ds-select:focus,
.admin-ds .ds-textarea:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(42,110,187,.15);
}
.admin-ds .ds-input::placeholder { color: var(--text-muted); }

.admin-ds .ds-helper { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.admin-ds .ds-error  { font-size: 11.5px; color: var(--red);        margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.admin-ds .ds-required-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--red); margin-left: 4px; }

/* ---------------- tables ---------------- */
.admin-ds .ds-table { width: 100%; border-collapse: collapse; background: var(--card); font-variant-numeric: tabular-nums; }
.admin-ds .ds-table th {
  text-align: left; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted);
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: var(--card); position: sticky; top: 0; z-index: 1;
}
.admin-ds .ds-table td {
  font-size: 12.5px; color: var(--text-primary);
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  height: var(--density-row-h);
}
.admin-ds .ds-table tbody tr:hover { background: rgba(42,110,187,.04); }
.admin-ds .ds-table tbody tr:last-child td { border-bottom: 0; }

/* ---------------- tabs ---------------- */
.admin-ds .ds-tabbar {
  display: flex; gap: 6px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px;
  box-shadow: var(--shadow);
}
.admin-ds .ds-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 700; color: var(--text-secondary);
  cursor: pointer; border: 1px solid transparent;
  text-decoration: none;
}
.admin-ds .ds-tab:hover { color: var(--text-primary); }
.admin-ds .ds-tab.is-active { background: var(--blue); color: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.06); }

.admin-ds .ds-subpills { display: flex; gap: 6px; padding: 4px; }
.admin-ds .ds-subpill {
  padding: 6px 12px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; color: var(--text-secondary);
  border: 1px solid transparent; cursor: pointer;
}
.admin-ds .ds-subpill.is-active {
  background: var(--blue-dim); color: var(--blue);
  border-color: rgba(42,110,187,.2);
}

/* ---------------- layout shell ---------------- */
.admin-ds .ds-shell { display: flex; min-height: 100vh; }
.admin-ds .ds-topbar {
  position: sticky; top: 0; z-index: 40;
  height: 52px; background: var(--nav); color: #fff;
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px; border-bottom: 1px solid var(--nav-border);
}
.admin-ds .ds-topbar a { color: #fff; text-decoration: none; }
.admin-ds .ds-topbar .ds-topbar-left { display: flex; align-items: center; gap: 12px; }
.admin-ds .ds-topbar .ds-topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.admin-ds .ds-sidebar {
  width: 248px; min-height: 100vh;
  background: var(--sidebar-bg); color: rgba(255,255,255,.8);
  padding: 12px 8px; font-size: 13px;
  position: sticky; top: 0; align-self: flex-start;
}
.admin-ds .ds-sidebar-section { padding: 8px 4px 4px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: rgba(255,255,255,.4); }
.admin-ds .ds-sidebar a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 6px;
  color: rgba(255,255,255,.8); text-decoration: none;
  font-size: 13px;
}
.admin-ds .ds-sidebar a:hover   { background: rgba(255,255,255,.04); color: #fff; }
.admin-ds .ds-sidebar a.is-active { background: rgba(255,255,255,.06); color: #fff; }
.admin-ds .ds-sidebar svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 15px; }
.admin-ds .ds-main  { flex: 1; min-width: 0; padding: 20px 24px; }
.admin-ds .ds-page-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.admin-ds .ds-page-title { font-size: 17px; font-weight: 800; letter-spacing: -.25px; color: var(--text-primary); }

/* ---------------- states (loading / empty / error) ---------------- */
.admin-ds .section-card[data-state="loading"] .section-card-body > * { visibility: hidden; }
.admin-ds .section-card[data-state="loading"] .section-card-body::before {
  content: ""; display: block; height: 16px; margin-bottom: 8px;
  background: linear-gradient(to right,#f1f5f9,#e5e7eb,#f1f5f9);
  background-size: 200% 100%; animation: ds-shimmer 1.4s linear infinite;
  border-radius: 4px;
}
.admin-ds .section-card[data-state="loading"] .section-card-body::after {
  content: ""; display: block; height: 16px; width: 70%;
  background: linear-gradient(to right,#f1f5f9,#e5e7eb,#f1f5f9);
  background-size: 200% 100%; animation: ds-shimmer 1.4s linear infinite;
  border-radius: 4px;
}

.admin-ds .ds-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 32px; color: var(--text-secondary);
}
.admin-ds .ds-empty svg { width: 44px; height: 44px; stroke: var(--text-muted); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 12px; }
.admin-ds .ds-empty h4 { font-size: 13px; font-weight: 700; color: var(--text-primary); margin: 0 0 4px; }
.admin-ds .ds-empty p  { font-size: 12.5px; color: var(--text-secondary); margin: 0 0 16px; }

/* ---------------- motion ---------------- */
@keyframes ds-fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes ds-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.admin-ds .delay-05 { animation-delay: .05s; }
.admin-ds .delay-10 { animation-delay: .10s; }
.admin-ds .delay-15 { animation-delay: .15s; }
.admin-ds .delay-20 { animation-delay: .20s; }
.admin-ds .delay-25 { animation-delay: .25s; }
.admin-ds .delay-30 { animation-delay: .30s; }

@media (prefers-reduced-motion: reduce) {
  .admin-ds .section-card { animation: none; }
  .admin-ds * { transition-duration: 0s !important; }
}

/* ---------------- print ---------------- */
@media print {
  .admin-ds .ds-topbar,
  .admin-ds .ds-sidebar,
  .admin-ds .no-print,
  #__diag_dot, #__diag_panel {
    display: none !important;
  }
  .admin-ds { background: #fff; }
  .admin-ds .section-card { box-shadow: none; break-inside: avoid; }
  .admin-ds .ds-table tbody tr:hover { background: transparent; }
}

/* ---------------- small-viewport block (desktop-only tool) ---------------- */
.admin-ds .ds-desktop-only-banner { display: none; }
@media (max-width: 1023px) {
  .admin-ds .ds-shell { display: none; }
  .admin-ds .ds-desktop-only-banner {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 100vh; padding: 32px; text-align: center;
    color: var(--text-secondary); background: var(--bg);
  }
  .admin-ds .ds-desktop-only-banner h1 { font-size: 17px; font-weight: 800; color: var(--text-primary); margin: 0 0 6px; }
  .admin-ds .ds-desktop-only-banner p  { font-size: 12.5px; margin: 0; max-width: 360px; }
}
