
:root {
    --bg: #f5f7fa;
    --card: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --header-bg: #0f172a;
    --sidebar-bg: #111827;
    --sidebar-text: #e5e7eb;
    --sidebar-muted: #9ca3af;
    --shadow: 0 1px 2px rgba(0,0,0,.03), 0 8px 24px rgba(0,0,0,.04);
}

[data-theme="dark"] {
    --bg: #020617;
    --card: #0f172a;
    --text: #f8fafc;
    --muted: #94a3b8;
    --border: #1e293b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --header-bg: #020617;
    --sidebar-bg: #020617;
    --sidebar-text: #f8fafc;
    --sidebar-muted: #94a3b8;
    --shadow: 0 1px 2px rgba(0,0,0,.18), 0 8px 24px rgba(0,0,0,.25);
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

body {
    overflow-x: hidden;
}

a {
    color: var(--primary);
}

img,
svg,
video {
    max-width: 100%;
    height: auto;
}

/* =====================================================
   APP SHELL / SIDEBAR
   ===================================================== */

.app-shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 24px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
}

.mobile-sidebar-top {
    display: none;
}

.sidebar-close {
    display: none;
}

.brand,
.brand:link,
.brand:visited,
.brand:hover,
.brand:active {
    display: block;
    color: #ffffff;
    text-decoration: none;
    font-size: 30px;
    font-weight: 900;
    letter-spacing: -0.04em;
    margin-bottom: 26px;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-label {
    color: var(--sidebar-muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
    margin: 18px 10px 8px;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar nav a,
.sidebar nav a:link,
.sidebar nav a:visited,
.theme-toggle {
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 15px;
    font-weight: 700;
    padding: 11px 12px;
    border-radius: 10px;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    background: rgba(255,255,255,0.09);
    color: #ffffff;
}

.sidebar nav a.primary-link {
    background: var(--primary);
    color: white;
}

.sidebar nav a.primary-link:hover {
    background: var(--primary-hover);
}

.theme-toggle {
    width: 100%;
    border: 1px solid rgba(255,255,255,.16);
    background: rgba(255,255,255,.07);
    cursor: pointer;
    text-align: left;
}

/* =====================================================
   CONTENT / TOPBAR
   ===================================================== */

.content {
    min-width: 0;
}

.topbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    padding: 18px 28px;
    border-bottom: 1px solid var(--border);
    background: var(--card);
    position: sticky;
    top: 0;
    z-index: 50;
}

.user-pill {
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

.mobile-menu-button {
    display: none;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    border-radius: 10px;
    padding: 10px 12px;
    font-weight: 800;
    cursor: pointer;
}

main {
    max-width: 1400px;
    margin: 32px auto;
    padding: 0 24px;
}

.top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

h1 {
    margin: 0 0 8px;
    font-size: clamp(28px, 4vw, 34px);
    font-weight: 900;
    line-height: 1.1;
}

h2,
h3 {
    margin-top: 0;
}

/* =====================================================
   CARDS / GRIDS / STATS
   ===================================================== */

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
    min-width: 0;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(310px, 100%), 1fr));
    gap: 18px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    min-width: 0;
}

.stat-card strong {
    display: block;
    font-size: clamp(24px, 4vw, 30px);
    line-height: 1;
    margin-bottom: 8px;
    overflow-wrap: anywhere;
}

.note-card {
    transition: transform .15s ease;
}

.note-card:hover {
    transform: translateY(-2px);
}

.note-card h3 {
    margin-bottom: 8px;
    font-size: 20px;
    overflow-wrap: anywhere;
}

/* =====================================================
   TEXT / META
   ===================================================== */

.muted {
    color: var(--muted);
    font-size: 14px;
}

.meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 10px;
}

.note-content {
    line-height: 1.8;
    white-space: pre-wrap;
    font-size: 17px;
    overflow-wrap: anywhere;
}

/* =====================================================
   FORMS
   ===================================================== */

label {
    display: block;
    margin: 16px 0 6px;
    font-weight: 800;
}

input,
textarea,
select {
    width: 100%;
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 16px;
    background: var(--card);
    color: var(--text);
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

textarea {
    min-height: 350px;
    resize: vertical;
    line-height: 1.6;
}

.search-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    margin-bottom: 24px;
}

.code-input {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* =====================================================
   BUTTONS
   ===================================================== */

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 20px;
}

