/* =============================================================================
   Sodrak Design System — Unified Theme Tokens, Components & Utilities
   Imported by all templates. Single source of truth for the visual language.
   ============================================================================= */

/* ── Theme Tokens ───────────────────────────────────────────────────────────── */
:root {
    /* Palette — Dark (default) */
    --bg:            #0b0d14;
    --surface:       #161926;
    --surface-hover: #1f2436;
    --border:        #2b304a;
    --border-light:  #3b4266;
    --accent:        #4f8ef7;
    --accent-hover:  #3a7ae0;
    --accent-glow:   rgba(79, 142, 247, 0.20);
    --accent-purple: #7c3aed;
    --purple-glow:   rgba(124, 58, 237, 0.25);
    --text:          #f0f2f8;
    --text-secondary:#c0c5d8;
    --muted:         #8e95b3;
    --success:       #10b981;
    --warning:       #f59e0b;
    --danger:        #ef4444;

    /* Radii */
    --radius:        12px;
    --radius-sm:     8px;
    --radius-xs:     6px;

    /* Shadows */
    --shadow-sm:     0 2px 8px rgba(0,0,0,0.20);
    --shadow:        0 8px 30px rgba(0,0,0,0.35);
    --shadow-glow:   0 0 14px var(--accent-glow);

    /* Derived / Convenience */
    --input-bg:      rgba(255, 255, 255, 0.05);
    --modal-bg:      #161926;
    --header-height: 56px;

    /* Typography */
    --font-sans:     -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-mono:     SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
}

/* Light theme */
[data-theme="light"] {
    --bg:            #f4f6fa;
    --surface:       #ffffff;
    --surface-hover: #f0f3fa;
    --border:        #d9e0ee;
    --border-light:  #c5d0e6;
    --accent:        #2563eb;
    --accent-hover:  #1d4ed8;
    --accent-glow:   rgba(37, 99, 235, 0.15);
    --accent-purple: #7c3aed;
    --purple-glow:   rgba(124, 58, 237, 0.15);
    --text:          #111827;
    --text-secondary:#374151;
    --muted:         #6b7280;
    --success:       #059669;
    --warning:       #d97706;
    --danger:        #dc2626;
    --input-bg:      rgba(0, 0, 0, 0.04);
    --modal-bg:      #ffffff;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.25s ease, color 0.25s ease;
}

/* ── Scrollbars ─────────────────────────────────────────────────────────────── */
* {
    scrollbar-width: thin;
    scrollbar-color: #64748b #161926;
}
[data-theme="light"] * {
    scrollbar-color: #94a3b8 #f1f5f9;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: var(--bg); }
*::-webkit-scrollbar-thumb { background: var(--muted); border-radius: 5px; border: 2px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ── Shared Header ──────────────────────────────────────────────────────────── */
.s-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 1px 8px rgba(0,0,0,0.12);
    max-width: 100%;
}

.s-header-left, .s-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.s-header-brand {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.s-header-meta {
    font-size: 0.78rem;
    color: var(--muted);
    background: var(--input-bg);
    padding: 3px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.s-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: var(--radius-xs);
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    font-size: 0.84rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.18s ease;
    white-space: nowrap;
    line-height: 1.3;
}

.s-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.s-btn i { font-size: 0.9rem; }

/* Variants */
.s-btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.s-btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.s-btn-success {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}
.s-btn-success:hover {
    opacity: 0.9;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.s-btn-danger {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.35);
    color: var(--danger);
}
.s-btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
    color: #fff;
    border-color: var(--danger);
}

.s-btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--muted);
}
.s-btn-ghost:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border);
    transform: none;
    box-shadow: none;
}

/* Icon-only variant */
.s-btn-icon {
    padding: 7px;
    min-width: 34px;
    min-height: 34px;
}

/* Divider between button groups */
.s-header-divider {
    width: 1px;
    height: 22px;
    background: var(--border);
    flex-shrink: 0;
}

/* ── Status Badge ───────────────────────────────────────────────────────────── */
.s-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 10px;
    background: rgba(16, 185, 129, 0.12);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.s-status.offline {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.3);
}
.s-status.syncing {
    background: rgba(245, 158, 11, 0.12);
    color: var(--warning);
    border-color: rgba(245, 158, 11, 0.3);
}

