:root {
    --sidebar: #0d111c;
    --sidebar-soft: #151b29;
    --sidebar-line: #263044;
    --bg: #f4f6f8;
    --panel: #ffffff;
    --panel-muted: #f8fafc;
    --line: #d9dee7;
    --text: #18202f;
    --muted: #687386;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --warn: #b45309;
    --danger: #b42318;
    --shadow: 0 18px 55px rgba(14, 23, 38, 0.16);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    margin: 0;
}

button,
input,
textarea,
select {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

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

.app-shell {
    display: grid;
    grid-template-columns: 310px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: var(--sidebar);
    color: #edf3ff;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 22px 18px;
}

.brand {
    align-items: center;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    min-width: 0;
}

.brand-mark {
    align-items: center;
    background: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: #111827;
    display: grid;
    flex: 0 0 42px;
    font-weight: 900;
    height: 42px;
    justify-content: center;
    letter-spacing: 0;
    width: 42px;
}

.brand-title {
    color: #ffffff;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0;
}

.brand-subtitle,
.brand-version,
.eyebrow,
.meta,
.muted {
    color: var(--muted);
    font-size: 12px;
}

.sidebar .brand-subtitle,
.sidebar .brand-version {
    color: #9aa8bd;
}

.main-nav,
.sidebar-tools,
.context-list,
.sidebar-footer,
.settings-stack {
    display: grid;
    gap: 10px;
}

.main-nav {
    margin-bottom: 18px;
}

.nav-item,
.footer-item {
    align-items: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #c7d2e5;
    cursor: pointer;
    display: flex;
    gap: 10px;
    min-height: 42px;
    padding: 9px 10px;
    text-align: left;
}

.nav-item:hover,
.footer-item:hover,
.nav-item.active {
    background: var(--sidebar-soft);
    border-color: var(--sidebar-line);
    color: #ffffff;
}

.nav-icon {
    align-items: center;
    background: #242d3f;
    border-radius: 7px;
    display: grid;
    flex: 0 0 26px;
    font-size: 12px;
    font-weight: 800;
    height: 26px;
    justify-content: center;
    width: 26px;
}

.sidebar-tools {
    border-bottom: 1px solid var(--sidebar-line);
    border-top: 1px solid var(--sidebar-line);
    margin-bottom: 16px;
    padding: 16px 0;
}

.sidebar-tools label,
.field label {
    color: #7a869a;
    display: block;
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 6px;
}

.field label {
    color: #596579;
}

input,
textarea,
select {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    min-height: 40px;
    outline: none;
    padding: 9px 11px;
    width: 100%;
}

.sidebar input {
    background: #0a0f1b;
    border-color: var(--sidebar-line);
    color: #ffffff;
}

textarea {
    min-height: 140px;
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.context-list {
    min-height: 0;
    overflow: auto;
}

.context-heading {
    color: #8d9ab0;
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 2px;
    text-transform: uppercase;
}

.tag-list {
    display: grid;
    gap: 7px;
}

.tag-row {
    align-items: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: #cbd6e8;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    min-height: 36px;
    padding: 7px 9px;
    text-align: left;
}

.tag-row:hover,
.tag-row.active {
    background: var(--sidebar-soft);
    border-color: var(--sidebar-line);
    color: #ffffff;
}

.tag-count {
    background: #263044;
    border-radius: 999px;
    color: #aebbd0;
    font-size: 11px;
    font-weight: 800;
    min-width: 24px;
    padding: 2px 7px;
    text-align: center;
}

.sidebar-footer {
    border-top: 1px solid var(--sidebar-line);
    margin-top: auto;
    padding-top: 14px;
}

.workspace {
    min-width: 0;
    padding: 24px;
}

.topbar {
    align-items: center;
    display: flex;
    gap: 18px;
    justify-content: space-between;
    margin-bottom: 18px;
}

.topbar h1 {
    font-size: 28px;
    letter-spacing: 0;
    line-height: 1.1;
    margin: 4px 0 0;
}

.topbar-actions,
.row-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
    align-items: center;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    font-weight: 800;
    gap: 8px;
    justify-content: center;
    min-height: 40px;
    padding: 9px 13px;
    text-decoration: none;
}

.primary-button {
    background: var(--accent);
    border: 1px solid var(--accent);
    color: #ffffff;
}

.primary-button:hover {
    background: var(--accent-dark);
}

.secondary-button {
    background: #ffffff;
    border: 1px solid var(--line);
    color: var(--text);
}

.danger-button {
    background: #fff4f2;
    border: 1px solid #ffd4cf;
    color: var(--danger);
}

.icon-button {
    background: #ffffff;
    border: 1px solid var(--line);
    color: var(--text);
    flex: 0 0 38px;
    height: 38px;
    padding: 0;
    width: 38px;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.dashboard-band,
.panel,
.empty-state {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.dashboard-band {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 16px;
    padding: 14px;
}

.stat {
    min-width: 0;
}

.stat strong {
    display: block;
    font-size: 26px;
    line-height: 1.1;
}

.stat span {
    color: var(--muted);
    font-size: 12px;
}

.drop-zone {
    align-items: center;
    background: #ffffff;
    border: 1px dashed #a8b3c5;
    border-radius: 8px;
    color: var(--muted);
    display: grid;
    gap: 5px;
    justify-content: center;
    min-height: 150px;
    padding: 18px;
    text-align: center;
}

.compact-drop {
    background: #0a0f1b;
    border-color: #38445b;
    color: #aebbd0;
    min-height: 84px;
}

.drop-zone.dragging,
.document-card.dragging {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.document-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.document-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
    display: grid;
    gap: 12px;
    min-height: 360px;
    overflow: hidden;
}

.doc-preview {
    background: #eef2f7;
    border-bottom: 1px solid var(--line);
    height: 170px;
    overflow: hidden;
    position: relative;
}

.doc-preview iframe,
.doc-preview img,
.modal-preview iframe,
.modal-preview img {
    border: 0;
    height: 100%;
    object-fit: contain;
    width: 100%;
}

.file-symbol {
    align-items: center;
    color: #4b5563;
    display: grid;
    font-size: 42px;
    font-weight: 900;
    height: 100%;
    justify-content: center;
}

.doc-body {
    display: grid;
    gap: 10px;
    min-width: 0;
    padding: 0 14px 14px;
}

.doc-title-row {
    align-items: start;
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.doc-title {
    font-size: 16px;
    font-weight: 850;
    line-height: 1.25;
    min-width: 0;
    overflow-wrap: anywhere;
}

.badge,
.status-badge,
.tag-chip {
    align-items: center;
    border-radius: 999px;
    display: inline-flex;
    font-size: 12px;
    font-weight: 800;
    min-height: 24px;
    padding: 3px 8px;
}

.badge {
    background: #eefcf9;
    color: var(--accent-dark);
}

.status-badge {
    background: #f1f5f9;
    color: #475569;
}

.status-badge.warn {
    background: #fff7ed;
    color: var(--warn);
}

.status-badge.ok {
    background: #ecfdf5;
    color: var(--accent-dark);
}

.tag-chip {
    background: #eef2ff;
    color: #3730a3;
}

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.empty-state {
    color: var(--muted);
    display: grid;
    gap: 10px;
    justify-items: center;
    padding: 42px 20px;
    text-align: center;
}

.panel {
    display: grid;
    gap: 14px;
    padding: 16px;
}

.panel-header {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.panel-header h2,
.panel-header h3 {
    font-size: 18px;
    margin: 0;
}

.form-grid {
    display: grid;
    gap: 13px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field.wide,
.wide {
    grid-column: 1 / -1;
}

.hash-row {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 4px;
    padding: 10px;
}

.hash-row code,
.hash-value {
    color: #334155;
    font-family: Consolas, "Liberation Mono", monospace;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.version-list {
    display: grid;
    gap: 8px;
}

.version-row {
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 8px;
    grid-template-columns: 76px minmax(0, 1fr) auto;
    padding: 10px;
}

.modal-backdrop {
    align-items: center;
    background: rgba(4, 9, 18, 0.58);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 22px;
    position: fixed;
    z-index: 40;
}

.modal-panel {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    max-height: min(900px, calc(100vh - 44px));
    max-width: 1160px;
    overflow: hidden;
    width: min(1160px, 100%);
}

.modal-header {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 14px 16px;
}

.modal-header h2 {
    font-size: 18px;
    margin: 0;
}

.modal-content {
    display: grid;
    gap: 0;
    grid-template-columns: minmax(320px, 1fr) minmax(360px, 440px);
    min-height: 0;
    overflow: hidden;
}

.modal-preview {
    background: #e9eef5;
    min-height: 620px;
    overflow: auto;
}

.modal-form {
    border-left: 1px solid var(--line);
    display: grid;
    gap: 14px;
    max-height: calc(100vh - 132px);
    overflow: auto;
    padding: 16px;
}

.suggest-wrap {
    position: relative;
}

.tag-suggestions {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: none;
    left: 0;
    max-height: 190px;
    overflow: auto;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 5;
}

.tag-suggestions.open {
    display: grid;
}

.tag-suggestion {
    background: #ffffff;
    border: 0;
    border-bottom: 1px solid #edf0f5;
    cursor: pointer;
    min-height: 36px;
    padding: 8px 10px;
    text-align: left;
}

.tag-suggestion:hover {
    background: #f1f5f9;
}

.toast {
    background: #111827;
    border-radius: 8px;
    bottom: 20px;
    box-shadow: var(--shadow);
    color: #ffffff;
    display: none;
    max-width: min(420px, calc(100vw - 40px));
    padding: 12px 14px;
    position: fixed;
    right: 20px;
    z-index: 60;
}

.toast.show {
    display: block;
}

.auth-page {
    align-items: center;
    background: #090b12;
    display: grid;
    justify-items: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-card,
.setup-card {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 16px;
    max-width: 920px;
    padding: 22px;
    width: min(100%, 920px);
}

.auth-card {
    max-width: 430px;
}

.auth-brand .brand-title {
    color: var(--text);
}

.auth-brand .brand-subtitle,
.auth-brand .brand-version {
    color: var(--muted);
}

.form-error,
.form-success {
    border-radius: 8px;
    font-weight: 700;
    padding: 10px 12px;
}

.form-error {
    background: #fff4f2;
    color: var(--danger);
}

.form-success {
    background: #ecfdf5;
    color: var(--accent-dark);
}

.switch-row {
    align-items: center;
    display: flex;
    gap: 8px;
}

.switch-row input {
    min-height: auto;
    width: auto;
}

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

    .sidebar {
        min-height: auto;
    }

    .modal-content {
        grid-template-columns: 1fr;
    }

    .modal-preview {
        min-height: 330px;
    }

    .modal-form {
        border-left: 0;
        border-top: 1px solid var(--line);
        max-height: none;
    }

    .dashboard-band {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 680px) {
    .workspace {
        padding: 16px;
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .dashboard-band,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .document-grid {
        grid-template-columns: 1fr;
    }

    .version-row {
        grid-template-columns: 1fr;
    }
}
