/* ============================================================
   CLEARPAY DASHBOARD — Dark Sidebar Layout
   Professional pharmacy dashboard inspired by Tabz/HealNow
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=DM+Sans:wght@500;700&display=swap');

:root {
  /* Sidebar & header */
  --sidebar-bg: #0f1117;
  --sidebar-width: 240px;
  --header-bg: #161822;
  --header-height: 60px;

  /* Brand */
  --brand: #4f6ef7;
  --brand-light: #6b85fa;
  --brand-glow: rgba(79, 110, 247, 0.15);

  /* Surfaces */
  --bg: #f4f5f9;
  --card-bg: #ffffff;
  --card-elevated: #ffffff;

  /* Text */
  --text: #1e2030;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;

  /* Accents */
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  /* Misc */
  --border: #e5e7eb;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --shadow: 0 4px 12px rgba(0,0,0,0.05), 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.06);
}

/* Dark theme */
[data-theme="dark"] {
  --sidebar-bg: #0b0d14;
  --header-bg: #0f1117;
  --bg: #13151d;
  --card-bg: #1a1d2b;
  --card-elevated: #212435;
  --text: #e5e7ef;
  --text-secondary: #9ca3b8;
  --text-muted: #6b7290;
  --border: rgba(255,255,255,0.08);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow: 0 4px 12px rgba(0,0,0,0.25);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.35);
}
[data-theme="dark"] .form-group input,
[data-theme="dark"] .form-group select,
[data-theme="dark"] .search-input,
[data-theme="dark"] .date-input,
[data-theme="dark"] .period-select { background: var(--card-elevated); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .main-header { background: var(--header-bg); border-color: var(--border); }
[data-theme="dark"] .data-table th { background: rgba(255,255,255,0.06); }
[data-theme="dark"] .data-table tr.clickable:hover td { background: rgba(79,110,247,0.06); }
[data-theme="dark"] .summary-tile { background: var(--card-elevated); }
[data-theme="dark"] .summary-tile:hover { background: rgba(255,255,255,0.08); }
[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,0.7); }
[data-theme="dark"] .error-message { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.2); }
[data-theme="dark"] .login-card { background: var(--card-bg); }

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: var(--sidebar-bg);
  background-image: radial-gradient(ellipse at 30% 20%, rgba(79,110,247,0.12) 0%, transparent 50%),
                    radial-gradient(ellipse at 70% 80%, rgba(79,110,247,0.08) 0%, transparent 50%);
}
.login-container { width: 100%; max-width: 420px; padding: 20px; }
.login-card {
  background: var(--card-bg); border-radius: 16px;
  padding: 48px 36px; box-shadow: var(--shadow-lg);
}
.login-header { text-align: center; margin-bottom: 36px; }
.login-header h1 { font-family: 'DM Sans', sans-serif; font-size: 32px; font-weight: 700; color: var(--brand); letter-spacing: -0.03em; }
.login-header p { color: var(--text-secondary); margin-top: 4px; font-size: 15px; }
.login-footer { text-align: center; color: rgba(255,255,255,0.3); margin-top: 24px; font-size: 13px; }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.form-group input, .form-group select {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
  background: #fff; color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow);
}
.error-message { color: var(--danger); font-size: 14px; margin-bottom: 12px; padding: 10px 14px; background: #fef2f2; border-radius: var(--radius-sm); border: 1px solid #fecaca; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; font-family: inherit;
  cursor: pointer; text-decoration: none;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--brand); color: white; box-shadow: 0 2px 8px rgba(79,110,247,0.25); }
.btn-primary:hover { background: var(--brand-light); box-shadow: 0 4px 12px rgba(79,110,247,0.3); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #0ea572; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #d97706; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text); background: rgba(0,0,0,0.04); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-full { width: 100%; padding: 12px; font-size: 15px; margin-top: 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width); background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
}
.sidebar-brand {
  padding: 20px 24px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-brand h1 {
  font-family: 'DM Sans', sans-serif; font-size: 22px; font-weight: 700;
  color: #fff; letter-spacing: -0.03em;
}
.sidebar-brand .brand-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 8px var(--brand); }

.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 8px;
  color: rgba(255,255,255,0.5); font-size: 14px; font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { color: rgba(255,255,255,0.8); background: rgba(255,255,255,0.05); }
