:root {
    --background: #f8fafc;
    --background-soft: #eef2f7;
    --surface: #ffffff;
    --surface-2: #f8fbff;
    --border: #d9e2ec;
    --border-strong: #c6d0db;
    --text: #0f172a;
    --muted: #526173;
    --accent: #0f172a;
    --accent-2: #2563eb;
    --success: #0f766e;
    --danger: #dc2626;
    --warning: #d97706;
    --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
    --radius: 1rem;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Helvetica Neue", sans-serif;
    color: var(--text);
    background:
        linear-gradient(180deg, rgba(37, 99, 235, 0.06), transparent 22%),
        linear-gradient(90deg, rgba(15, 23, 42, 0.04), transparent 28%),
        var(--background);
}

a {
    color: inherit;
    text-decoration: none;
}

a:hover {
    text-decoration: none;
}

.app-shell {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
}

.sidebar-scrim,
.nav-toggle {
    display: none;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 1.5rem;
    background: #0b1220;
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.brand-link {
    display: flex;
    gap: 0.9rem;
    align-items: center;
    padding: 0.5rem 0;
}

.brand-icon {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.85rem;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    font-weight: 700;
    font-size: 1.1rem;
}

.brand-label,
.brand-subtitle {
    display: block;
}

.brand-label {
    font-weight: 700;
}

.brand-subtitle {
    color: #94a3b8;
    font-size: 0.85rem;
}

.sidebar-nav,
.workspace-nav {
    display: grid;
    gap: 0.35rem;
}

.nav-link,
.workspace-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 0.95rem;
    border-radius: 0.85rem;
    color: inherit;
    transition: 0.18s ease;
}

.nav-link:hover,
.workspace-link:hover {
    background: rgba(255, 255, 255, 0.08);
}

.nav-link.active,
.workspace-link.active {
    background: rgba(37, 99, 235, 0.2);
    color: #fff;
}

.workspace-count {
    min-width: 2rem;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #cbd5e1;
    text-align: center;
    font-size: 0.78rem;
    font-weight: 700;
}

.sidebar-foot {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-caption {
    color: #94a3b8;
    margin: 0;
    font-size: 0.8rem;
}

.sidebar-user {
    margin: 0.35rem 0 1rem;
    font-weight: 600;
}

.main-shell {
    min-width: 0;
}

.topbar,
.content-shell {
    width: min(1320px, calc(100% - 2.5rem));
    margin: 0 auto;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.5rem 0 1rem;
    align-items: flex-end;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.page-title,
.hero-title,
.section-title,
.surface h3,
.auth-title {
    margin: 0;
    font-family: "Georgia", "Times New Roman", serif;
}

.global-search,
.inline-search,
.hero-actions,
.form-actions,
.card-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.global-search {
    align-items: center;
    min-width: min(460px, 100%);
}

.global-search input,
.inline-search input,
.input,
.textarea,
.select {
    width: 100%;
    padding: 0.85rem 1rem;
    border-radius: 0.9rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.global-search input {
    flex: 1 1 18rem;
}

.input:focus,
.textarea:focus,
.select:focus,
.global-search input:focus,
.inline-search input:focus {
    outline: none;
    border-color: #93c5fd;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
}

.textarea {
    min-height: 120px;
    resize: vertical;
}

.checkbox {
    width: 1.05rem;
    height: 1.05rem;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.85rem;
    padding: 0.8rem 1rem;
    min-height: 2.9rem;
    font-weight: 600;
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
}

.button:hover {
    opacity: 0.96;
}

.button.ghost {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.button.danger {
    background: var(--danger);
}

.button.full {
    width: 100%;
}

.content-shell {
    padding-bottom: 2rem;
}

.messages {
    margin-bottom: 1rem;
}

.alert {
    padding: 0.95rem 1rem;
    border-radius: 0.9rem;
    background: var(--surface);
    border: 1px solid var(--border);
}

.alert.success {
    border-color: rgba(15, 118, 110, 0.25);
    background: rgba(15, 118, 110, 0.08);
}

.alert.warning {
    border-color: rgba(217, 119, 6, 0.25);
    background: rgba(217, 119, 6, 0.09);
}

.alert.error {
    border-color: rgba(220, 38, 38, 0.25);
    background: rgba(220, 38, 38, 0.08);
}

.hero-panel,
.surface,
.workspace-card,
.auth-card,
.workspace-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.hero-panel,
.surface,
.workspace-card,
.auth-card {
    padding: 1.4rem;
}

.hero-panel {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}

.hero-panel.compact {
    align-items: center;
}

.hero-copy,
.muted,
.table-subtle,
.field-help {
    color: var(--muted);
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.74rem;
    margin: 0 0 0.35rem;
    color: var(--accent-2);
    font-weight: 700;
}

.metric-grid,
.board-grid,
.project-grid,
.dual-grid {
    display: grid;
    gap: 1rem;
}

.metric-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 1rem;
}

.metric-card {
    border-radius: 1rem;
    padding: 1rem 1.1rem;
    background: linear-gradient(180deg, var(--surface), var(--surface-2));
    border: 1px solid var(--border);
}

.metric-card.interactive {
    display: block;
}

.metric-label {
    margin: 0;
    color: var(--muted);
    font-size: 0.84rem;
}

.metric-value {
    margin: 0.35rem 0 0;
    font-size: 1.7rem;
    font-weight: 700;
}

.board-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    margin-bottom: 1rem;
}

.dual-grid {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    margin-bottom: 1rem;
}

.surface-head,
.workspace-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.stack-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.stack-list li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
}

.stack-list li:last-child {
    border-bottom: 0;
}

.project-grid {
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
}

.workspace-card h3 {
    margin: 0.15rem 0 0;
}

.workspace-code,
.workspace-panel-label {
    margin: 0;
    color: var(--accent-2);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.badge,
.section-count {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.1);
    color: #1d4ed8;
    font-size: 0.82rem;
    font-weight: 600;
}

.meta-grid {
    display: grid;
    gap: 0.8rem;
    margin: 0;
}

.meta-grid div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid var(--border);
}