.btn {
    border: none;
    border-radius: 10px;
    padding: 11px 16px;
    text-decoration: none;
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    transition: all .15s ease;
    background: var(--primary);
    color: white;
    display: inline-block;
    text-align: center;
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn.secondary {
    background: #4b5563;
    color: white;
}

.btn.secondary:hover {
    background: #374151;
}

.btn.success {
    background: var(--success);
    color: white;
}

.btn.danger {
    background: var(--danger);
    color: white;
}

.btn.warning {
    background: var(--warning);
    color: #111827;
}

/* =====================================================
   TAGS / ALERTS
   ===================================================== */

.tag {
    display: inline-block;
    background: #dbeafe;
    color: #1e40af;
    padding: 4px 10px;
    margin: 2px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
}

.error,
.success-box {
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 20px;
}

.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.success-box {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* =====================================================
   TABLES
   ===================================================== */

.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    min-width: 760px;
}

th,
td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.inline-form {
    display: inline;
}

/* =====================================================
   FEATURE AREAS
   ===================================================== */

.export-list {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.kanban-board {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.kanban-column {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    min-height: 360px;
    min-width: 0;
}

.kanban-column h2 {
    font-size: 18px;
    margin-bottom: 14px;
}

.version-list {
    display: grid;
    gap: 12px;
}

.version-item {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    background: var(--bg);
}

.audit-item {
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
}

.audit-item:last-child {
    border-bottom: 0;
}

.share-box {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    background: var(--bg);
    margin-top: 18px;
}

/* =====================================================
   TABLET
   ===================================================== */

@media (max-width: 1100px) {
    .app-shell {
        grid-template-columns: 230px minmax(0, 1fr);
    }

    .sidebar {
        padding: 22px 14px;
    }

    main {
        padding: 0 18px;
    }

    .kanban-board {
        grid-template-columns: 1fr;
    }
}

/* =====================================================
   MOBILE
   ===================================================== */

@media (max-width: 820px) {
    .app-shell {
        display: block;
        min-height: 100vh;
    }

    .app-shell::before {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(2, 6, 23, .58);
        z-index: 900;
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }

    .app-shell.sidebar-open::before {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(86vw, 340px);
        height: 100dvh;
        transform: translateX(-105%);
        transition: transform .22s ease;
        box-shadow: 20px 0 40px rgba(0,0,0,.28);
        border-right: 1px solid rgba(255,255,255,.08);
    }

    .app-shell.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .desktop-brand {
        display: none !important;
    }

    .mobile-sidebar-top {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        margin-bottom: 22px;
    }

    .mobile-sidebar-top .brand {
        margin-bottom: 0;
        font-size: 28px;
    }

    .sidebar-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 42px;
        height: 42px;
        border: 1px solid rgba(255,255,255,.18);
        border-radius: 10px;
        background: rgba(255,255,255,.08);
        color: white;
        font-size: 28px;
        line-height: 1;
        cursor: pointer;
    }

    .topbar {
        justify-content: space-between;
        padding: 14px 16px;
    }

    .mobile-menu-button {
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }

    .user-pill {
        max-width: 58vw;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        text-align: right;
    }

    main {
        margin: 20px auto;
        padding: 0 14px;
    }

    .top-row {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .top-row .actions,
    .top-row .btn {
        width: 100%;
    }

    .card {
        padding: 18px;
        border-radius: 14px;
    }

    .grid,
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .search-row {
        grid-template-columns: 1fr;
    }

    textarea {
        min-height: 260px;
    }

    .actions {
        align-items: stretch;
    }

    .actions .btn,
    .actions button,
    .actions form {
        width: 100%;
    }

    .inline-form {
        display: block;
    }

    .export-list .btn {
        flex: 1 1 100%;
    }

    .meta {
        gap: 8px;
        flex-direction: column;
    }

    table {
        min-width: 680px;
    }
}

/* =====================================================
   SMALL MOBILE
   ===================================================== */

@media (max-width: 420px) {
    h1 {
        font-size: 26px;
    }

    .card {
        padding: 16px;
    }

    .brand,
    .mobile-sidebar-top .brand {
        font-size: 25px;
    }

    .user-pill {
        font-size: 12px;
    }

    .btn,
    input,
    textarea,
    select {
        font-size: 15px;
    }

    .stat-card strong {
        font-size: 24px;
    }
}


.rich-content {
    line-height: 1.8;
    font-size: 17px;
    overflow-wrap: anywhere;
}

.rich-content h1,
.rich-content h2,
.rich-content h3,
.rich-content h4 {
    margin-top: 1.25em;
    margin-bottom: .5em;
}

.rich-content p {
    margin: 0 0 1em;
}

.rich-content ul,
.rich-content ol {
    padding-left: 1.5em;
}

.rich-content blockquote {
    border-left: 4px solid var(--border);
    padding-left: 14px;
    color: var(--muted);
    margin-left: 0;
}

.rich-content pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    overflow-x: auto;
}

.rich-content table {
    min-width: 0;
    width: 100%;
    border-collapse: collapse;
}

.rich-content a {
    word-break: break-word;
}

.tox-tinymce {
    border-radius: 12px !important;
    border-color: var(--border) !important;
}

[data-theme="dark"] .tox,
[data-theme="dark"] .tox .tox-toolbar,
[data-theme="dark"] .tox .tox-toolbar__primary,
[data-theme="dark"] .tox .tox-edit-area__iframe,
[data-theme="dark"] .tox .tox-statusbar {
    border-color: var(--border) !important;
}
