/* ── Reset / Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-bg: #f4f6f9;
    --color-surface: #ffffff;
    --color-border: #dde2ea;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-danger: #dc2626;
    --color-success: #16a34a;
    --color-warning: #d97706;
    --color-muted: #6b7280;
    --color-text: #111827;
    --sidebar-width: 240px;
    --radius: 6px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--color-text);
    background: var(--color-bg);
    font-size: 14px;
    line-height: 1.5;
}

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

    a:hover {
        text-decoration: underline;
    }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: #1e293b;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px 16px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #334155;
}

.sidebar-logo {
    font-size: 20px;
}

.sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: #f1f5f9;
}

.nav-links {
    list-style: none;
    padding: 12px 0;
    flex: 1;
}

    .nav-links li a {
        display: block;
        padding: 8px 16px;
        color: #94a3b8;
        font-size: 13px;
        border-left: 3px solid transparent;
        transition: all .15s;
    }

        .nav-links li a:hover,
        .nav-links li a.active {
            color: #f1f5f9;
            background: #334155;
            border-left-color: var(--color-primary);
            text-decoration: none;
        }

.nav-section {
    padding: 16px 16px 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #475569;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid #334155;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sidebar-user {
    font-size: 12px;
    color: #94a3b8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-logout {
    background: none;
    border: 1px solid #475569;
    color: #94a3b8;
    padding: 4px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}

    .btn-logout:hover {
        background: #334155;
        color: #f1f5f9;
    }

/* ── Main content ──────────────────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 32px;
}

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

    .page-header h1 {
        font-size: 22px;
        font-weight: 600;
    }

.page-subtitle {
    color: var(--color-muted);
    font-size: 14px;
}

.back-link {
    font-size: 13px;
    color: var(--color-muted);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    padding: 7px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all .15s;
}

    .btn:hover {
        background: #f1f5f9;
        text-decoration: none;
    }

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

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

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

    .btn-danger:hover {
        background: #b91c1c;
        border-color: #b91c1c;
    }

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 640px;
}

.form-group {
    margin-bottom: 16px;
}

    .form-group label {
        display: block;
        font-size: 13px;
        font-weight: 500;
        margin-bottom: 5px;
    }

.form-control {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 14px;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border .15s;
}

    .form-control:focus {
        outline: none;
        border-color: var(--color-primary);
    }

textarea.form-control {
    resize: vertical;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check-input {
    width: auto;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
}

.form-hint {
    font-size: 12px;
    color: var(--color-muted);
    margin-top: 4px;
}

.field-error {
    font-size: 12px;
    color: var(--color-danger);
    display: block;
    margin-top: 3px;
}

.optional {
    font-weight: normal;
    color: var(--color-muted);
}

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

/* ── Tables ────────────────────────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

    .data-table th,
    .data-table td {
        padding: 10px 14px;
        text-align: left;
        border-bottom: 1px solid var(--color-border);
        font-size: 13px;
    }

    .data-table th {
        background: #f8fafc;
        font-weight: 600;
        color: var(--color-muted);
        font-size: 11px;
        text-transform: uppercase;
    }

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

    .data-table tr:hover td {
        background: #f8fafc;
    }

.actions {
    display: flex;
    gap: 6px;
    white-space: nowrap;
}

.url-truncate {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.badge-success {
    background: #dcfce7;
    color: #15803d;
}

.badge-warning {
    background: #fef9c3;
    color: #a16207;
}

.badge-info {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge-muted {
    background: #f1f5f9;
    color: var(--color-muted);
}

.badge-admin {
    background: #ede9fe;
    color: #6d28d9;
}

/* ── Stat cards ────────────────────────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 24px;
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--color-primary);
}

.stat-label {
    font-size: 13px;
    color: var(--color-muted);
    margin-top: 4px;
}

.stat-link {
    display: inline-block;
    margin-top: 12px;
    font-size: 13px;
}

/* ── Document cards ────────────────────────────────────────────────────────── */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
}

.card-icon {
    font-size: 28px;
    padding: 20px 20px 0;
}

.card-body {
    padding: 12px 20px 0;
    flex: 1;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
}

.card-desc {
    font-size: 13px;
    color: var(--color-muted);
    margin-bottom: 8px;
}

.card-meta {
    font-size: 12px;
    color: var(--color-muted);
}

.card-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--color-border);
    margin-top: 16px;
}

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-muted);
}

