/* design.css — shared tokens + primitives for Carbontribe Engine.
 *
 * Single source of truth for the design system. Every page shell links
 * this file; per-page CSS should reference these tokens via var(...).
 *
 * Phase 0 decisions from tasks/plan.md §8:
 *   - error red = #dc2626 (kit value, industry standard)
 *   - page bg   = #fafafa (grey canvas, white cards sit on top)
 */

:root {
    /* --- color tokens --- */
    --primary: #7c3aed;          /* Carbontribe purple */
    --primary-dark: #6d28d9;
    --primary-fade: hsl(263 70% 50% / 0.08);
    --primary-ring: hsl(263 70% 50% / 0.14);
    --accent: #0d9488;           /* teal — success / minted */
    --accent-fade: hsl(173 80% 40% / 0.12);
    --accent-ring: hsl(173 80% 40% / 0.3);
    --fg: #0a0a0f;               /* near-black text */
    --bg: #fafafa;               /* page canvas */
    --bg-surface: #ffffff;       /* cards + panels */
    --bg-subtle: #f4f4f5;        /* table header, muted fills */
    --muted: #71717a;            /* secondary text */
    --border: #e4e4e7;
    --error: #dc2626;
    --error-fade: hsl(0 72% 51% / 0.1);
    --error-ring: hsl(0 72% 51% / 0.3);
    --warn: #b45309;
    --warn-fade: hsl(38 92% 50% / 0.1);
    --warn-ring: hsl(38 92% 50% / 0.3);
    --success: #0d9488;

    /* --- spacing scale (4px base, aligned with the kit's usage) --- */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 24px;
    --sp-6: 32px;

    /* --- radius scale --- */
    --r-sm: 4px;
    --r-md: 8px;

    /* --- typography --- */
    --font-head: 'Inter', system-ui, sans-serif;
    --font-body: 'IBM Plex Sans', system-ui, sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;

    /* --- elevation (kit's layered, subtle shadows) --- */
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04),
                   0 4px 8px rgba(0, 0, 0, 0.02),
                   0 8px 16px rgba(0, 0, 0, 0.01);
    --shadow-panel: 0 1px 2px rgba(0, 0, 0, 0.04),
                    0 4px 8px rgba(0, 0, 0, 0.02);
}

/* ---------- base ---------- */

.mono,
code,
kbd {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* Uppercase label helper — used for sidebar groupings + KPI card headers. */
.label-small {
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 500;
}

/* ---------- pills (status + filter) ---------- */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 9px;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-subtle);
    color: var(--muted);
    border: 1px solid var(--border);
}

.pill-accent {
    background: var(--accent-fade);
    color: var(--accent);
    border-color: var(--accent-ring);
}

.pill-muted {
    background: var(--bg-subtle);
    color: var(--muted);
    border-color: var(--border);
}

.pill-error {
    background: var(--error-fade);
    color: var(--error);
    border-color: var(--error-ring);
}

.pill-warn {
    background: var(--warn-fade);
    color: var(--warn);
    border-color: var(--warn-ring);
}

.pill-primary {
    background: var(--primary-fade);
    color: var(--primary);
    border-color: hsl(263 70% 50% / 0.3);
}

.pill-dot {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: currentColor;
    flex-shrink: 0;
}

/* ---------- card ---------- */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    box-shadow: var(--shadow-card);
    transition: box-shadow 200ms ease;
}

/* ---------- buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--r-sm);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: background 120ms ease, border-color 120ms ease;
    line-height: 1.2;
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover:not(:disabled):not([aria-disabled="true"]) {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--fg);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled):not([aria-disabled="true"]) {
    border-color: var(--muted);
}

.btn-ghost {
    background: transparent;
    color: var(--fg);
    border-color: transparent;
}

.btn-ghost:hover:not(:disabled):not([aria-disabled="true"]) {
    background: var(--bg-subtle);
}

/* ---------- topbar (shared chrome) ----------
 * Emitted by services/ui/app.py::_header_html. Kit-aligned: breadcrumb +
 * live-status pill + search shell + notifications + primary CTA + org
 * switcher + user menu. Sticky at the top of every page that uses the
 * shell; stays minimal on unauth pages.
 */

.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 28px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    font-family: var(--font-body);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-brand-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.topbar-search {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    width: 300px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--muted);
    cursor: text;
}

