*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --border: #dce1e8;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --info-bg: #eff6ff;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

html {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    margin: 0;
    padding: 0;
}

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

a:hover {
    text-decoration: underline;
}

/* Top bar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    flex-wrap: wrap;
    gap: 8px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.logo {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.logo:hover {
    text-decoration: none;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-badge {
    font-size: 14px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.view-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
}

.view-meta {
    font-size: 13px;
    color: var(--text-muted);
}

/* Container */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px;
}

.view-container {
    max-width: 1200px;
}

.container h2 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 20px;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
}

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

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

.btn-outline {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}

.btn-outline:hover {
    background: var(--bg);
    color: var(--text);
}

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

.btn-block {
    display: block;
    width: 100%;
}

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

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-info {
    background: var(--info-bg);
    color: var(--primary);
    border: 1px solid #bfdbfe;
}

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

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 24px;
}

.login-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 40px 32px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    text-align: center;
}

.login-icon {
    font-size: 48px;
    margin-bottom: 8px;
}

.login-card h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

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

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

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text);
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.15s;
}

.form-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Share grid */
.share-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 12px;
}

.share-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s, transform 0.15s;
    text-decoration: none;
    color: var(--text);
}

.share-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
    text-decoration: none;
}

.share-icon {
    font-size: 40px;
    margin-bottom: 8px;
}

.share-name {
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    word-break: break-all;
    margin-bottom: 4px;
}

.share-size {
    font-size: 13px;
    color: var(--text-muted);
}

/* Breadcrumbs */
.breadcrumbs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 20px;
    font-size: 14px;
    color: var(--text-muted);
}

.breadcrumbs a {
    color: var(--primary);
}

.breadcrumbs .current {
    color: var(--text);
    font-weight: 600;
}

.breadcrumbs .sep {
    margin: 0 4px;
    color: var(--text-muted);
}

/* File table */
.file-table {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.file-table-header {
    display: grid;
    grid-template-columns: 1fr 100px 140px 100px;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.file-row {
    display: grid;
    grid-template-columns: 1fr 100px 140px 100px;
    gap: 8px;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    transition: background 0.1s;
}

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

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

.parent-row {
    text-decoration: none;
    color: var(--text);
}

.parent-row:hover {
    text-decoration: none;
}

.col-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-row .col-name a,
.file-row.parent-row {
    color: var(--text);
    text-decoration: none;
}

.file-row .col-name a:hover,
.file-row.parent-row:hover {
    color: var(--primary);
}

/* Viewable file link */
.view-link {
    color: var(--primary);
    text-decoration: none;
}

.view-link:hover {
    text-decoration: underline;
    color: var(--primary-hover);
}

.col-size {
    color: var(--text-muted);
    font-size: 13px;
}

.col-modified {
    color: var(--text-muted);
    font-size: 13px;
}

.col-action {
    text-align: right;
}

.item-count {
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

code {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 13px;
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
}

/* User menu */
.user-menu {
    position: relative;
    cursor: pointer;
}

.user-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    min-width: 160px;
    z-index: 100;
    margin-top: 4px;
    overflow: hidden;
}

.user-menu:hover .user-menu-dropdown,
.user-menu:focus-within .user-menu-dropdown {
    display: block;
}

.menu-link {
    display: block;
    padding: 10px 16px;
    font-size: 14px;
    color: var(--text);
    text-decoration: none;
    transition: background 0.1s;
}

.menu-link:hover {
    background: var(--bg);
    text-decoration: none;
}

/* Settings */
.settings-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
    max-width: 480px;
}

.settings-card h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
}

.settings-form .btn-primary {
    margin-top: 8px;
}

/* View page */
.view-page .topbar {
    flex-wrap: wrap;
}

.image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.image-container img {
    max-width: 100%;
    max-height: 85vh;
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.view-page.pdf-view {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 0;
    margin: 0;
    max-width: 100vw;
    overflow: hidden;
}

.view-page.pdf-view .topbar {
    flex-shrink: 0;
    padding: 8px 16px;
}

.pdf-container {
    flex: 1;
    padding: 0;
    margin: 0;
    display: flex;
    min-height: 0;
}

.pdf-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.media-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.audio-player {
    text-align: center;
}

.audio-icon {
    font-size: 64px;
}

.audio-filename {
    font-size: 16px;
    font-weight: 500;
    margin-top: 8px;
    color: var(--text);
}

/* Text viewer (standalone page) */
.text-viewer {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    font-size: 13px;
    line-height: 1.6;
    white-space: pre;
    overflow-x: auto;
    margin: 0;
    padding: 0;
    color: #e2e8f0;
    background: #1e293b;
    border-radius: var(--radius);
    padding: 20px;
    max-height: 80vh;
    overflow-y: auto;
    width: 100%;
}

.text-viewer code {
    background: none;
    padding: 0;
    border-radius: 0;
}

/* Badge */
.badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    vertical-align: middle;
    margin-left: 6px;
}

.badge.user {
    background: var(--text-muted);
}

.badge.admin {
    background: var(--primary);
}

/* User cards */
.user-cards {
    display: grid;
    gap: 12px;
    margin-bottom: 24px;
}

.user-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.user-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.user-card-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-card-name {
    font-size: 15px;
    font-weight: 600;
}

.user-card-header .btn + .btn {
    margin-left: 4px;
}

.user-card-body {
    padding: 14px 20px;
}

.user-card-note {
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}

.share-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    display: inline-block;
    padding: 2px 10px;
    font-size: 12px;
    background: var(--info-bg);
    color: var(--primary);
    border-radius: 12px;
    font-weight: 500;
}

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

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

/* Checkbox group */
.checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: normal;
    margin-bottom: 0;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

/* Select dropdown */
select {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    background: var(--surface);
    transition: border-color 0.15s;
    cursor: pointer;
}

select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Create user card */
.create-user-card {
    border-left: 3px solid var(--primary);
}

.form-note {
    font-size: 13px;
    color: var(--text-muted);
    padding: 8px 0;
}

/* Responsive */
@media (max-width: 768px) {
    .file-table-header,
    .file-row {
        grid-template-columns: 1fr 80px 100px;
    }

    .col-modified {
        display: none;
    }

    .col-action {
        text-align: right;
    }

    .col-action .btn {
        padding: 4px 8px;
        font-size: 12px;
    }

    .topbar-left {
        flex-wrap: wrap;
    }

    .view-meta {
        display: none;
    }
}
