/*
 * Squidb stylesheet — implements DESIGN-SYSTEM.md (4/8 spacing, 14px body, slate
 * palette + semantic tokens, bordered cards + subtle shadow, restraint).
 * Hand-written for now; production swaps in the Tailwind build using these tokens.
 */
:root {
    --bg: #f8fafc;            /* slate-50 */
    --surface: #ffffff;
    --surface-2: #f1f5f9;     /* slate-100 */
    --sidebar: #0b1220;       /* near-black slate */
    --sidebar-2: #111a2e;
    --sidebar-text: #cbd5e1;  /* slate-300 */
    --sidebar-muted: #64748b; /* slate-500 */
    --border: #e2e8f0;        /* slate-200 */
    --border-strong: #cbd5e1; /* slate-300 */
    --text: #0f172a;          /* slate-900 */
    --muted: #64748b;         /* slate-500 */
    --subtle: #94a3b8;        /* slate-400 */
    --primary: #2563eb;       /* blue-600 */
    --primary-hover: #1d4ed8; /* blue-700 */
    --primary-soft: #eff6ff;  /* blue-50 */
    --ok-bg: #ecfdf5; --ok-text: #047857; --ok-border: #a7f3d0;
    --err-bg: #fef2f2; --err-text: #b91c1c; --err-border: #fecaca;

    --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-xl: 16px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow: 0 1px 3px rgba(16, 24, 40, .1), 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .08);
    --ease: cubic-bezier(.4, 0, .2, 1);
    --font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
    --mono: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
[x-cloak] { display: none !important; }
a { color: inherit; }
.icon { width: 20px; height: 20px; flex: 0 0 auto; }
.muted { color: var(--muted); }
code { font: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- brand ---------- */
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
    background: linear-gradient(135deg, #3b82f6, #2563eb); color: #fff; font-weight: 700; font-size: 16px; }
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -.01em; }

/* ---------- app shell ---------- */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }
/* Sidebar is pinned to the viewport so it never scrolls with the page; the page
   itself uses the natural window scroll. */
