:root {
    color-scheme: light;
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-soft: #f1f5f9;
    --text: #17202a;
    --muted: #657282;
    --line: #d8e0ea;
    --primary: #155eef;
    --primary-strong: #0f46b7;
    --danger: #b42318;
    --success-bg: #e7f7ee;
    --success: #126b3a;
    --error-bg: #fde8e7;
    --error: #9f1c14;
}

* {
    box-sizing: border-box;
}

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

a {
    color: var(--primary);
    text-decoration: none;
}

.shell {
    width: min(1440px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 18px 0 48px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 54px;
    margin-bottom: 14px;
}

.topbar div {
    display: grid;
    gap: 2px;
}

.topbar strong {
    font-size: 1.05rem;
}

.topbar span,
.muted,
small {
    color: var(--muted);
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    margin-top: 16px;
}

.narrow {
    max-width: 460px;
    margin: 48px auto;
}

.drive-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.drive-sidebar {
    position: sticky;
    top: 16px;
    display: grid;
    gap: 12px;
}

.sidebar-section {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.sidebar-section h2 {
    margin: 0 0 10px;
    font-size: .92rem;
    color: var(--muted);
}

.main-nav {
    display: grid;
    gap: 4px;
}

.nav-item,
.nav-path a {
    display: flex;
    align-items: center;
    min-height: 38px;
    border-radius: 999px;
    padding: 8px 12px;
    color: var(--text);
}

.nav-item.active {
    background: #e8f0fe;
    color: #174ea6;
    font-weight: 700;
}

.note-list-item {
    display: grid;
    gap: 4px;
    min-width: 0;
    border-radius: 8px;
    padding: 10px;
    color: var(--text);
}

.note-list-item:hover,
.note-list-item.active {
    background: #f1f6ff;
}

.note-list-item span,
.note-list-item small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notes-list {
    max-height: calc(100vh - 210px);
    overflow: auto;
}

.nav-path {
    display: grid;
    gap: 2px;
    margin: -4px 0 4px;
    padding-left: 18px;
    border-left: 2px solid #dbe7fb;
}

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

.drive-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: flex-start;
    gap: 16px;
    min-height: 62px;
    padding: 6px 4px 12px;
}

.toolbar-actions {
    display: grid;
    justify-items: start;
    gap: 8px;
    min-width: 0;
}

.drive-toolbar h1,
.panel h1 {
    margin: 0;
    font-size: 1.35rem;
}

.toolbar-meta {
    color: var(--muted);
    white-space: nowrap;
    padding-top: 8px;
}

.folder-actions {
    width: 100%;
    min-width: min(520px, 100%);
    max-width: 760px;
    text-align: left;
}

.folder-actions summary {
    display: inline-flex;
    justify-content: center;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 12px;
    background: #fff;
    cursor: pointer;
    list-style: none;
}

.folder-actions summary::-webkit-details-marker {
    display: none;
}

.folder-actions[open] {
    grid-column: 1 / -1;
    width: 100%;
    max-width: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    color: var(--muted);
}

.breadcrumb a {
    color: var(--muted);
}

.file-browser {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.empty-state {
    display: grid;
    gap: 6px;
    padding: 42px 24px;
    text-align: center;
    color: var(--muted);
}

.empty-state strong {
    color: var(--text);
}

.stack,
.share-form {
    display: grid;
    gap: 12px;
}

.share-form {
    grid-template-columns: minmax(180px, 1.2fr) minmax(180px, 1fr) minmax(140px, .8fr) auto;
    align-items: end;
    margin-top: 14px;
}

label {
    display: grid;
    gap: 6px;
    font-weight: 650;
}

input,
textarea,
button,
.button {
    min-height: 40px;
    border-radius: 6px;
    border: 1px solid var(--line);
    padding: 8px 12px;
    font: inherit;
}

input,
textarea {
    width: 100%;
    background: #fff;
}

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

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    color: var(--text);
    cursor: pointer;
}

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

.primary:hover {
    background: var(--primary-strong);
}

.wide {
    width: 100%;
}

.danger {
    margin-top: 16px;
}

.danger button {
    color: var(--danger);
    border-color: #f1b8b3;
}

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

.drive-table + .drive-table {
    border-top: 10px solid var(--surface-soft);
}

th,
td {
    border-top: 1px solid var(--line);
    padding: 11px 14px;
    text-align: left;
    vertical-align: middle;
    overflow-wrap: anywhere;
    word-break: break-word;
}

thead th {
    border-top: 0;
}

th {
    color: var(--muted);
    font-size: .84rem;
    font-weight: 700;
}

.item-row:hover {
    background: #f8fbff;
}

.item-name {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 650;
}

.item-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: #edf2f7;
    color: #405368;
    font-size: .9rem;
}

.folder-row .item-icon {
    background: #fff4d6;
    color: #8a5a00;
}

