/*
 * BCOS master stylesheet
 *
 * Layout is mobile-first:
 *   Mobile   < 768px   (base rules)
 *   Tablet   768px – 1199px
 *   Desktop  >= 1200px
 *
 * Theme: light and dark. The OS preference applies by default; setting
 * <html data-theme="light|dark"> overrides it (see assets/js/bcos.js).
 */

/* ------------------------------------------------------------------ Font */

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url("../fonts/inter/InterVariable.woff2") format("woff2");
}

@font-face {
    font-family: "Inter";
    font-style: italic;
    font-weight: 100 900;
    font-display: swap;
    src: url("../fonts/inter/InterVariable-Italic.woff2") format("woff2");
}

/* ---------------------------------------------------------------- Tokens */

:root {
    /* Typography */
    --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.75rem;
    --text-4xl: 2rem;
    --leading-tight: 1.2;
    --leading-normal: 1.55;

    /* Spacing (4px scale) */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Layout */
    --container: 1280px;
    --gutter: var(--space-4);
    --header-height: 56px;
    --grid-columns: 1;

    /* Shape & motion */
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-full: 999px;
    --transition: 150ms ease;

    /* Light palette */
    color-scheme: light;
    --color-bg: #f5f7fa;
    --color-surface: #ffffff;
    --color-surface-2: #f0f2f6;
    --color-border: #e1e5ec;
    --color-border-strong: #c9d0db;
    --color-text: #101828;
    --color-text-muted: #5a6478;
    --color-text-subtle: #8a93a5;

    --color-primary: #4a6fd4;
    --color-primary-hover: #3f62c2;
    --color-primary-soft: #eef2fb;
    --color-on-primary: #ffffff;
    --color-on-danger: #ffffff;

    --color-success: #3f8f5f;
    --color-success-soft: #edf6f0;
    --color-warning: #b07433;
    --color-warning-soft: #fbf4e8;
    --color-danger: #c25555;
    --color-danger-soft: #fbeeee;
    --color-info: #3d7fa8;
    --color-info-soft: #ecf3f8;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.12);
    --focus-ring: 0 0 0 3px rgba(74, 111, 212, 0.3);
}

/* Dark palette — applied by OS preference unless light is forced, or when dark is forced */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --color-bg: #0b0f17;
        --color-surface: #121826;
        --color-surface-2: #1a2233;
        --color-border: #252f42;
        --color-border-strong: #364257;
        --color-text: #e6e9ef;
        --color-text-muted: #a0a9ba;
        --color-text-subtle: #6f7a8e;

        --color-primary: #7d9ce8;
        --color-primary-hover: #93aef0;
        --color-primary-soft: #1c2640;
        --color-on-primary: #0b0f17;
        --color-on-danger: #0b0f17;

        --color-success: #6cc195;
        --color-success-soft: #142a1f;
        --color-warning: #e3b66a;
        --color-warning-soft: #2d2416;
        --color-danger: #e38585;
        --color-danger-soft: #2f1a1c;
        --color-info: #74b4d8;
        --color-info-soft: #13242f;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
        --focus-ring: 0 0 0 3px rgba(125, 156, 232, 0.4);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --color-bg: #0b0f17;
    --color-surface: #121826;
    --color-surface-2: #1a2233;
    --color-border: #252f42;
    --color-border-strong: #364257;
    --color-text: #e6e9ef;
    --color-text-muted: #a0a9ba;
    --color-text-subtle: #6f7a8e;

    --color-primary: #7d9ce8;
    --color-primary-hover: #93aef0;
    --color-primary-soft: #1c2640;
    --color-on-primary: #0b0f17;
    --color-on-danger: #0b0f17;

    --color-success: #6cc195;
    --color-success-soft: #142a1f;
    --color-warning: #e3b66a;
    --color-warning-soft: #2d2416;
    --color-danger: #e38585;
    --color-danger-soft: #2f1a1c;
    --color-info: #74b4d8;
    --color-info-soft: #13242f;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
    --focus-ring: 0 0 0 3px rgba(125, 156, 232, 0.4);
}

/* ----------------------------------------------------------------- Reset */

*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    font-feature-settings: "cv11", "ss01";
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img, svg, video { display: block; max-width: 100%; height: auto; }
input, button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ------------------------------------------------------------ Typography */

h1, h2, h3, h4, h5, h6 {
    margin: 0 0 var(--space-3);
    line-height: var(--leading-tight);
    font-weight: 650;
    letter-spacing: -0.015em;
}
h1 { font-size: var(--text-3xl); letter-spacing: -0.025em; }
h2 { font-size: var(--text-2xl); letter-spacing: -0.02em; }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
h6 { font-size: var(--text-sm); text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-muted); }

