/* ============================================================
   BabelWrap Dashboard Styles
   ============================================================ */

/* ---- Reset & tokens ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f8f9fb; --surface: #ffffff; --border: #e2e5ea;
    --text: #1a1d23; --text-muted: #6b7280; --text-dim: #9ca3af;
    --primary: #6366f1; --primary-hover: #4f46e5; --primary-light: #eef2ff;
    --success: #059669; --success-bg: #ecfdf5; --success-border: #a7f3d0;
    --danger: #dc2626; --danger-bg: #fef2f2; --danger-border: #fecaca;
    --warning: #f59e0b; --warning-bg: #fffbeb; --warning-border: #fde68a;
    --radius: 8px; --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.03);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;
    --gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    --transition-fast: 150ms ease;
    --focus-ring: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; font-size: 15px; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* ---- Focus ---- */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ---- Layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 250px; background: var(--surface); border-right: 1px solid var(--border); padding: 1.25rem 0; display: flex; flex-direction: column; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar-brand { padding: 0 1.25rem 1.25rem; font-size: 1.1rem; font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 0.5rem; }
.sidebar-brand svg { width: 24px; height: 24px; }

.sidebar-nav { flex: 1; }
.sidebar-section { padding: 1rem 0 0.25rem; }
.sidebar-section:first-child { padding-top: 0; }
.sidebar-label { padding: 0 1.25rem; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 0.25rem; }
.sidebar-nav a { display: flex; align-items: center; gap: 0.7rem; padding: 0.5rem 1.25rem; color: var(--text-muted); font-size: 0.88rem; font-weight: 500; border-left: 3px solid transparent; transition: all var(--transition-fast); }
.sidebar-nav a:hover { color: var(--text); background: var(--bg); text-decoration: none; }
.sidebar-nav a.active { color: var(--primary); background: var(--primary-light); border-left-color: var(--primary); }
.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.7; }
.sidebar-nav a.active svg { opacity: 1; }

.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); }
.sidebar-footer .email { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; padding: 2rem 2.5rem; max-width: 1100px; min-width: 0; }
.main h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 1.5rem; }
.main h2 { font-size: 1.15rem; font-weight: 600; margin: 2rem 0 1rem; }
.main h3 { font-size: 1rem; font-weight: 600; margin: 1.5rem 0 0.75rem; }

/* ---- Cards ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem 1.5rem; box-shadow: var(--shadow); }
.card-header { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 0.75rem; }
.card-value { font-size: 1.6rem; font-weight: 700; }
.card-sub { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.25rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }

/* ---- Stat card with link ---- */
.stat-card { position: relative; transition: box-shadow var(--transition-fast); }
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-card-link { position: absolute; inset: 0; z-index: 1; }