td small {
    display: block;
    margin-top: 3px;
    font-weight: 400;
}

.actions {
    text-align: right;
    white-space: nowrap;
}

.select-col {
    width: 44px;
    text-align: center;
}

.select-col input {
    width: 18px;
    min-height: 18px;
    padding: 0;
}

.bulk-bar {
    display: flex;
    justify-content: flex-end;
    padding: 10px 14px;
    border-top: 1px solid var(--line);
    background: #fbfdff;
}

.action-group {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.inline {
    display: inline;
}

.danger-button {
    color: var(--danger);
    border-color: #f1b8b3;
}

.hint,
.inline-hint {
    color: var(--muted);
    font-size: .88rem;
}

.hint {
    margin: 8px 0 0;
}

.inline-hint {
    align-self: center;
    white-space: normal;
}

.upload-progress {
    display: grid;
    gap: 12px;
}

.progress-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 12px;
    align-items: center;
}

.progress-title {
    min-width: 0;
    overflow-wrap: anywhere;
    white-space: normal;
    color: var(--muted);
    font-size: .92rem;
}

.progress-track {
    grid-column: 1 / -1;
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: #e8edf3;
}

.progress-bar {
    width: 0;
    height: 100%;
    background: var(--primary);
    transition: width .15s ease;
}

.progress-label {
    color: var(--muted);
    font-size: .92rem;
}

.progress-item.failed .progress-bar {
    background: var(--danger);
}

.progress-item.failed .progress-label {
    color: var(--danger);
}

.upload-summary {
    border-radius: 6px;
    padding: 10px 12px;
}

.upload-summary.success {
    background: var(--success-bg);
    color: var(--success);
}

.upload-summary.warning {
    background: #fff7e6;
    color: #8a5a00;
}

.link-field {
    width: min(100%, 520px);
    min-width: 0;
    max-width: 100%;
    font-size: .9rem;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.expiry-form {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.expiry-form input {
    width: 100%;
    min-width: 0;
}

.expiry-form button {
    min-width: 96px;
    white-space: nowrap;
}

.flash {
    border-radius: 8px;
    margin-bottom: 16px;
    padding: 12px 14px;
    overflow-wrap: anywhere;
}

.flash.success {
    background: var(--success-bg);
    color: var(--success);
}

.flash.error {
    background: var(--error-bg);
    color: var(--error);
}

.note-editor-form {
    min-width: 0;
}

.note-editor-panel {
    display: grid;
    gap: 14px;
    margin-top: 0;
}

.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    background: #fbfdff;
}

.editor-toolbar button {
    min-width: 38px;
    min-height: 34px;
    padding: 6px 9px;
    font-size: .9rem;
}

.rich-editor {
    min-height: 420px;
    max-height: 66vh;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    background: #fff;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.rich-editor:focus {
    outline: 2px solid #b6ccff;
    outline-offset: 2px;
}

.rich-editor h1,
.rich-editor h2,
.rich-editor h3,
.rich-editor p,
.rich-editor ul,
.rich-editor ol,
.rich-editor blockquote,
.rich-editor pre {
    margin-top: 0;
}

.rich-editor blockquote {
    border-left: 4px solid var(--line);
    margin-left: 0;
    padding-left: 14px;
    color: #3f4e5f;
}

.rich-editor pre,
.rich-editor code {
    border-radius: 6px;
    background: #f3f6fa;
    font-family: Consolas, "Liberation Mono", monospace;
}

.rich-editor pre {
    padding: 12px;
    white-space: pre-wrap;
}

.rich-editor table {
    margin: 10px 0;
}

.rich-editor td,
.rich-editor th {
    border: 1px solid var(--line);
    min-width: 120px;
}

.note-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

@media (max-width: 900px) {
    .drive-layout,
    .share-form {
        grid-template-columns: 1fr;
    }

    .drive-sidebar {
        position: static;
    }

    .notes-list {
        max-height: none;
    }

    .rich-editor {
        min-height: 320px;
        max-height: none;
    }

    .drive-toolbar {
        display: grid;
    }

    .toolbar-meta {
        padding-top: 0;
    }

    .toolbar-actions {
        justify-items: stretch;
    }

    .folder-actions,
    .folder-actions[open] {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 700px) {
    .shell {
        width: min(100vw - 20px, 1440px);
        padding-top: 10px;
    }

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

    table,
    thead,
    tbody,
    tr,
    th,
    td {
        display: block;
    }

    th {
        display: none;
    }

    tr {
        border-top: 1px solid var(--line);
        padding: 10px 0;
    }

    td {
        border-top: 0;
        padding: 7px 12px;
    }

    .actions {
        text-align: left;
    }

    .action-group {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .link-field,
    .expiry-form input {
        width: 100%;
        max-width: none;
    }

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