p { margin: 0 0 var(--space-4); }
small, .text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-muted { color: var(--color-text-muted); }
.text-subtle { color: var(--color-text-subtle); }
.lead { font-size: var(--text-lg); color: var(--color-text-muted); }
.tabular { font-variant-numeric: tabular-nums; }

a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-hover); text-decoration: underline; text-underline-offset: 3px; }

code, kbd, pre { font-family: var(--font-mono); font-size: 0.9em; }
code {
    padding: 0.1em 0.35em;
    border-radius: var(--radius-sm);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
}
kbd {
    padding: 0.1em 0.4em;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border-strong);
    border-bottom-width: 2px;
    background: var(--color-surface);
}

hr { border: 0; border-top: 1px solid var(--color-border); margin: var(--space-8) 0; }

/* ---------------------------------------------------------------- Layout */

.container {
    width: 100%;
    max-width: var(--container);
    margin-inline: auto;
    padding-inline: var(--gutter);
}

.grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(var(--grid-columns), minmax(0, 1fr));
}
.grid-2, .grid-3, .grid-4 { display: grid; gap: var(--space-4); grid-template-columns: 1fr; }

.stack > * + * { margin-top: var(--space-4); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.section { padding-block: var(--space-8); }

/* Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--header-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}
.app-header .container {
    height: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-4);
}
.brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
}
.brand:hover { color: var(--color-text); text-decoration: none; }
.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: grid;
    place-items: center;
    background: var(--color-primary);
    color: var(--color-on-primary);
    font-size: var(--text-xs);
    font-weight: 800;
}
.brand-version {
    font-weight: 500;
    font-size: var(--text-xs);
    color: var(--color-text-subtle);
}
.nav { display: none; gap: var(--space-1); }
.nav a {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-weight: 500;
}
.nav a:hover { color: var(--color-text); background: var(--color-surface-2); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--color-primary); background: var(--color-primary-soft); }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

/* ----------------------------------------------------------- Components */

/* Card */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-header, .card-body, .card-footer { padding: var(--space-4); }
.card-header { border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.card-header h3, .card-header h4 { margin: 0; }
.card-footer { border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: var(--space-2); }

/* Stat tile */
.stat-label { font-size: var(--text-sm); color: var(--color-text-muted); margin: 0; }
.stat-value { font-size: var(--text-3xl); font-weight: 650; letter-spacing: -0.025em; font-variant-numeric: tabular-nums; margin: var(--space-1) 0; }
.stat-delta { font-size: var(--text-sm); font-weight: 550; }
.stat-delta.up { color: var(--color-success); }
.stat-delta.down { color: var(--color-danger); }

/* Button */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 40px;
    padding: 0 var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: var(--text-sm);
    font-weight: 550;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover { background: var(--color-primary-hover); color: var(--color-on-primary); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--color-surface-2); color: var(--color-text); }
.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-surface-2); color: var(--color-text); }
.btn-danger { background: var(--color-danger); color: var(--color-on-danger); }
.btn-danger:hover { filter: brightness(0.94); color: var(--color-on-danger); }

.btn-sm { min-height: 32px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn-lg { min-height: 48px; padding: 0 var(--space-6); font-size: var(--text-base); }
.btn-block { width: 100%; }
.btn-icon { width: 40px; padding: 0; }

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-2);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 550;
    background: var(--color-surface-2);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}
.badge-primary { background: var(--color-primary-soft); color: var(--color-primary); border-color: transparent; }
.badge-success { background: var(--color-success-soft); color: var(--color-success); border-color: transparent; }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); border-color: transparent; }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); border-color: transparent; }
.badge-info { background: var(--color-info-soft); color: var(--color-info); border-color: transparent; }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Alert */
.alert {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    border: 1px solid transparent;
    border-left-width: 4px;
    font-size: var(--text-sm);
}
.alert strong { display: block; margin-bottom: 2px; }
.alert-info { background: var(--color-info-soft); border-color: var(--color-info); }
.alert-success { background: var(--color-success-soft); border-color: var(--color-success); }
.alert-warning { background: var(--color-warning-soft); border-color: var(--color-warning); }
.alert-danger { background: var(--color-danger-soft); border-color: var(--color-danger); }

/* Forms */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.label { font-size: var(--text-sm); font-weight: 550; }
.hint { font-size: var(--text-xs); color: var(--color-text-muted); }
.field.is-invalid .hint { color: var(--color-danger); }