/* ── Share view ────────────────────────────────────────────────────────────── */
.share-header {
    flex-direction: column;
    align-items: flex-start;
}

.share-desc {
    color: var(--color-muted);
    font-size: 14px;
    margin-top: 4px;
}

.share-meta {
    margin-top: 8px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.share-actions {
    margin-bottom: 24px;
}

.share-info-box {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    max-width: 600px;
}

    .share-info-box h3 {
        font-size: 15px;
        font-weight: 600;
        margin-bottom: 8px;
    }

    .share-info-box p {
        font-size: 14px;
        color: var(--color-muted);
        margin-bottom: 8px;
    }

/* ── Checkbox list ─────────────────────────────────────────────────────────── */
.checkbox-list {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 10px 14px;
    max-height: 200px;
    overflow-y: auto;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    font-size: 13px;
    cursor: pointer;
}

.text-muted {
    color: var(--color-muted);
}

/* ── Login page ────────────────────────────────────────────────────────────── */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--color-bg);
}

.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

.login-logo {
    font-size: 40px;
    text-align: center;
    margin-bottom: 12px;
}

.login-title {
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 13px;
    color: var(--color-muted);
    text-align: center;
    margin-bottom: 24px;
}

.login-card .form-group {
    margin-bottom: 14px;
}

.login-card .btn-block {
    margin-top: 20px;
    padding: 10px;
    font-size: 15px;
}

/* ── File browser ──────────────────────────────────────────────────────────── */
.file-browser {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.file-browser-bar {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--color-border);
    gap: 10px;
}

.breadcrumb {
    font-size: 13px;
    color: var(--color-muted);
    font-family: monospace;
}

.file-list {
    padding: 4px 0;
    min-height: 120px;
}

.file-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background .1s;
    border-bottom: 1px solid #f1f5f9;
}

    .file-row:last-child {
        border-bottom: none;
    }

    .file-row:hover {
        background: #f8fafc;
    }

    .file-row.folder .file-name {
        font-weight: 500;
    }

.file-icon {
    font-size: 16px;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.file-name {
    flex: 1;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-meta {
    font-size: 11px;
    color: var(--color-muted);
    white-space: nowrap;
    display: flex;
    gap: 12px;
}

.file-empty {
    padding: 40px;
    text-align: center;
    color: var(--color-muted);
    font-size: 13px;
}

.file-loading {
    padding: 40px;
    text-align: center;
    color: var(--color-muted);
    font-size: 13px;
}

/* ── Folder picker (share form) ────────────────────────────────────────────── */
.folder-picker {
    margin-bottom: 8px;
}

.folder-path-display {
    display: flex;
    align-items: center;
}

    .folder-path-display span {
        font-family: monospace;
        font-size: 13px;
        color: var(--color-text);
        background: #f8fafc;
        border: 1px solid var(--color-border);
        padding: 6px 10px;
        border-radius: var(--radius);
        flex: 1;
    }

.folder-browser {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-top: 8px;
    overflow: hidden;
}

.folder-browser-nav {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: #f8fafc;
    border-bottom: 1px solid var(--color-border);
}

.folder-list {
    max-height: 220px;
    overflow-y: auto;
}

.folder-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid #f1f5f9;
}

    .folder-item:hover {
        background: #f8fafc;
    }

    .folder-item:last-child {
        border-bottom: none;
    }

.folder-browser-footer {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--color-border);
    background: #f8fafc;
}

.alert-info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

/* ── Code block ────────────────────────────────────────────────────────────── */
.code-block {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-family: monospace;
    font-size: 12px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ── Nav badge ─────────────────────────────────────────────────────────────── */
.nav-badge {
    display: inline-block;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 6px;
    vertical-align: middle;
}

.alert-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #15803d;
}

/* ── Setup steps ───────────────────────────────────────────────────────────── */
.setup-steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 680px;
}

.step-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    display: flex;
    gap: 20px;
    padding: 24px;
    transition: opacity .2s;
}

.step-card-muted {
    opacity: .45;
    pointer-events: none;
}