.nav-item.active { color: #fff; background: rgba(79,110,247,0.15); }
.nav-item.active .nav-icon { color: var(--brand); }
.nav-icon { width: 20px; text-align: center; font-size: 16px; }
.nav-svg { width: 20px; height: 20px; flex-shrink: 0; stroke: currentColor; }
.nav-item.active .nav-svg { stroke: var(--brand); }
.nav-separator { height: 1px; background: rgba(255,255,255,0.06); margin: 12px 0; }

.sidebar-footer {
  padding: 16px 16px 20px; border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-user { flex: 1; min-width: 0; }
.sidebar-user-name { color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-pharmacy { color: rgba(255,255,255,0.4); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-avatar {
  width: 34px; height: 34px; border-radius: 8px; background: var(--brand);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; font-weight: 700; flex-shrink: 0;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main { flex: 1; margin-left: var(--sidebar-width); }

.main-header {
  height: var(--header-height); background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; position: sticky; top: 0; z-index: 50;
}
.main-header-title { font-family: 'DM Sans', sans-serif; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.main-header-right { display: flex; align-items: center; gap: 12px; }
.period-select {
  padding: 6px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; font-family: inherit; color: var(--text-secondary); background: #fff;
  cursor: pointer;
}

.main-content { padding: 24px 28px; }

/* ============================================================
   SECTIONS (page views)
   ============================================================ */
.section { display: none; }
.section.active { display: block; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }

.stat-card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow-sm);
  display: flex; align-items: flex-start; gap: 14px;
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.stat-icon.blue { background: rgba(79,110,247,0.1); color: var(--brand); }
.stat-icon.green { background: rgba(16,185,129,0.1); color: var(--success); }
.stat-icon.amber { background: rgba(245,158,11,0.1); color: var(--warning); }
.stat-icon.purple { background: rgba(139,92,246,0.1); color: #8b5cf6; }
.stat-info { flex: 1; }
.stat-label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.stat-value { font-family: 'DM Sans', sans-serif; font-size: 28px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.2; margin-top: 2px; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ============================================================
   CARDS & PANELS
   ============================================================ */
.card {
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); margin-bottom: 20px; overflow: hidden;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-header h3 { font-family: 'DM Sans', sans-serif; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.card-header .card-badge { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.card-body { padding: 20px; }
.card h3 { font-family: 'DM Sans', sans-serif; font-size: 16px; font-weight: 700; margin-bottom: 16px; letter-spacing: -0.01em; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ============================================================
   SUB-TABS (within a section)
   ============================================================ */
.sub-tabs { display: flex; gap: 0; margin-bottom: 20px; border-bottom: 1.5px solid var(--border); }
.sub-tab {
  padding: 10px 20px; border: none; background: none;
  font-size: 14px; font-weight: 500; font-family: inherit;
  color: var(--text-secondary); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1.5px;
  transition: color 0.15s, border-color 0.15s;
}
.sub-tab:hover { color: var(--text); }
.sub-tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ============================================================
   CHART PLACEHOLDER
   ============================================================ */
.chart-area { width: 100%; }
.chart-bars-wrap {
  display: flex; align-items: flex-end; gap: 6px;
  width: 100%; height: 220px; padding-top: 20px;
}
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.chart-bar-container { width: 100%; height: 180px; display: flex; align-items: flex-end; justify-content: center; }
.chart-bar {
  width: 100%; max-width: 36px; border-radius: 5px 5px 0 0;
  background: linear-gradient(180deg, var(--brand) 0%, rgba(79,110,247,0.6) 100%);
  min-height: 4px; position: relative;
  transition: opacity 0.15s, transform 0.15s;
  cursor: pointer;
}
.chart-bar:hover { opacity: 0.85; transform: scaleY(1.02); transform-origin: bottom; }
.chart-tooltip {
  position: absolute; top: -24px; left: 50%; transform: translateX(-50%);
  font-size: 11px; font-weight: 700; color: var(--brand);
  opacity: 0; transition: opacity 0.15s;
  white-space: nowrap;
}
.chart-bar:hover .chart-tooltip { opacity: 1; }
.chart-label {
  font-size: 10px; color: var(--text-muted); margin-top: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%; text-align: center;
}

/* ============================================================
   SUMMARY TILES (like Refill requests, Open carts, etc.)
   ============================================================ */
.summary-tiles { display: flex; flex-direction: column; gap: 10px; }
.summary-tile {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--bg); cursor: pointer;
  transition: background 0.15s;
}
.summary-tile:hover { background: #ecedf2; }
.tile-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.tile-icon.blue { background: rgba(79,110,247,0.1); color: var(--brand); }
.tile-icon.green { background: rgba(16,185,129,0.1); color: var(--success); }
.tile-icon.amber { background: rgba(245,158,11,0.1); color: var(--warning); }
.tile-icon.red { background: rgba(239,68,68,0.1); color: var(--danger); }
.tile-info { flex: 1; }
.tile-arrow { color: var(--text-muted); flex-shrink: 0; transition: transform 0.15s, color 0.15s; }
.summary-tile:hover .tile-arrow { color: var(--brand); transform: translateX(2px); }
.tile-label { font-size: 13px; color: var(--text-secondary); }
.tile-value { font-family: 'DM Sans', sans-serif; font-size: 22px; font-weight: 700; line-height: 1.2; }

/* ============================================================
   DATA TABLE
   ============================================================ */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  text-align: left; padding: 10px 14px; font-size: 12px; font-weight: 600;
  text-transform: capitalize; letter-spacing: 0.02em; color: var(--text-muted);
  border-bottom: 1.5px solid var(--border); background: #e8e9ef;
}
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover td { background: rgba(79,110,247,0.03); }

.view-all-link { font-size: 13px; font-weight: 500; color: var(--brand); text-decoration: none; cursor: pointer; }
.view-all-link:hover { color: var(--brand-light); }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
}
.badge-delivery { background: rgba(79,110,247,0.1); color: var(--brand); }
.badge-pickup { background: rgba(16,185,129,0.1); color: var(--success); }
.badge-paid { background: rgba(16,185,129,0.1); color: var(--success); }
.badge-unknown { background: var(--bg); color: var(--text-muted); }
.badge-status-green { background: rgba(16,185,129,0.1); color: var(--success); }
.badge-status-blue { background: rgba(79,110,247,0.1); color: var(--brand); }
.badge-status-amber { background: rgba(245,158,11,0.1); color: var(--warning); }
.badge-status-red { background: rgba(239,68,68,0.1); color: var(--danger); }
.badge-role-owner { background: rgba(139,92,246,0.1); color: #8b5cf6; }
.badge-role-admin { background: rgba(79,110,247,0.1); color: var(--brand); }
.badge-role-staff { background: var(--bg); color: var(--text-muted); }

/* ============================================================
   SEARCH BAR
   ============================================================ */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.search-input {
  flex: 1; min-width: 200px; padding: 9px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-glow); }
.date-input {
  padding: 9px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination { display: flex; align-items: center; gap: 12px; margin-top: 16px; justify-content: center; }
.page-info { font-size: 13px; color: var(--text-muted); }

/* ============================================================
   MODAL
   ============================================================ */
.modal { display: none; position: fixed; inset: 0; z-index: 1000; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,17,23,0.6); backdrop-filter: blur(4px); }
.modal-content {
  position: relative; z-index: 1; background: var(--card-bg);
  border-radius: 14px; width: 90%; max-width: 700px; max-height: 85vh;
  overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card-bg); z-index: 1; border-radius: 14px 14px 0 0; }
.modal-header h3 { font-family: 'DM Sans', sans-serif; font-size: 18px; font-weight: 700; }
.modal-body { padding: 24px; }
.modal-actions { margin-top: 20px; display: flex; gap: 8px; }

/* ============================================================
   DETAIL GRID
   ============================================================ */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; margin-bottom: 20px; font-size: 14px; }
.detail-grid strong { color: var(--text-secondary); font-weight: 500; }

.signature-img { max-width: 300px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 8px; }

/* ============================================================
   ADMIN FORMS
   ============================================================ */
.admin-form { max-width: 600px; }
.form-section { font-size: 16px; font-family: 'DM Sans', sans-serif; font-weight: 700; color: var(--text); margin: 28px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border); letter-spacing: -0.01em; }
.form-section:first-of-type { margin-top: 0; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-hint { font-size: 12px; color: var(--text-muted); }

.logo-upload-area { margin-bottom: 16px; }
.logo-controls { display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0; font-size: 13px; color: var(--text-secondary); }
.logo-controls label { display: flex; align-items: center; gap: 6px; }
.logo-controls input[type="range"] { width: 120px; }

/* ============================================================
   UTILITIES
   ============================================================ */
.text-muted { color: var(--text-muted); font-size: 14px; padding: 24px 0; text-align: center; }
.text-success { color: var(--success); font-weight: 600; }
.text-danger { color: var(--danger); font-weight: 600; }

/* ============================================================
   THEME TOGGLE
   ============================================================ */
.theme-toggle-wrap { display: flex; align-items: center; gap: 8px; padding: 8px 14px; }
.theme-toggle-label { font-size: 12px; color: rgba(255,255,255,0.4); }
.theme-toggle {
  position: relative; width: 44px; height: 24px;
  background: rgba(255,255,255,0.1); border-radius: 12px;
  cursor: pointer; border: none; padding: 0;
  transition: background 0.2s;
}
.theme-toggle.dark { background: var(--brand); }
.theme-toggle-knob {
  position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.theme-toggle.dark .theme-toggle-knob { transform: translateX(20px); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 22px; }
  .detail-grid { grid-template-columns: 1fr; }
  .search-bar { flex-direction: column; }
  .search-input { min-width: 100%; }
  .modal-content { width: 95%; }
  .main-content { padding: 16px; }
  .form-row { flex-direction: column; }
}