.meta-grid dt {
    color: var(--muted);
}

.meta-grid dd {
    margin: 0;
    text-align: right;
}

.workspace-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 1rem;
}

.workspace-sidebar {
    display: grid;
    gap: 1rem;
    align-content: start;
}

.workspace-panel {
    padding: 1rem;
}

.workspace-content {
    min-width: 0;
}

.graph-filter-bar,
.graph-layout {
    display: grid;
    gap: 1rem;
}

.graph-filter-bar {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    align-items: end;
}

.graph-filter-field,
.graph-search-field {
    display: grid;
    gap: 0.45rem;
}

.graph-filter-field span,
.graph-search-field span {
    font-weight: 600;
}

.graph-filter-actions,
.graph-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.graph-layout {
    grid-template-columns: minmax(0, 1.9fr) minmax(300px, 0.9fr);
    align-items: start;
}

.graph-stage {
    min-width: 0;
}

.graph-canvas-shell {
    position: relative;
    border-radius: 1rem;
    overflow: hidden;
    border: 1px solid var(--border);
    background:
        radial-gradient(circle at top, rgba(37, 99, 235, 0.08), transparent 35%),
        linear-gradient(180deg, #f8fbff, #eef4fb);
    min-height: 720px;
}

.project-graph-canvas {
    display: block;
    width: 100%;
    height: 720px;
}

.graph-canvas-overlay {
    position: absolute;
    inset: 0;
    display: none;
    place-items: center;
    text-align: center;
    padding: 2rem;
    color: var(--muted);
    background: rgba(248, 250, 252, 0.88);
}

.graph-canvas-overlay.is-visible {
    display: grid;
}

.graph-help {
    margin: 0.9rem 0 0;
}

.graph-side-column {
    display: grid;
    gap: 1rem;
}

.graph-selection-panel,
.graph-selection-card,
.graph-node-meta,
.graph-selection-copy {
    display: grid;
    gap: 0.8rem;
}

.graph-selection-card h4 {
    margin: 0;
    font-size: 1.2rem;
}

.graph-node-meta {
    margin: 0;
}

.graph-node-meta div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 0.55rem;
    border-bottom: 1px solid var(--border);
}

.graph-node-meta dt {
    color: var(--muted);
}

.graph-node-meta dd {
    margin: 0;
    text-align: right;
}

.graph-selection-copy p {
    margin: 0;
    color: var(--muted);
}

.graph-legend-list,
.graph-relationship-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.75rem;
}

.graph-legend-list li,
.graph-relationship-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding-bottom: 0.7rem;
    border-bottom: 1px solid var(--border);
}

.graph-legend-list li:last-child,
.graph-relationship-list li:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.graph-swatch {
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 999px;
    display: inline-block;
    margin-right: 0.65rem;
    flex: 0 0 auto;
}