.input, .select, .textarea {
    width: 100%;
    min-height: 40px;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    background: var(--color-surface);
    font-size: var(--text-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.input::placeholder, .textarea::placeholder { color: var(--color-text-subtle); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: var(--focus-ring); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--color-surface-2); color: var(--color-text-subtle); cursor: not-allowed; }
.field.is-invalid .input { border-color: var(--color-danger); }
.textarea { min-height: 96px; resize: vertical; }
.select {
    appearance: none;
    padding-right: var(--space-8);
    background-image: linear-gradient(45deg, transparent 50%, var(--color-text-muted) 50%), linear-gradient(135deg, var(--color-text-muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
}

.check { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--color-primary); }

.switch { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); cursor: pointer; }
.switch input {
    appearance: none;
    width: 38px;
    height: 22px;
    margin: 0;
    border-radius: var(--radius-full);
    background: var(--color-border-strong);
    position: relative;
    transition: background var(--transition);
    cursor: pointer;
}
.switch input::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition);
}
.switch input:checked { background: var(--color-primary); }
.switch input:checked::after { transform: translateX(16px); }

/* Table */
.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--color-surface); }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th, .table td { padding: var(--space-3) var(--space-4); text-align: left; white-space: nowrap; }
.table th {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    background: var(--color-surface-2);
    border-bottom: 1px solid var(--color-border);
}
.table td { border-bottom: 1px solid var(--color-border); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--color-surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Tabs */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--color-border); overflow-x: auto; }
.tab {
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    background: none;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-weight: 550;
    white-space: nowrap;
}
.tab:hover { color: var(--color-text); }
.tab[aria-selected="true"] { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* Breadcrumb */
.breadcrumb { display: flex; flex-wrap: wrap; gap: var(--space-2); padding: 0; margin: 0; list-style: none; font-size: var(--text-sm); color: var(--color-text-muted); }
.breadcrumb li + li::before { content: "/"; margin-right: var(--space-2); color: var(--color-text-subtle); }
.breadcrumb [aria-current="page"] { color: var(--color-text); font-weight: 550; }

/* Pagination */
.pagination { display: flex; gap: var(--space-1); padding: 0; margin: 0; list-style: none; }
.pagination a {
    display: grid;
    place-items: center;
    min-width: 36px;
    height: 36px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-weight: 550;
}
.pagination a:hover { background: var(--color-surface-2); color: var(--color-text); text-decoration: none; }
.pagination a[aria-current="page"] { background: var(--color-primary); color: var(--color-on-primary); }

/* Avatar */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-grid;
    place-items: center;
    background: var(--color-primary-soft);
    color: var(--color-primary);
    font-size: var(--text-xs);
    font-weight: 700;
}

/* Progress */
.progress { height: 8px; border-radius: var(--radius-full); background: var(--color-surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--color-primary); }

/* Modal (static preview; real modals should use <dialog>) */
.modal {
    max-width: 440px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

/* Theme switcher */
.theme-switch { display: inline-flex; padding: 2px; border-radius: var(--radius); background: var(--color-surface-2); border: 1px solid var(--color-border); }
.theme-switch button {
    border: 0;
    background: none;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 550;
    color: var(--color-text-muted);
}
.theme-switch button[aria-pressed="true"] { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }

/* Device indicator: shows which breakpoint is active */
.device::after { content: "Mobile"; }

/* Utilities */
.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
}
.hide-mobile { display: none; }

/* ------------------------------------------------- Tablet: 768px – 1199px */

@media (min-width: 768px) {
    :root {
        --gutter: var(--space-6);
        --header-height: 64px;
        --grid-columns: 2;
        --text-3xl: 2rem;
        --text-4xl: 2.25rem;
    }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5); }
    .card-header, .card-body, .card-footer { padding: var(--space-5); }
    .section { padding-block: var(--space-10); }
    .nav { display: flex; }
    .hide-mobile { display: revert; }
    .hide-tablet-up { display: none; }
    .device::after { content: "Tablet"; }
}

/* ------------------------------------------------------- Desktop: 1200px+ */

@media (min-width: 1200px) {
    :root {
        --gutter: var(--space-8);
        --grid-columns: 4;
        --text-3xl: 2.25rem;
        --text-4xl: 2.75rem;
    }
    .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .grid-2, .grid-3, .grid-4 { gap: var(--space-6); }
    .card-header, .card-body, .card-footer { padding: var(--space-6); }
    .section { padding-block: var(--space-12); }
    .device::after { content: "Desktop"; }
}