.topbar-search-icon {
    width: 15px; height: 15px;
    stroke: currentColor; fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.topbar-search-placeholder { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

@media (max-width: 900px) {
    .topbar { padding: 10px 16px; flex-wrap: wrap; gap: 8px; }
    .topbar-search { width: 100%; order: 10; margin-left: 0; }
}

/* T3: at <640px the search shell hides (the placeholder text "Search
 * assets, methodologies, logs…" is ⌘K-only on desktop anyway), the
 * topbar tightens, and the user menu lets the org switcher dropdown
 * stand alone — no `+ New Org` text overflow. */
@media (max-width: 640px) {
    .topbar { padding: 8px 12px; gap: 6px; }
    .topbar-search { display: none; }
    .topbar-user { gap: 6px; }
    .topbar-brand-link img { width: 36px !important; height: 36px !important; }
}

/* ---------- sidebar (shared chrome) ----------
 * Emitted by services/ui/app.py::_sidebar_html. Kit-aligned: 224px wide,
 * brand block at top, uppercase section labels, 4px-radius items with
 * subtle active-state bg, org footer pinned to bottom.
 */

.sidebar {
    width: 224px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    font-family: var(--font-body);
    position: sticky;
    top: 60px;
    align-self: flex-start;
    max-height: calc(100vh - 60px);
    overflow-y: auto;
}

.sidebar-section {
    padding: 14px 12px 4px;
}

.sidebar-label {
    padding: 6px 10px;
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: var(--r-sm);
    font-size: 13.5px;
    color: #242428;
    text-decoration: none;
    font-weight: 400;
    transition: background 120ms ease, color 120ms ease;
}

.sidebar-link:hover {
    background: var(--bg-subtle);
    color: var(--fg);
}

.sidebar-link.active {
    background: var(--primary-fade);
    color: var(--primary);
    font-weight: 500;
}

.sidebar-link svg {
    width: 15px; height: 15px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.sidebar-org {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-org-avatar {
    width: 28px; height: 28px;
    border-radius: var(--r-sm);
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}

.sidebar-org-name { font-size: 13px; font-weight: 500; color: var(--fg); }
.sidebar-org-role { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* Mobile drawer (T2). Sidebar becomes a fixed-position drawer that slides
 * in from the left when `body[data-sidebar-open]` is set. The toggle JS
 * lives in _layout.html; per-page templates don't need to know. */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(280px, 80vw);
        max-height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 220ms ease;
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.18);
    }
    body[data-sidebar-open] .sidebar { transform: translateX(0); }
    .sidebar-section { padding: 14px 12px 4px; }
}

/* Backdrop sits behind the open drawer (semi-transparent click target).
 * Hidden on desktop; shown only when the drawer is open on mobile.
 * The HTML element ships with `hidden` until the JS opens the drawer,
 * so it doesn't intercept taps before then. */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 15, 0.4);
    z-index: 999;
    display: none;
}
@media (max-width: 768px) {
    body[data-sidebar-open] .sidebar-backdrop:not([hidden]) { display: block; }
}

/* Hamburger button (T2). Hidden on desktop, shown only at <768px.
 * The display rules are scoped to a media query so they win regardless
 * of where this block sits relative to the .hidden-desktop helper. */
.topbar-hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    color: var(--fg);
    cursor: pointer;
    flex-shrink: 0;
}
.topbar-hamburger:hover { background: var(--bg-subtle); }
.topbar-hamburger:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
@media (max-width: 768px) {
    .topbar-hamburger { display: inline-flex; }
}

/* ---------- keyboard hint ---------- */

.kbd {
    display: inline-block;
    padding: 1px 6px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--muted);
    line-height: 1.4;
}

/* ---------- responsive utilities (Phase 0 / T1) ----------
 * Mobile-first helpers shared by every page. Per-page templates that
 * still redeclare their own `.container` should drop the redeclaration
 * and inherit these rules.
 */

/* `.container` is declared inline by most page shells today (max-width
 * 1400px, padding 2rem). On phones, 32px gutters consume 18% of a 360px
 * canvas — squeeze them. We don't redefine `.container` itself here to
 * avoid colliding with per-page declarations; this rule only narrows the
 * padding at small widths and wins via the @media specificity boost. */
@media (max-width: 640px) {
    .container { padding: 1rem !important; }
}

/* Tables: wrap any `<table>` in `<div class="table-scroll">` to keep
 * horizontal scroll inside the wrapper instead of the page body. */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.table-scroll > table { min-width: 100%; }

/* Visibility helpers — preferred over per-page media queries. They use
 * `display: revert` so the element snaps back to its native display
 * value (e.g. an `inline-flex` button stays inline-flex when shown). */
.hidden-desktop { display: none; }

@media (max-width: 768px) {
    .hidden-mobile { display: none !important; }
    .hidden-desktop { display: revert !important; }
}

/* Touch targets: buttons + links scale to 44px (iOS HIG / Material
 * recommendation) on coarse pointers — phones, tablets — without making
 * the desktop UI feel sparse. */
@media (pointer: coarse) {
    .btn,
    .sidebar-link,
    a.btn,
    button.btn-ghost {
        min-height: 44px;
    }
}

