:root {
    --bg: #ffffff;
    --bg2: #f8f9fa;
    --bg3: #f1f3f4;
    --bg4: #e8eaed;
    --border: #dadce0;
    --border2: #e8eaed;
    --accent: #3b82f6;
    --accent2: #60a5fa;
    --accent-g: #10b981;
    --accent-r: #ef4444;
    --accent-y: #f59e0b;
    --text: #202124;
    --text2: #5f6368;
    --text3: #80868b;
    --card: #ffffff;
    --mono: 'JetBrains Mono', monospace;
    --sans: 'Onest', 'Inter', 'Roboto', sans-serif;

    --bg-color: var(--bg);
    --surface: var(--bg2);
    --sidebar-bg: #f8f9fa;
    --sidebar-text: #5f6368;
    --sidebar-text-hover: #202124;
    --sidebar-text-active: #3b82f6;
    --sidebar-hover-bg: rgba(95, 99, 104, .08);
    --sidebar-active-bg: #e8f0fe;
    --sidebar-border: #dadce0;
    --text-color: var(--text);
    --muted: var(--text2);
    --primary-color: var(--accent);
    --danger: var(--accent-r);
    --danger-bg: #fce8e6;
    --success: var(--accent-g);
    --border-color: var(--border);
    --hover-color: var(--bg3);
    
    --radius: 12px;
    --radius: 12px;
}

[data-theme="dark"] {
    --bg: #1e1e1e;
    --bg2: #252526;
    --bg3: #2d2d30;
    --bg4: #3e3e42;
    --border: #333333;
    --border2: #404040;
    --text: #e0e0e0;
    --text2: #aaaaaa;
    --text3: #80868b;
    --card: #252526;
    
    --sidebar-bg: #1e1e1e;
    --sidebar-text: #aaaaaa;
    --sidebar-text-hover: #ffffff;
    --sidebar-hover-bg: rgba(255, 255, 255, .08);
    --sidebar-active-bg: rgba(59, 130, 246, 0.15);
    --sidebar-border: #333333;
    
    --danger-bg: rgba(239, 68, 68, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--sans);
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

.hidden {
    display: none !important;
}

/* Auth Shell */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg3);
}

.auth-container {
    background: var(--card);
    padding: 36px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    width: 100%;
    max-width: 420px;
}

.auth-brand {
    text-align: center;
    margin-bottom: 24px;
}

.auth-brand h1 {
    color: var(--primary-color);
    font-size: 28px;
    line-height: 1.2;
    margin-bottom: 6px;
}

.auth-brand p {
    color: var(--muted);
    font-size: 14px;
}

.input-group {
    display: block;
    margin-bottom: 16px;
}

.input-group label {
    display: block;
    font-size: 12px;
    margin-bottom: 6px;
    color: var(--muted);
    font-weight: 500;
}

.input-group input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    background: var(--bg-color);
    color: var(--text-color);
}

.input-group input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 10px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.btn:hover {
    background: #2563eb;
}

.btn.secondary {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

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

.full-width {
    width: 100%;
}

.status-line {
    color: var(--muted);
    font-size: 13px;
    min-height: 18px;
    margin-top: 12px;
    text-align: center;
}

.status-line.error { color: var(--danger); }
.status-line.success { color: var(--success); }

/* App Interface with Sidebar */
#app-interface {
    display: none;
    width: 100%;
    height: 100vh;
    flex-direction: row;
}

.sidebar {
    width: 270px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    font-size: 20px;
    font-weight: 700;
    color: var(--primary-color);
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-tabs {
    list-style: none;
    padding: 14px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    padding: 12px 22px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--sidebar-text);
    border-radius: 0 22px 22px 0;
    margin-right: 10px;
}

.nav-item:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-hover);
}

.nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-active);
}

.user-profile-box {
    padding: 15px 20px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 13px;
}

.logout-btn {
    cursor: pointer;
    color: var(--danger);
    font-weight: 600;
    border: none;
    background: transparent;
}

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-color);
    overflow-y: auto;
}

.tab-content {
    display: none;
    padding: 28px;
}

.tab-content.active {
    display: block;
}

.tab-title-area {
    margin-bottom: 20px;
}

.tab-title-area h2 {
    font-size: 22px;
    font-weight: 500;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 20px;
}

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

th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

th {
    color: var(--muted);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    background: var(--bg3);
}

tr:hover {
    background: var(--bg3);
}

.action-icon {
    cursor: pointer;
    color: var(--muted);
}
.action-icon:hover { color: var(--primary-color); }
.action-icon.delete:hover { color: var(--danger); }

/* File Drop Upload */
.file-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 32px 24px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;
    background: var(--bg-color);
}
.file-drop:hover {
    border-color: var(--primary-color);
    background: var(--sidebar-hover-bg);
}
.file-drop input[type="file"] {
    display: none;
}
.file-drop .file-drop-icon {
    font-size: 32px;
    color: var(--primary-color);
    margin-bottom: 8px;
}
.file-drop b {
    font-size: 15px;
    color: var(--text-color);
    margin-bottom: 4px;
}
.file-drop small {
    font-size: 13px;
    color: var(--muted);
}
.file-drop.selected {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.05);
}

/* File Viewer Iframe */
#viewer-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-color);
    z-index: 1000;
    flex-direction: column;
}

.viewer-header {
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    justify-content: space-between;
}

iframe {
    flex: 1;
    border: none;
    width: 100%;
    height: 100%;
    background: white;
}

/* Dropdown Menus */
.dropdown-menu {
    background: var(--card) !important;
    color: var(--text-color);
    animation: fadeIn 0.15s ease-out forwards;
}
.dropdown-menu.closing {
    animation: fadeOut 0.15s ease-in forwards;
}
.dropdown-item {
    transition: background 0.1s ease;
    color: var(--text-color);
}
.dropdown-item:hover {
    background: var(--sidebar-hover-bg);
}
.dropdown-item .material-icons {
    color: var(--muted) !important;
}
