/* ===== Variables ===== */
/* Light theme = defaults. Dark applied via [data-theme="dark"] or
   automatically when prefers-color-scheme: dark + no explicit override. */
:root {
    --bg:            #ffffff;
    --surface:       #f8f9fb;
    --surface2:      #eef0f5;
    --border:        #e2e5ec;
    --text:          #1a1d27;
    --muted:         #6b7280;
    --primary:       #6366f1;
    --primary-hover: #4f46e5;
    --success:       #10b981;
    --warning:       #f59e0b;
    --danger:        #ef4444;
    --danger-text:   #b91c1c;
    --draft-text:    #4f46e5;
    --backdrop:      rgba(0,0,0,0.4);
    --radius:        8px;
    --sidebar-w:     220px;
}

/* Auto theme — follow OS preference when user hasn't picked one */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:          #0f1117;
        --surface:     #1a1d27;
        --surface2:    #252836;
        --border:      #2d3148;
        --text:        #e2e8f0;
        --muted:       #8892a4;
        --danger-text: #fca5a5;
        --draft-text:  #818cf8;
        --backdrop:    rgba(0,0,0,0.7);
    }
}

/* Explicit overrides — win regardless of OS preference */
:root[data-theme="dark"] {
    --bg:          #0f1117;
    --surface:     #1a1d27;
    --surface2:    #252836;
    --border:      #2d3148;
    --text:        #e2e8f0;
    --muted:       #8892a4;
    --danger-text: #fca5a5;
    --draft-text:  #818cf8;
    --backdrop:    rgba(0,0,0,0.7);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface2); padding: 2px 6px; border-radius: 4px; font-family: 'Cascadia Code', 'Fira Code', monospace; font-size: 12px; }
pre { white-space: pre-wrap; word-break: break-word; }
small { font-size: 12px; }

/* ===== Layout ===== */
.layout { display: flex; min-height: 100vh; }
.content { margin-left: var(--sidebar-w); padding: 32px 40px; flex: 1; max-width: 1100px; }
.loading { color: var(--muted); padding: 24px 0; }
.muted { color: var(--muted); }

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: fixed;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    z-index: 10;
}
.brand {
    padding: 0 20px 28px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--primary);
}
.sidebar ul { list-style: none; flex: 1; }
.sidebar ul li a {
    display: block;
    padding: 10px 20px;
    color: var(--muted);
    font-size: 14px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.sidebar ul li a:hover { color: var(--text); text-decoration: none; background: var(--surface2); }
.sidebar ul li a.active { color: var(--text); border-left-color: var(--primary); background: var(--surface2); }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); }

/* Current-user info block above the logout button */
.user-info { margin-bottom: 12px; }
.user-info-row   { display: flex; align-items: baseline; gap: 6px; margin-bottom: 4px; font-size: 13px; }
.user-info-key   { color: var(--muted); flex-shrink: 0; }
.user-info-value { color: var(--text); font-weight: 600; word-break: break-word; }
.user-info-role  { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.user-info-role.role-admin   { background: rgba(99,102,241,0.15); color: var(--primary); }
.user-info-role.role-manager { background: rgba(245,158,11,0.15); color: var(--warning); }
.user-info-role.role-viewer  { background: rgba(107,114,128,0.15); color: var(--muted); }

/* ===== Mobile responsiveness ===== */
@media (max-width: 768px) {
    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 12px 0;
    }
    .sidebar ul { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 12px; }
    .sidebar ul li a { padding: 6px 10px; border-left: none; border-radius: 4px; font-size: 13px; }
    .sidebar ul li a.active { background: var(--surface2); }
    .content { margin-left: 0; padding: 16px 20px; max-width: 100%; }
    .brand { padding: 0 16px 12px; font-size: 16px; }
    .sidebar-footer { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; flex-wrap: wrap; gap: 8px; }
    .user-info { margin-bottom: 0; flex: 1; min-width: 140px; }
    .layout { flex-direction: column; }
    .form-row { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .page-header h1 { font-size: 20px; }
    .table { font-size: 13px; }
    .table th, .table td { padding: 8px; }
    /* Horizontal scroll for wide tables instead of breaking layout */
    .table { display: block; overflow-x: auto; white-space: nowrap; }
}
.btn-logout {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 8px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    width: 100%;
    transition: all 0.15s;
}
.btn-logout:hover { color: var(--text); border-color: var(--text); }

/* ===== Page Header ===== */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; gap: 16px; }
.page-header h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.page-header-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ===== Breadcrumb ===== */
.breadcrumb { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--text); text-decoration: none; }