/* ---------- shared page hero ----------
 * Used by /orgs/<slug>/{settings,audit}, /settings/api-keys, /support,
 * /admin/support. Same visual language as the reports + NFT gallery
 * pages: breadcrumb · purple eyebrow · big H1 · lede · 4-cell mono
 * metric strip on a grid-bg backdrop with radial mask.
 *
 * Macro lives at partials/_page_hero.html. Page templates pass
 * {crumb, eyebrow, h1, lead, metrics:[{label, value, sub, accent?}]}.
 */

.ct-hero { position: relative; overflow: hidden; background: var(--bg-surface, #fff); border-bottom: 1px solid var(--border); }
.ct-hero-grid {
    position: absolute; inset: 0;
    background-image: linear-gradient(to right, #ebebed 1px, transparent 1px),
                      linear-gradient(to bottom, #ebebed 1px, transparent 1px);
    background-size: 60px 60px;
    mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 75%);
    -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 30%, transparent 75%);
    pointer-events: none;
}
.ct-hero-inner { position: relative; padding: 56px 0 40px; font-family: var(--font-body); }
.ct-hero-crumb { font-family: var(--font-mono); font-size: 12px; color: var(--muted); margin-bottom: 22px; display: flex; gap: 10px; align-items: center; letter-spacing: 0.04em; }
.ct-hero-crumb-now { color: var(--fg); }
.ct-hero-eyebrow { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--primary); font-weight: 500; margin-bottom: 16px; display: inline-flex; align-items: center; gap: 10px; }
.ct-hero-eyebrow-dot { width: 6px; height: 6px; border-radius: 999px; background: var(--primary); }
.ct-hero-h1 { font-family: var(--font-head); font-weight: 700; font-size: clamp(36px, 4.5vw, 52px); line-height: 1.05; letter-spacing: -0.025em; margin: 0; max-width: 880px; color: var(--fg); }
.ct-hero-lead { font-size: 17px; line-height: 1.5; color: #3f3f46; margin: 18px 0 0; max-width: 720px; }
.ct-hero-metric-row { margin-top: 32px; display: flex; border-top: 1px solid var(--border); padding-top: 20px; }
.ct-hero-metric-cell { flex: 1; padding-right: 20px; border-right: 1px solid var(--border); }
.ct-hero-metric-cell:last-child { border-right: 0; }
.ct-hero-metric-lbl { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.ct-hero-metric-val { font-family: var(--font-mono); font-size: 22px; font-weight: 500; color: var(--fg); font-variant-numeric: tabular-nums; }
.ct-hero-metric-val.is-positive { color: var(--accent); }
.ct-hero-metric-val.is-warn { color: #b45309; }
.ct-hero-metric-val.is-error { color: var(--error); }
.ct-hero-metric-val.is-primary { color: var(--primary); }
.ct-hero-metric-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

@media (max-width: 640px) {
    .ct-hero-inner { padding: 36px 0 28px; }
    .ct-hero-metric-row { flex-wrap: wrap; gap: 16px 0; }
    .ct-hero-metric-cell { flex: 1 1 50%; border-right: 0; padding-right: 0; }
}

/* Reusable filter toolbar (matches reports + NFTs gallery). Pages can
 * mix and match: pill rows, label chips, a search input, a meta count. */
.ct-toolbar { background: var(--bg-surface, #fff); border-bottom: 1px solid var(--border); padding: 14px 0; font-family: var(--font-body); }
.ct-toolbar-inner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ct-toolbar-group { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ct-toolbar-lbl { font-family: var(--font-mono); font-size: 10px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; padding: 0 4px 0 0; }
.ct-toolbar-pill { padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; color: #52525b; cursor: pointer; background: #fff; font-family: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.ct-toolbar-pill:hover { border-color: var(--primary); }
.ct-toolbar-pill.is-active { background: var(--fg); color: #fff; border-color: var(--fg); }
.ct-toolbar-pill-count { font-family: var(--font-mono); font-size: 11px; color: #a1a1aa; font-variant-numeric: tabular-nums; }
.ct-toolbar-pill.is-active .ct-toolbar-pill-count { color: rgba(255,255,255,0.6); }
.ct-toolbar-input { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 4px; padding: 8px 12px; background: #fff; font-size: 13px; }
.ct-toolbar-input input { border: 0; outline: 0; flex: 1; font-size: 13px; background: transparent; color: var(--fg); font-family: inherit; min-width: 140px; }
.ct-toolbar-spacer { flex: 1; }
.ct-toolbar-meta { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

/* Toolbar form controls — _layout.html ships a global `input, select
 * { width: 100% }` rule that's right for stacked-form pages but wrong
 * for the inline filter pill-row used here. Scope a width override
 * inside `.ct-toolbar` so toolbar selects/inputs sit inline. */
.ct-toolbar select, .ct-toolbar input { width: auto; }
