:root {
    --bg: #0f172a;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger: #dc2626;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text); background: #f1f5f9; font-size: 15px; line-height: 1.5;
}

/* ── Portal shell ───────────────────────────────────────── */
.navbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 28px; background: var(--bg); color: #fff;
}
.navbar-brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; }
.navbar-brand span { color: #93c5fd; font-weight: 600; }
.navbar-nav { display: flex; align-items: center; gap: 18px; }
.navbar-nav a { color: #cbd5e1; text-decoration: none; font-size: 14px; }
.navbar-nav a:hover { color: #fff; }
.portal-main { padding: 32px 20px; }
.container { max-width: 720px; margin: 0 auto; }
.page-title { font-size: 22px; margin: 0 0 20px; }

/* ── Dashboard shell (sidebar) ──────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
    width: 240px; flex: 0 0 240px; background: var(--bg); color: #cbd5e1;
    display: flex; flex-direction: column; padding: 20px 0;
}
.app-brand { display: block; font-weight: 700; font-size: 18px; color: #fff; padding: 6px 22px 20px; text-decoration: none; }
.app-brand:hover { opacity: .85; }
.app-brand span { color: #93c5fd; font-weight: 600; }
.app-nav { display: flex; flex-direction: column; gap: 2px; }
.app-nav-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid #1e293b; }
.app-sidebar .nav-link {
    display: block; padding: 11px 22px; color: #cbd5e1; text-decoration: none;
    font-size: 14px; border-left: 3px solid transparent;
}
.app-sidebar .nav-link:hover { background: #1e293b; color: #fff; }
.app-sidebar .nav-link.active { background: #1e293b; color: #fff; border-left-color: var(--primary); }
.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.app-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.app-topbar h1 { font-size: 18px; margin: 0; }
.app-user { color: var(--muted); font-size: 14px; display: inline-flex; align-items: center; gap: 10px; }
.paystrip { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.paystrip form { margin: 0; }
/* Content fills the available width so widgets spread across the page
   instead of leaving a large empty right margin. A high cap keeps line
   lengths sane on ultra-wide monitors. */
.app-content { padding: 28px; max-width: 1600px; width: 100%; }
/* Keep long-form text pages (forms, prose) readable by constraining just
   their inner content, not the dashboard pages. */
.app-content--narrow { max-width: 820px; }

/* ── Dashboard grids (stat tiles + tiled cards) ─────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin: 0 0 20px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; margin-bottom: 20px; }
.card-grid > .card { margin-bottom: 0; }
.span-all { grid-column: 1 / -1; }
.stat-card .stat-label { color: var(--muted); font-size: 13px; }
.stat-card .stat-value { font-size: 22px; font-weight: 700; margin-top: 6px; }

/* ── Tables ─────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.table td { padding: 9px 8px; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
.table tr:last-child td { border-bottom: none; }
.table code { font-size: 13px; }
.table-wrap { overflow-x: auto; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 16px; }
.muted { color: var(--muted); }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-block; border: 1px solid transparent; border-radius: 8px;
    padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
    text-decoration: none; text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); }
.navbar .btn-ghost { color: #cbd5e1; border-color: #334155; }
.navbar .btn-ghost:hover { color: #fff; border-color: #475569; }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ── Forms ──────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: #334155; }
.field input, .field select, .field textarea {
    width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 15px; color: var(--text); font-family: inherit; line-height: 1.3;
}
.field select { height: 46px; }
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-row { display: flex; gap: 16px; }
.form-row .field { flex: 1; min-width: 0; }
.req { color: var(--danger); font-style: normal; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.field-hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.btn-lg { padding: 13px 18px; font-size: 15px; margin-top: 6px; }

/* ── Password visibility toggle (eye button) ────────────── */
.pw-wrap { position: relative; display: block; }
.field .pw-wrap input { padding-right: 44px; }
.pw-toggle {
    position: absolute; top: 0; right: 0; height: 100%; width: 42px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; padding: 0; margin: 0;
    color: var(--muted); cursor: pointer;
}
.pw-toggle:hover { color: var(--text); }
.pw-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; border-radius: 8px; }
.pw-toggle svg { width: 18px; height: 18px; display: block; }

/* grouped form sections (registration) */
.form-section-label {
    font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); font-weight: 700; margin: 22px 0 12px; padding-bottom: 7px;
    border-bottom: 1px solid var(--border);
}

/* ── Alerts ─────────────────────────────────────────────── */
.alert { padding: 11px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 18px; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.alert-warn { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.verify-banner { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.verify-banner form { margin: 0; }
.badge { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 600; }
.badge-ok { background: #dcfce7; color: #15803d; }
.badge-warn { background: #fef3c7; color: #b45309; }

/* ── Detail / key box ───────────────────────────────────── */
.detail { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; font-size: 14px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.tag { display: inline-block; background: #eef2ff; color: #4338ca; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.keybox { display: flex; align-items: center; gap: 10px; background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 6px 0 14px; }
.keybox code { font-size: 14px; word-break: break-all; flex: 1; }

/* ── Auth (login / register) cards ──────────────────────── */
.login-body {
    display: flex; align-items: center; justify-content: center; min-height: 100vh;
    background: linear-gradient(135deg, #0f172a, #1e293b); padding: 24px;
}
.login-card {
    background: var(--surface); width: 420px; max-width: 100%; padding: 32px;
    border-radius: 14px; box-shadow: 0 20px 40px rgba(0,0,0,.3);
}
.login-card.narrow { width: 380px; }
.login-card.wide { width: 600px; padding: 32px 36px; }
.login-logo {
    width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), #1e3a8a); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px; font-weight: 800; box-shadow: 0 8px 20px rgba(37,99,235,.35);
}
.login-brand { font-size: 22px; font-weight: 700; text-align: center; margin: 0 0 4px; }
.login-sub { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 24px; }

/* Remember-me row + checkbox */
.remember-row { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 20px; }
.remember-row a { font-size: 14px; color: var(--primary); font-weight: 600; text-decoration: none; }
.remember-row a:hover { text-decoration: underline; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); cursor: pointer; user-select: none; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }
.auth-alt { text-align: center; margin-top: 18px; font-size: 14px; color: var(--muted); }
.auth-alt a { color: var(--primary); font-weight: 600; text-decoration: none; }

/* ── Profile header + avatar ────────────────────────────── */
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.avatar { display: inline-block; border-radius: 50%; object-fit: cover; background: #e2e8f0; }
.avatar-lg { width: 56px; height: 56px; }

/* ── Profile two-column layout (main + status sidebar) ──── */
.profile-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.profile-main { min-width: 0; }
.profile-side { min-width: 0; }
.profile-layout .card { margin-bottom: 0; }

/* ── Integration status widget ──────────────────────────── */
.integration-card { border-left: 4px solid var(--border); }
.integration-card h2 { margin: 10px 0 4px; }
.integration-card .btn { margin-top: 12px; }
.integration-connected { border-left-color: #15803d; }
.integration-pending { border-left-color: #b45309; }
.integration-inactive { border-left-color: #b45309; }

/* ── API token display ──────────────────────────────────── */
.token-display { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0 4px; }
.token-val {
    flex: 1 1 auto; min-width: 0; word-break: break-all;
    background: #f1f5f9; border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 12px; font-family: "Courier New", monospace; font-size: 14px;
}

@media (max-width: 900px) {
    /* Stack the profile + status widget; show the widget first (it's the CTA). */
    .profile-layout { grid-template-columns: 1fr; }
    .profile-side { order: -1; }
}
@media (max-width: 600px) {
    .form-row { flex-direction: column; gap: 0; }
    .detail { grid-template-columns: 1fr; gap: 2px 0; }
    .detail dt { margin-top: 8px; }
}
@media (max-width: 760px) {
    .app-shell { flex-direction: column; }
    .app-sidebar { width: 100%; flex-basis: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; }
    .app-brand { padding: 6px 12px; }
    .app-nav { flex-direction: row; flex-wrap: wrap; gap: 0; }
    .app-nav-bottom { margin: 0; border: none; padding: 0; }
    .app-sidebar .nav-link { padding: 8px 12px; border-left: none; border-bottom: 3px solid transparent; }
    .app-sidebar .nav-link.active { border-left: none; border-bottom-color: var(--primary); }
    .app-content { padding: 18px; }
}