/* ---- Badge ---- */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.badge-free { background: #f3f4f6; color: #6b7280; }
.badge-usage { background: #dbeafe; color: #1d4ed8; }
.badge-active { background: var(--success-bg); color: var(--success); }
.badge-revoked, .badge-closed, .badge-expired, .badge-failed { background: var(--danger-bg); color: var(--danger); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-error { background: var(--danger-bg); color: var(--danger); }
.badge-exploring, .badge-modeling, .badge-pending_payment, .badge-paid { background: var(--warning-bg); color: #92400e; }
.badge-ready, .badge-completed { background: var(--success-bg); color: var(--success); }
.badge-stale { background: #f3f4f6; color: #6b7280; }
.badge-refunded { background: #f3f4f6; color: #6b7280; }

/* ---- Forms ---- */
label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 0.35rem; color: var(--text); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="url"], select, textarea {
    width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 0.95rem; font-family: var(--font); background: var(--surface); color: var(--text);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: var(--focus-ring); }
input::placeholder { color: var(--text-dim); }
.form-group { margin-bottom: 1rem; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0.6rem 1.25rem; border: none; border-radius: var(--radius); font-size: 0.9rem; font-weight: 500; font-family: var(--font); cursor: pointer; transition: all var(--transition-fast); text-decoration: none; line-height: 1.4; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); color: white; text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); text-decoration: none; }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.btn-danger:hover { background: #fee2e2; text-decoration: none; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); padding: 0.6rem 0.75rem; border-bottom: 2px solid var(--border); }
td { padding: 0.75rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
code { font-family: var(--mono); font-size: 0.85em; background: var(--bg); padding: 0.15rem 0.4rem; border-radius: 4px; }
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
tr.clickable-row { cursor: pointer; transition: background var(--transition-fast); }
tr.clickable-row:hover { background: var(--bg); }

/* ---- Progress bar ---- */
.progress-bar { width: 100%; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 0.5rem; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.3s; }
.progress-fill-warning { background: var(--warning); }
.progress-fill-danger { background: var(--danger); }

/* ---- Alerts ---- */
.alert { padding: 1rem 1.25rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-success { background: var(--success-bg); border: 1px solid var(--success-border); color: #065f46; }
.alert-error { background: var(--danger-bg); border: 1px solid var(--danger-border); color: #991b1b; }
.alert-warning { background: var(--warning-bg); border: 1px solid var(--warning-border); color: #92400e; }
.alert-key { background: #f0fdf4; border: 1px solid #86efac; padding: 1.25rem; }
.alert-key .key-value { font-family: var(--mono); font-size: 0.85rem; background: white; border: 1px solid #d1d5db; padding: 0.75rem; border-radius: var(--radius); margin: 0.75rem 0; word-break: break-all; line-height: 1.5; }

/* ---- Inline form row ---- */
.form-row { display: flex; gap: 0.75rem; align-items: flex-end; }
.form-row .form-group { flex: 1; margin-bottom: 0; }
.form-row .btn { flex-shrink: 0; height: 42px; }

/* ---- Auth page centering ---- */
.auth-container { max-width: 400px; margin: 3rem auto; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 2rem; box-shadow: var(--shadow-md); }
.auth-card h1 { text-align: center; margin-bottom: 1.5rem; font-size: 1.3rem; }
.auth-footer { text-align: center; margin-top: 1.25rem; font-size: 0.9rem; color: var(--text-muted); }
.auth-brand { text-align: center; margin-bottom: 2rem; font-size: 1.3rem; font-weight: 700; color: var(--primary); }

/* ---- Code block ---- */
.code-block { background: #1e1e2e; color: #cdd6f4; padding: 1rem 1.25rem; border-radius: var(--radius); font-family: var(--mono); font-size: 0.82rem; line-height: 1.7; overflow-x: auto; white-space: pre; }

/* ---- Empty state ---- */
.empty { text-align: center; padding: 2.5rem 1.5rem; color: var(--text-muted); }
.empty svg { width: 48px; height: 48px; margin: 0 auto 1rem; opacity: 0.4; }
.empty p { margin-bottom: 0.5rem; }
.empty .btn { margin-top: 1rem; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; }
.tab { padding: 0.6rem 1.25rem; font-size: 0.9rem; font-weight: 500; color: var(--text-muted); background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -2px; cursor: pointer; font-family: var(--font); transition: all var(--transition-fast); text-decoration: none; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---- Filter bar ---- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; margin-bottom: 1.5rem; padding: 1rem 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.filter-bar .form-group { margin-bottom: 0; min-width: 140px; }
.filter-bar label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); }
.filter-bar input, .filter-bar select { font-size: 0.85rem; padding: 0.5rem 0.6rem; }

/* ---- Pagination ---- */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 1rem 0; font-size: 0.85rem; color: var(--text-muted); }
.pagination-controls { display: flex; gap: 0.5rem; }
.pagination-controls a, .pagination-controls span { display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 36px; padding: 0 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.85rem; font-weight: 500; color: var(--text-muted); text-decoration: none; transition: all var(--transition-fast); }
.pagination-controls a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.pagination-controls .active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination-controls .disabled { opacity: 0.4; pointer-events: none; }

/* ---- Charts ---- */
.chart-container { position: relative; height: 280px; }
.chart-container-sm { height: 200px; }
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }

/* ---- Welcome banner ---- */
.welcome-banner { background: var(--gradient); color: white; border-radius: var(--radius-lg); padding: 2rem; margin-bottom: 1.5rem; }
.welcome-banner h2 { color: white; margin: 0 0 0.75rem; font-size: 1.2rem; }
.welcome-banner p { opacity: 0.9; margin-bottom: 1rem; font-size: 0.95rem; }
.welcome-steps { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.welcome-step { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; font-weight: 500; }
.welcome-step a { color: white; text-decoration: underline; text-underline-offset: 2px; }
.welcome-step .step-num { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: rgba(255,255,255,0.25); font-size: 0.75rem; font-weight: 700; }

/* ---- Quick actions ---- */
.quick-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.quick-actions .btn { font-size: 0.85rem; }

/* ---- Activity feed ---- */
.activity-feed td { font-size: 0.85rem; padding: 0.5rem 0.75rem; }
.activity-feed .type-icon { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 500; }

/* ---- Danger zone ---- */
.danger-zone { border: 1px solid var(--danger-border); border-radius: var(--radius-lg); padding: 1.25rem 1.5rem; background: var(--danger-bg); }
.danger-zone h3 { color: var(--danger); margin-top: 0; }

/* ---- Pills ---- */
.pill { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.25rem 0.65rem; background: var(--primary-light); color: var(--primary); border-radius: 999px; font-size: 0.8rem; font-weight: 500; margin: 0.15rem; }
.pill button { background: none; border: none; color: inherit; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0; opacity: 0.6; }
.pill button:hover { opacity: 1; }

/* ---- Status dot ---- */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.4rem; }
.status-dot-active { background: var(--success); }
.status-dot-closed, .status-dot-expired { background: var(--text-dim); }

/* ---- JSON viewer ---- */
.json-block { background: #1e1e2e; color: #cdd6f4; padding: 1rem 1.25rem; border-radius: var(--radius); font-family: var(--mono); font-size: 0.8rem; line-height: 1.6; overflow-x: auto; white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow-y: auto; }

/* ---- Section divider ---- */
.section-divider { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* ---- HTMX loading indicators ---- */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Hamburger menu ---- */
.sidebar-toggle { display: none; position: fixed; top: 1rem; left: 1rem; z-index: 110; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem; cursor: pointer; box-shadow: var(--shadow); }
.sidebar-toggle svg { width: 20px; height: 20px; color: var(--text); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 99; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: -260px; z-index: 100; transition: left 0.25s ease; height: 100vh; box-shadow: var(--shadow-lg); }
    .sidebar.open { left: 0; }
    .sidebar-toggle { display: block; }
    .sidebar-overlay.open { display: block; }
    .main { padding: 1.25rem; padding-top: 3.5rem; }
    .card-grid { grid-template-columns: 1fr 1fr; }
    .chart-row { grid-template-columns: 1fr; }
    .filter-bar { flex-direction: column; }
    .filter-bar .form-group { width: 100%; }
    .form-row { flex-direction: column; }
    .form-row .btn { width: 100%; }
    .welcome-steps { flex-direction: column; gap: 0.75rem; }
    .quick-actions { flex-direction: column; }
    .quick-actions .btn { width: 100%; }
}
@media (max-width: 480px) {
    .card-grid { grid-template-columns: 1fr; }
    .pagination { flex-direction: column; gap: 0.75rem; align-items: stretch; text-align: center; }
}