.sidebar { width: 248px; background: var(--sidebar); color: var(--sidebar-text);
    display: flex; flex-direction: column; padding: 16px 12px;
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 30; overflow-y: auto; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; color: #fff; padding: 6px 8px 16px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; }
.nav-group { margin-top: 6px; border-top: 1px solid rgba(255, 255, 255, .06); padding-top: 6px; }
.nav-section-btn { display: flex; align-items: center; justify-content: space-between; width: 100%;
    background: none; border: none; cursor: pointer; padding: 9px 10px; border-radius: 8px;
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--sidebar-muted); font-family: inherit; }
.nav-section-btn:hover { background: rgba(255, 255, 255, .06); color: var(--sidebar-text); }
.nav-chev { width: 14px; height: 14px; transition: transform .18s var(--ease); }
.nav-chev.is-open { transform: rotate(180deg); }
.nav-sub { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.nav-link { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px;
    color: var(--sidebar-text); text-decoration: none; font-weight: 500; transition: background .15s var(--ease); }
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.is-active { background: rgba(37, 99, 235, .22); color: #fff; }
.nav-icon { width: 19px; height: 19px; opacity: .9; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 10px 8px; margin-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, .08); }
a.sidebar-user { text-decoration: none; border-radius: 8px; transition: background .15s; }
a.sidebar-user:hover { background: rgba(255, 255, 255, .05); }
.sidebar-user-meta { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user-name { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { color: var(--sidebar-muted); font-size: 12px; }

.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
    background: var(--primary); color: #fff; font-size: 12px; font-weight: 600; flex: 0 0 auto; }

.main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; margin-left: 248px; }
.topbar { height: 60px; display: flex; align-items: center; gap: 14px; padding: 0 24px;
    background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-title { font-size: 16px; font-weight: 650; margin: 0; flex: 1 1 auto; letter-spacing: -.01em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px;
    border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-toggle { display: none; }

.lang { display: inline-flex; gap: 2px; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.lang-link { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
    text-decoration: none; padding: 4px 8px; border-radius: 5px; font-weight: 600; }
.lang-link.is-active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

.user-menu { position: relative; }
.avatar-btn { background: none; border: none; padding: 0; cursor: pointer; }
.menu { position: absolute; right: 0; top: 46px; min-width: 200px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-md); padding: 6px; }
.menu-head { padding: 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-name { font-weight: 600; font-size: 13px; }
.menu-item { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border-radius: 7px;
    background: none; border: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); }
.menu-icon { width: 17px; height: 17px; color: var(--muted); }

.content { padding: 28px 24px 40px; max-width: 1180px; width: 100%; }

/* ---------- page heading ---------- */
.page-head { margin-bottom: 22px; }
.page-head.with-action { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
.page-title { font-size: 22px; font-weight: 680; letter-spacing: -.02em; margin: 0; }
.page-sub { color: var(--muted); margin: 4px 0 0; }

/* utilities */
.narrow { max-width: 560px; }
.text-right { text-align: right; }
.search-bar { margin-bottom: 16px; }
.search-bar .input { max-width: 280px; }
.confirm-input { max-width: 280px; }
.mt-2 { margin-top: 12px; }

/* ---------- stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat { display: flex; gap: 14px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-xl); padding: 18px; box-shadow: var(--shadow-sm); }
.stat-icon { display: inline-grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; flex: 0 0 auto; }
.stat-icon .icon { width: 22px; height: 22px; }
.tone-blue { background: #eff6ff; color: #2563eb; }
.tone-violet { background: #f5f3ff; color: #7c3aed; }
.tone-emerald { background: #ecfdf5; color: #059669; }
.tone-amber { background: #fffbeb; color: #d97706; }
.stat-body { display: flex; flex-direction: column; min-width: 0; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin: 2px 0; overflow-wrap: anywhere; }
.stat-hint { font-size: 12px; color: var(--subtle); }

/* ---------- cards ---------- */
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-sm); }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-title { margin: 0; font-size: 15px; font-weight: 650; }
.card-body { padding: 20px; }

.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.checklist li { display: flex; align-items: center; gap: 10px; color: var(--text); }
.check-icon { width: 18px; height: 18px; color: #059669; flex: 0 0 auto; }

.kv { margin: 0; }
.kv > div { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.kv > div:first-child { border-top: none; }
.kv dt { color: var(--muted); margin: 0; }
.kv dd { margin: 0; font-weight: 500; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.badge-ok { background: var(--ok-bg); color: var(--ok-text); }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-weight: 600; font-size: 13px; }
.help { font-size: 12px; color: var(--subtle); }
.input { font: var(--font); height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--r-md);
    background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s; }
.input::placeholder { color: var(--subtle); }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.input:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
textarea.textarea { height: auto; min-height: 120px; padding: 10px 12px; line-height: 1.5; resize: vertical; font: var(--font); }

/* filter pills (chips on top of a list) */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 99px; font-size: 13px; font-weight: 500;
    background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none; transition: background .15s, border-color .15s; }
.pill:hover { border-color: var(--border-strong); }
.pill.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* modules admin */
.module-head { display: flex; align-items: center; gap: 14px; }
.module-icon { display: inline-flex; width: 38px; height: 38px; border-radius: 9px; align-items: center; justify-content: center;
    background: var(--surface-2); color: var(--muted); flex: none; }
.module-meta { flex: 1 1 auto; min-width: 0; }
.module-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.module-sub { font-size: 13px; margin-top: 2px; }
.module-actions { flex: none; }
.module-danger { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); display: flex; flex-direction: column; gap: 8px; }
.module-danger .input { max-width: 220px; }

.select-wrap { display: inline-flex; position: relative; }
.select { appearance: none; -webkit-appearance: none; font: var(--font); height: 40px; padding: 0 38px 0 12px;
    border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface); color: var(--text); cursor: pointer; min-width: 220px; }
.select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.select-wrap::after { content: ""; position: absolute; right: 15px; top: 50%; width: 7px; height: 7px;
    border-right: 2px solid var(--subtle); border-bottom: 2px solid var(--subtle); transform: translateY(-70%) rotate(45deg); pointer-events: none; }
.select-block { display: block; }
.select-block .select { width: 100%; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mail-test { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.mail-test .input { max-width: 300px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

/* translation manager */
.tr-toolbar { margin-bottom: 14px; }
.coverage-meta { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.coverage-track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.coverage-fill { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s var(--ease); }
.cov-0 { width: 0; } .cov-10 { width: 10%; } .cov-20 { width: 20%; } .cov-30 { width: 30%; }
.cov-40 { width: 40%; } .cov-50 { width: 50%; } .cov-60 { width: 60%; } .cov-70 { width: 70%; }
.cov-80 { width: 80%; } .cov-90 { width: 90%; } .cov-100 { width: 100%; }
.tr-table td { vertical-align: middle; }
.tr-key { white-space: nowrap; } .tr-key code { font-size: 12px; }
.tr-source { max-width: 280px; }
.tr-save { position: sticky; bottom: 0; padding: 14px 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: var(--font); font-weight: 600;
    height: 40px; padding: 0 18px; border-radius: var(--r-md); border: 1px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, box-shadow .15s; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.notice { display: flex; align-items: center; gap: 9px; padding: 11px 14px; border-radius: var(--r-md); margin-bottom: 16px; font-size: 13px; border: 1px solid transparent; }
.notice.ok { background: var(--ok-bg); color: var(--ok-text); border-color: var(--ok-border); }
.notice.err { background: var(--err-bg); color: var(--err-text); border-color: var(--err-border); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); }
.table tbody tr:hover { background: var(--surface-2); }
.cell-link { color: var(--text); font-weight: 600; text-decoration: none; }
.cell-link:hover { color: var(--primary); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.badge-violet { background: #f5f3ff; color: #7c3aed; }
.badge-muted { background: var(--surface-2); color: var(--muted); }
.badge-blue { background: #eff6ff; color: #2563eb; }
.badge-danger { background: #fef2f2; color: #dc2626; }

/* api docs */
.codeblock { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
    padding: 12px 14px; font-size: 12.5px; overflow-x: auto; margin: 10px 0; white-space: pre; color: var(--text); }
.endpoint { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.endpoint-path { font-size: 13px; font-weight: 600; }
.endpoint-body { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.field-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.field-list li { display: flex; align-items: center; gap: 8px; font-size: 13px; }

.pagination { display: flex; gap: 4px; margin-top: 16px; }
.page-link { display: inline-grid; place-items: center; min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid var(--border); border-radius: var(--r-sm); color: var(--muted); text-decoration: none; font-size: 13px; }
.page-link:hover { background: var(--surface-2); }
.page-link.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- checkboxes / overrides ---------- */
.checks { display: flex; flex-direction: column; gap: 9px; }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

.ov-group { margin-bottom: 16px; }
.ov-group-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 8px; }
.ov-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--border); }
.ov-name { font-size: 13px; }
.ov-pills { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; flex: 0 0 auto; }
.ov-pill { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 5px; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; }
.ov-pill input { position: absolute; opacity: 0; width: 0; height: 0; }
/* reactive without JS via :has() — also covers the server-rendered checked state */
.ov-pill.ov-none:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.ov-pill.ov-grant:has(input:checked) { background: #16a34a; color: #fff; }
.ov-pill.ov-deny:has(input:checked) { background: #dc2626; color: #fff; }

.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.danger-zone { border-color: #fecaca; margin-top: 16px; }
.danger-zone .card-head { border-color: #fecaca; }

/* ---------- auth (login) ---------- */
.auth { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh;
    background: radial-gradient(1200px 500px at 50% -10%, #e0e7ff 0%, var(--bg) 55%); padding: 24px; }
.auth-wrap { width: 100%; max-width: 400px; }
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 18px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-md); padding: 28px; }
.auth-title { font-size: 20px; font-weight: 680; margin: 0; letter-spacing: -.02em; }
.auth-sub { color: var(--muted); margin: 6px 0 20px; }
.auth-alt { margin: 16px 0 0; text-align: center; font-size: 13px; }
.auth-demo { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.auth-demo-title { font-size: 12px; color: var(--muted); font-weight: 600; }
.auth-demo ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.auth-demo li { font-size: 12px; color: var(--subtle); }

/* ---------- responsive ---------- */
@media (max-width: 880px) {
    .cols { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .nav-toggle { display: inline-grid; }
    .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s var(--ease); }
    .sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-md); }
    .main { margin-left: 0; }
    .content { padding: 20px 16px 32px; }
}
html[dir="rtl"] .sidebar { transform: none; }

/* ── CRM activities timeline ───────────────────────────────────────────── */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: 0; }
.timeline-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timeline-time { margin-left: auto; font-size: 12px; }
.timeline-meta { font-size: 13px; margin: 2px 0 0; }
.timeline-body { margin: 6px 0 0; white-space: pre-wrap; }
.timeline-actions { margin-top: 6px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.cell-actions { text-align: right; white-space: nowrap; }

/* ── Customer-360 profile ──────────────────────────────────────────────── */
.profile-grid { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .profile-grid { grid-template-columns: 1fr; } }
.profile-side { display: flex; flex-direction: column; gap: 16px; }
.profile-main { min-width: 0; }
.detail-list { display: grid; grid-template-columns: 1fr; gap: 2px 0; margin: 0 0 14px; }
.detail-list dt { font-size: 12px; color: var(--muted); margin-top: 8px; }
.detail-list dd { margin: 0; font-size: 14px; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.plain-list li:last-child { border-bottom: 0; }

/* Avatars — monogram circles (reuses .avatar; adds size + colour tones) */
.avatar-lg { width: 48px; height: 48px; font-size: 17px; }
.avatar-sm { width: 26px; height: 26px; font-size: 11px; }
.avatar--blue { background: var(--primary); }
.avatar--emerald { background: #059669; }
.avatar--violet { background: #7c3aed; }
.avatar--amber { background: #d97706; }
.avatar--rose { background: #e11d48; }
.avatar--slate { background: #475569; }
.avatar--cyan { background: #0891b2; }
.avatar--fuchsia { background: #c026d3; }
.profile-head { display: flex; align-items: center; gap: 14px; }
.cell-user { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; }

/* ── Custom fields ─────────────────────────────────────────────────────── */
.field-error { color: var(--err-text); font-size: 12px; margin-top: 4px; }

/* ── Tenants admin (utilities) ─────────────────────────────────────────── */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { margin-top: 18px; }
.inline-form { display: inline-block; margin: 0; }
.ta-right { text-align: right; }
.dns-table code { font-size: 12.5px; }
@media (max-width: 720px) { .field-row { grid-template-columns: 1fr; } }