/* ===== Section Header ===== */
.section-header { display: flex; align-items: center; justify-content: space-between; margin: 28px 0 16px; }
.section-header h2 { font-size: 18px; font-weight: 600; }

/* ===== Buttons ===== */
.btn-primary {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: inline-block;
    transition: background 0.15s;
}
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary.btn-block { width: 100%; text-align: center; }

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 9px 18px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text); text-decoration: none; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    display: inline-block;
    transition: all 0.15s;
}
.btn-outline:hover { background: var(--primary); color: #fff; text-decoration: none; }

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

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 9px 18px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-danger:hover { background: #dc2626; }

.btn-danger-outline {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: 9px 18px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-danger-outline:hover { background: var(--danger); color: #fff; }

.btn-danger-sm {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-danger-sm:hover { background: var(--danger); color: #fff; }

/* ===== Table ===== */
.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left;
    padding: 10px 14px;
    color: var(--muted);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
}
.table td { padding: 13px 14px; border-bottom: 1px solid var(--border); }
.table tr:hover td { background: var(--surface2); }
.table tr:last-child td { border-bottom: none; }

/* ===== Badge ===== */
.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge.draft     { background: rgba(99,102,241,0.15); color: var(--draft-text); }
.badge.published { background: rgba(16,185,129,0.15); color: var(--success); }
.badge.archived  { background: rgba(107,114,128,0.15); color: var(--muted); }
.badge.mandatory { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge.channel-stable { background: rgba(16,185,129,0.1); color: var(--success); }
.badge.channel-beta   { background: rgba(245,158,11,0.1); color: var(--warning); }
.badge.channel-alpha  { background: rgba(239,68,68,0.1); color: var(--danger); }

/* ===== Card ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 20px;
}
.card h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

/* ===== Form ===== */
.field { margin-bottom: 16px; }
.field label, label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}
.hint { font-size: 11px; text-transform: none; letter-spacing: 0; color: var(--muted); margin-left: 6px; }
.field input, .field select, .field textarea,
input[type=text], input[type=password], select, textarea {
    display: block;
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
}
.field textarea, textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus,
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; text-transform: none; letter-spacing: 0; }
.checkbox-label input[type=checkbox] { width: auto; display: inline; }

/* ===== Stats ===== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 32px; }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
}
.stat-value { display: block; font-size: 36px; font-weight: 700; color: var(--primary); line-height: 1; }
.stat-label { display: block; color: var(--muted); font-size: 12px; margin-top: 6px; text-transform: uppercase; letter-spacing: 0.06em; }

/* ===== Login ===== */
.login-container { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 380px;
}
.login-brand { text-align: center; font-size: 22px; font-weight: 700; color: var(--primary); margin-bottom: 32px; letter-spacing: -0.02em; }

/* ===== API info ===== */
.api-info { margin-bottom: 24px; }
.api-info-title { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }
.api-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.api-method { font-size: 11px; font-weight: 600; color: var(--success); background: rgba(16,185,129,0.1); padding: 2px 8px; border-radius: 4px; flex-shrink: 0; }
.api-row code { font-size: 12px; word-break: break-all; }

/* ===== Release notes ===== */
.release-notes .release-notes-title { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }
.release-notes pre { color: var(--text); font-family: inherit; }

/* ===== Upload form ===== */
.upload-form { margin-bottom: 24px; }
.info { color: var(--warning); background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.3); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; font-size: 13px; }

/* ===== Error ===== */
.error {
    background: rgba(239,68,68,0.1);
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 14px;
    color: var(--danger-text);
    font-size: 13px;
}

/* ===== Empty state ===== */
.empty-state { text-align: center; padding: 48px 0; color: var(--muted); }
.empty-state a { margin-top: 16px; display: inline-block; }

/* ===== Modal ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    backdrop-filter: blur(2px);
}
.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    width: 500px;
    max-width: 90vw;
}
.modal-card h2 { margin-bottom: 8px; font-size: 18px; }
.modal-card p { color: var(--muted); margin-bottom: 20px; }

/* ===== Hash ===== */
.hash { font-size: 11px; cursor: help; }

/* ===== Markdown ===== */
.markdown-body { line-height: 1.7; }
.markdown-body h1,.markdown-body h2,.markdown-body h3 { margin: 16px 0 8px; font-weight: 600; }
.markdown-body h1 { font-size: 20px; }
.markdown-body h2 { font-size: 17px; }
.markdown-body h3 { font-size: 15px; }
.markdown-body p { margin-bottom: 10px; }
.markdown-body ul,.markdown-body ol { padding-left: 20px; margin-bottom: 10px; }
.markdown-body li { margin-bottom: 3px; }
.markdown-body code { background: var(--surface2); padding: 2px 5px; border-radius: 4px; font-size: 12px; }
.markdown-body pre { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; overflow-x: auto; margin-bottom: 10px; }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body a { color: var(--primary); }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.markdown-body blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--muted); margin: 0 0 10px; }

/* ===== Copy button ===== */
.btn-copy { background: none; border: 1px solid var(--border); border-radius: 4px; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 6px; margin-left: 6px; transition: color .15s, border-color .15s; }
.btn-copy:hover { color: var(--text); border-color: var(--primary); }
.api-row { display: flex; align-items: center; gap: 0; margin-bottom: 8px; }
.api-row code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Security page ===== */
.badge.danger  { background: rgba(239,68,68,0.15);  color: var(--danger); }
.badge.warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.ua-cell { display: block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; cursor: help; }

/* ===== Settings ===== */
.token-display { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.token-box { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-family: 'Cascadia Code','Fira Code',monospace; font-size: 13px; color: var(--text); word-break: break-all; }

/* ===== Preference rows (theme + language pickers) ===== */
.pref-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    gap: 16px;
}
.pref-row:last-child { border-bottom: none; }
.pref-row .pref-label { color: var(--text); font-size: 14px; font-weight: 500; }
.pref-row small { font-size: 12px; }
.pref-select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    width: 220px;
    flex-shrink: 0;
    cursor: pointer;
    transition: border-color 0.15s;
}
.pref-select:hover  { border-color: var(--primary); }
.pref-select:focus  { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }

/* ===== Nav search input ===== */
.nav-search {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
}
.nav-search:focus { outline: none; border-color: var(--primary); }

/* ===== Drag-and-drop file zone ===== */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    color: var(--muted);
    transition: all 0.15s;
    cursor: pointer;
}
.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background: rgba(99,102,241,0.05);
    color: var(--text);
}
.dropzone-icon { font-size: 28px; margin-bottom: 8px; }
.dropzone input[type=file] { display: none; }

/* ===== Bar chart (analytics) ===== */
.chart-bars { display: flex; align-items: flex-end; gap: 4px; height: 200px; padding-top: 12px; border-bottom: 1px solid var(--border); }
.chart-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.chart-bar { width: 100%; max-width: 32px; background: var(--primary); border-radius: 3px 3px 0 0; transition: opacity 0.15s; }
.chart-bar:hover { opacity: 0.85; }
.chart-bar-label { font-size: 10px; color: var(--muted); white-space: nowrap; }