/* ── Tag Pills ──────────────────────────────────────────────────────────────── */
.s-tag {
    background: rgba(79, 142, 247, 0.12);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 500;
}

/* ── Search Input ───────────────────────────────────────────────────────────── */
.s-search-wrap {
    position: relative;
}

.s-search-wrap i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    color: var(--muted);
    pointer-events: none;
}

.s-search {
    width: 100%;
    padding: 10px 14px 10px 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.s-search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.s-search::placeholder {
    color: var(--muted);
}

/* ── Section Titles ─────────────────────────────────────────────────────────── */
.s-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ── Card / Surface ─────────────────────────────────────────────────────────── */
.s-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    transition: all 0.15s ease;
}

.s-card:hover {
    border-color: var(--accent);
    background: var(--surface-hover);
}

.s-card.active {
    border-color: var(--accent);
    background: var(--accent-glow);
    box-shadow: inset 3px 0 0 var(--accent);
}

/* ── Note Content Body — Theme-Safe Wrapper ─────────────────────────────────
   Neutralises common inline styles from machine-generated notes so content
   remains readable in both dark and light themes. */
.note-content-body {
    color: var(--text);
    line-height: 1.65;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.note-content-body p { margin-bottom: 0.6rem; }
.note-content-body p:empty { display: none; }

.note-content-body ul, .note-content-body ol {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}

.note-content-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-xs);
    margin: 8px 0;
}

.note-content-body pre,
.note-content-body code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    border-radius: 4px;
}

.note-content-body code {
    background: var(--input-bg);
    padding: 2px 5px;
}

.note-content-body pre {
    background: var(--input-bg);
    padding: 12px;
    overflow-x: auto;
    margin-bottom: 0.75rem;
}

.note-content-body a {
    color: var(--accent);
    text-decoration: underline;
}
.note-content-body a:hover { color: var(--accent-hover); }

.note-content-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
}
.note-content-body th, .note-content-body td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    font-size: 0.88rem;
    text-align: left;
}
.note-content-body th {
    background: var(--input-bg);
    font-weight: 600;
}

/* ── Content Theme Safety (dark mode) ─────────────────────────────────── */
/* Override inline "color: black/dark" so text stays visible on dark bg */
:root:not([data-theme="light"]) .note-content-body [style*="color: #000"],
:root:not([data-theme="light"]) .note-content-body [style*="color: black"],
:root:not([data-theme="light"]) .note-content-body [style*="color: #111"],
:root:not([data-theme="light"]) .note-content-body [style*="color: #333"],
:root:not([data-theme="light"]) .note-content-body [style*="color:#000"],
:root:not([data-theme="light"]) .note-content-body [style*="color:#111"],
:root:not([data-theme="light"]) .note-content-body [style*="color:#333"] {
    color: var(--text) !important;
}

/* ── Content Theme Safety (light mode) ────────────────────────────────── */
/* Override inline "color: white/light" so text stays visible on light bg */
[data-theme="light"] .note-content-body [style*="color: #fff"],
[data-theme="light"] .note-content-body [style*="color: white"],
[data-theme="light"] .note-content-body [style*="color: #f0f2f8"],
[data-theme="light"] .note-content-body [style*="color:#fff"],
[data-theme="light"] .note-content-body [style*="color: #f0f"],
[data-theme="light"] .note-content-body [style*="color: inherit"] {
    color: var(--text) !important;
}

/* Fix background contrast in light mode */
[data-theme="light"] .note-content-body [style*="background: rgba(0,0,0,0.2"],
[data-theme="light"] .note-content-body [style*="background: rgba(0,0,0,0.25"],
[data-theme="light"] .note-content-body [style*="background: rgba(0,0,0,0.3"],
[data-theme="light"] .note-content-body [style*="background: rgba(0, 0, 0, 0.2"],
[data-theme="light"] .note-content-body [style*="background: rgba(0, 0, 0, 0.25"],
[data-theme="light"] .note-content-body [style*="background: rgba(0, 0, 0, 0.3"] {
    background: rgba(0,0,0,0.06) !important;
}
[data-theme="light"] .note-content-body [style*="background: rgba(0,0,0,0.15"],
[data-theme="light"] .note-content-body [style*="background: rgba(0, 0, 0, 0.15"] {
    background: rgba(0,0,0,0.04) !important;
}