.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 0.85rem 0.7rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.actions-cell {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.form-shell {
    max-width: 920px;
}

.form-surface {
    max-width: 920px;
}

.stack-form {
    display: grid;
    gap: 1rem;
}

.form-row label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.note-form-grid {
    display: grid;
    gap: 1.1rem;
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
    align-items: start;
}

.note-form-main,
.note-form-side {
    display: grid;
    gap: 1rem;
}

.handwriting-panel {
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: linear-gradient(180deg, #fcfdff, #f3f7fb);
    padding: 1rem;
    display: grid;
    gap: 0.9rem;
}

.handwriting-head,
.handwriting-actions,
.handwriting-meta {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.handwriting-surface {
    position: relative;
    border: 1px solid var(--border-strong);
    border-radius: 1rem;
    overflow: hidden;
    background:
        linear-gradient(transparent 31px, rgba(148, 163, 184, 0.28) 32px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.18) 1px, transparent 1px),
        #ffffff;
    background-size: 100% 32px, 24px 100%, auto;
}

.handwriting-canvas {
    display: block;
    width: 100%;
    height: 360px;
    touch-action: none;
    cursor: crosshair;
}

.handwriting-status {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.handwriting-status.error {
    color: var(--danger);
}

.handwriting-status.success {
    color: var(--success);
}

.recognized-text-box {
    min-height: 7rem;
    padding: 0.85rem 1rem;
    border: 1px dashed var(--border-strong);
    border-radius: 0.85rem;
    background: rgba(255, 255, 255, 0.9);
    white-space: pre-wrap;
}

.recognized-text-box.is-empty {
    color: var(--muted);
}

.handwriting-preview {
    display: grid;
    gap: 0.65rem;
}

.handwriting-preview img {
    width: 100%;
    max-height: 240px;
    object-fit: contain;
    border-radius: 0.85rem;
    border: 1px solid var(--border);
    background: #fff;
}

.field-error {
    margin: 0.4rem 0 0;
    color: var(--danger);
    font-size: 0.88rem;
}

.field-help {
    margin: 0.35rem 0 0;
    font-size: 0.88rem;
}

.danger-link {
    color: var(--danger);
}

.content-stack {
    display: grid;
    gap: 0.85rem;
}

.pagination {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1rem 0;
}

.guest-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem;
}

.auth-layout {
    width: min(480px, 100%);
}

.auth-card {
    width: 100%;
}

@media (max-width: 1100px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(88vw, 340px);
        height: 100vh;
        z-index: 40;
        transform: translateX(-102%);
        transition: transform 0.22s ease;
        overflow-y: auto;
    }

    .nav-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-scrim {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.4);
        z-index: 35;
    }

    .nav-open .sidebar-scrim {
        display: block;
    }

    .nav-toggle {
        display: inline-flex;
        flex: 0 0 auto;
        width: 3rem;
        height: 3rem;
        border-radius: 0.9rem;
        border: 1px solid var(--border);
        background: var(--surface);
        box-shadow: var(--shadow);
        align-items: center;
        justify-content: center;
        gap: 0.24rem;
        padding: 0.7rem;
        cursor: pointer;
    }

    .nav-toggle span:not(.sr-only) {
        display: block;
        width: 100%;
        height: 2px;
        border-radius: 999px;
        background: var(--text);
    }

    .topbar {
        align-items: flex-start;
    }

    .workspace-layout {
        grid-template-columns: 1fr;
    }

    .graph-layout {
        grid-template-columns: 1fr;
    }

    .note-form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .topbar,
    .hero-panel,
    .surface-head,
    .workspace-top,
    .stack-list li,
    .meta-grid div {
        flex-direction: column;
    }

    .topbar,
    .content-shell {
        width: min(100%, calc(100% - 1.2rem));
    }

    .global-search {
        min-width: 100%;
    }

    .meta-grid dd {
        text-align: left;
    }

    .graph-node-meta dd {
        text-align: left;
    }

    .workspace-nav {
        grid-auto-flow: column;
        grid-auto-columns: minmax(180px, 1fr);
        overflow-x: auto;
        padding-bottom: 0.25rem;
    }

    .workspace-link {
        min-height: 3rem;
    }

    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table tr {
        border: 1px solid var(--border);
        border-radius: 0.95rem;
        padding: 0.2rem 0.9rem;
        margin-bottom: 0.9rem;
        background: #fff;
    }

    .data-table td {
        border-bottom: 1px solid var(--border);
        padding: 0.8rem 0;
    }

    .data-table td:last-child {
        border-bottom: 0;
    }

    .data-table td::before {
        content: attr(data-label);
        display: block;
        color: var(--muted);
        font-size: 0.78rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        margin-bottom: 0.3rem;
    }

    .actions-cell {
        gap: 1rem;
    }

    .graph-canvas-shell,
    .project-graph-canvas {
        min-height: 520px;
        height: 520px;
    }

    .handwriting-canvas {
        height: 280px;
    }

    .handwriting-head,
    .handwriting-actions,
    .handwriting-meta {
        flex-direction: column;
        align-items: stretch;
    }
}