.step-number {
    width: 32px;
    height: 32px;
    background: var(--color-primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
    margin-top: 2px;
}

.step-body {
    flex: 1;
}

    .step-body h2 {
        font-size: 16px;
        font-weight: 600;
        margin-bottom: 8px;
    }

.step-desc {
    font-size: 13px;
    color: var(--color-muted);
    margin-bottom: 16px;
    line-height: 1.6;
}

    .step-desc code {
        background: #f1f5f9;
        padding: 1px 5px;
        border-radius: 3px;
        font-size: 12px;
    }

/* ── Title page (redirect source type) ────────────────────────────────────── */
.title-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

.title-page-card {
    text-align: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 48px 40px;
    max-width: 480px;
    width: 100%;
}

.title-page-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.title-page-name {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
}

.title-page-desc {
    color: var(--color-muted);
    margin-bottom: 20px;
}

.title-page-meta {
    margin-bottom: 20px;
}

.btn-lg {
    padding: 12px 28px;
    font-size: 16px;
}

/* ── Google button ─────────────────────────────────────────────────────────── */
.btn-google {
    background: #fff;
    border: 1px solid #dadce0;
    color: #3c4043;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
}

    .btn-google:hover {
        background: #f8f9fa;
    }

.login-divider {
    text-align: center;
    margin: 16px 0;
    position: relative;
}

    .login-divider::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 0;
        right: 0;
        border-top: 1px solid var(--color-border);
    }

    .login-divider span {
        background: var(--color-surface);
        padding: 0 12px;
        position: relative;
        font-size: 12px;
        color: var(--color-muted);
    }

/* ── OAuth sign-in buttons ─────────────────────────────────────────────────── */
.oauth-buttons {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

.btn-oauth {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 14px;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    cursor: pointer;
    text-decoration: none;
    transition: background .15s;
}

.btn-google {
    background: #fff;
    color: #3c4043;
}

    .btn-google:hover {
        background: #f8f9fa;
        text-decoration: none;
    }

.btn-microsoft {
    background: #fff;
    color: #2d2d2d;
}

    .btn-microsoft:hover {
        background: #f3f3f3;
        text-decoration: none;
    }

/* ── Share access list (user edit) ─────────────────────────────────────────── */
.share-access-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.share-access-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    cursor: pointer;
    font-size: 13px;
    transition: background .1s;
}

    .share-access-item:hover {
        background: #f8fafc;
    }

.share-access-inactive {
    opacity: .6;
}

.share-access-item input[type="checkbox"] {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.share-access-icon {
    font-size: 15px;
    flex-shrink: 0;
}

.share-access-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Old/archived files ────────────────────────────────────────────────────── */
.file-row.old-item .file-name,
.file-row.old-item .file-meta,
.file-row.old-item .file-icon {
    color: #dc2626;
}

.file-row.old-item {
    opacity: .75;
}

/* ── README box ────────────────────────────────────────────────────────────── */
.readme-box {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}

.readme-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: #fef3c7;
    border-bottom: 1px solid #fcd34d;
    font-size: 13px;
    font-weight: 500;
    color: #92400e;
}

.readme-toggle {
    background: none;
    border: 1px solid #fcd34d;
    border-radius: 4px;
    padding: 2px 10px;
    font-size: 12px;
    color: #92400e;
    cursor: pointer;
}

    .readme-toggle:hover {
        background: #fde68a;
    }

.readme-content {
    padding: 14px 16px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 13px;
    line-height: 1.6;
    color: #78350f;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
    display: block;
}

/* ── Breadcrumb navigation ─────────────────────────────────────────────────── */
.crumb-item {
    font-size: 13px;
    color: var(--color-muted);
}

.crumb-link {
    color: var(--color-primary);
    text-decoration: none;
}

    .crumb-link:hover {
        text-decoration: underline;
    }

.crumb-current {
    color: var(--color-text);
    font-weight: 500;
}

.crumb-sep {
    margin: 0 5px;
    color: var(--color-muted);
    font-size: 12px;
}

/* ── Share link button inside README ───────────────────────────────────────── */
.readme-share-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    border: 1px solid #f59e0b;
    color: #92400e;
    padding: 4px 12px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    margin: 2px 4px;
    transition: background .15s;
}

    .readme-share-btn::before {
        content: '📁';
    }

    .readme-share-btn:hover {
        background: #fef3c7;
        text-decoration: none;
    }

/* ── Sidebar share items ───────────────────────────────────────────────────── */
.nav-share-icon {
    margin-right: 7px;
    font-size: 13px;
}

.nav-empty {
    padding: 8px 16px;
    font-size: 12px;
    color: #475569;
    font-style: italic;
}

/* ── Root path locked display ──────────────────────────────────────────────── */
.root-path-locked {
    background: #f8fafc;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 10px 14px;
}

.root-path-value {
    font-family: monospace;
    font-size: 13px;
    color: var(--color-text);
}