/* Fix gradient headers in light mode */
[data-theme="light"] .note-content-body [style*="linear-gradient(135deg, #1e3c72"],
[data-theme="light"] .note-content-body [style*="linear-gradient(135deg, #1a2f5a"] {
    background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%) !important;
}

/* Fix border colors in light mode */
[data-theme="light"] .note-content-body [style*="border: 1px solid #444"],
[data-theme="light"] .note-content-body [style*="border-bottom: 1px solid #444"] {
    border-color: var(--border) !important;
}

/* Muted text safety */
[data-theme="light"] .note-content-body [style*="color: #bbb"],
[data-theme="light"] .note-content-body [style*="color: #aaa"],
[data-theme="light"] .note-content-body [style*="color: #999"],
[data-theme="light"] .note-content-body [style*="color: #888"],
[data-theme="light"] .note-content-body [style*="color:#bbb"],
[data-theme="light"] .note-content-body [style*="color:#aaa"],
[data-theme="light"] .note-content-body [style*="color:#999"],
[data-theme="light"] .note-content-body [style*="color:#888"] {
    color: var(--muted) !important;
}

/* ── Responsive: Mobile ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .s-header { padding: 0 12px; height: 48px; }
    .s-header-meta { display: none; }

    .s-btn span.s-btn-label { display: none; }
    .s-btn { padding: 7px; min-width: 34px; min-height: 34px; }
}

/* ── Responsive: Desktop cap ────────────────────────────────────────────────── */
@media (min-width: 1600px) {
    .s-header {
        padding: 0 calc((100% - 1560px) / 2 + 20px);
    }
}

/* ── User Dropdown ──────────────────────────────────────────────────────────── */
.s-user-menu {
    position: relative;
}

.s-user-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    min-width: 180px;
    z-index: 300;
    display: none;
    overflow: hidden;
}

.s-user-dropdown.open { display: block; }

.s-user-dropdown a,
.s-user-dropdown button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    font-size: 0.85rem;
    color: var(--text);
    background: none;
    border: none;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease;
    text-align: left;
}

.s-user-dropdown a:hover,
.s-user-dropdown button:hover {
    background: var(--surface-hover);
}

.s-user-dropdown .s-dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 2px 0;
}

.s-user-dropdown a.danger-item {
    color: var(--danger);
}
.s-user-dropdown a.danger-item:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* ── Settings Panel (collapsible) ───────────────────────────────────────────── */
.s-settings-panel {
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.s-settings-panel.collapsed {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.s-settings-panel:not(.collapsed) {
    max-height: 600px;
    padding: 16px 20px;
}

.s-settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

@media (max-width: 600px) {
    .s-settings-grid { grid-template-columns: 1fr; }
}

.s-settings-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 6px;
}

.s-settings-group textarea,
.s-settings-group input[type="text"],
.s-settings-group select {
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.85rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.2s;
}

.s-settings-group textarea:focus,
.s-settings-group input:focus,
.s-settings-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.s-settings-group textarea {
    resize: vertical;
    min-height: 60px;
    max-height: 150px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.45;
}

/* Toggle switch */
.s-toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.s-toggle input { opacity: 0; width: 0; height: 0; }

.s-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border);
    border-radius: 11px;
    transition: 0.2s;
}

.s-toggle-slider::before {
    content: "";
    position: absolute;
    height: 16px; width: 16px;
    left: 3px; bottom: 3px;
    background: var(--text);
    border-radius: 50%;
    transition: 0.2s;
}

.s-toggle input:checked + .s-toggle-slider { background: var(--accent); }
.s-toggle input:checked + .s-toggle-slider::before { transform: translateX(18px); }

/* ── Mobile Bottom Tab Bar ──────────────────────────────────────────────────── */
.s-mobile-tabs {
    display: none;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 6px 12px;
    gap: 6px;
    position: sticky;
    top: 48px;
    z-index: 95;
}

.s-mobile-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--radius-xs);
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.s-mobile-tab.active {
    background: var(--accent-glow);
    color: var(--accent);
    border-color: var(--accent);
}

@media (max-width: 768px) {
    .s-mobile-tabs { display: flex; }
}

/* ── Animations ─────────────────────────────────────────────────────────────── */
@keyframes s-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.s-fade-in { animation: s-fade-in 0.2s ease-out; }
