/* ── CSS Variables ──────────────────────────────────────────────── */
:root {
    --color-bg:           #ffffff;
    --color-bg-secondary: #f4f4f5;
    --color-bg-hover:     #f0f0f1;
    --color-sidebar:      #18181b;
    --color-sidebar-text: #e4e4e7;
    --color-sidebar-muted:#a1a1aa;
    --color-sidebar-hover:#27272a;
    --color-accent:       #6366f1;
    --color-accent-hover: #4f46e5;
    --color-accent-light: #eef2ff;
    --color-text:         #18181b;
    --color-text-muted:   #71717a;
    --color-border:       #e4e4e7;
    --color-danger:       #ef4444;
    --color-success:      #22c55e;
    --color-warning:      #f59e0b;
    --color-shadow:       rgba(0,0,0,0.08);

    --sidebar-width:    240px;
    --list-panel-width: 300px;
    --radius:           8px;
    --radius-lg:        12px;
    --transition:       150ms ease;
    --font:             'Inter', system-ui, sans-serif;
}

[data-theme="dark"] {
    --color-bg:           #09090b;
    --color-bg-secondary: #18181b;
    --color-bg-hover:     #27272a;
    --color-sidebar:      #09090b;
    --color-sidebar-text: #e4e4e7;
    --color-sidebar-muted:#71717a;
    --color-sidebar-hover:#18181b;
    --color-text:         #fafafa;
    --color-text-muted:   #a1a1aa;
    --color-border:       #27272a;
    --color-shadow:       rgba(0,0,0,0.3);
    --color-accent-light: #1e1b4b;
}

/* ── Reset ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    height: 100%;
    overflow: hidden;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, textarea, select { font: inherit; }
ul, ol { list-style: none; }

/* ── Layout ──────────────────────────────────────────────────────── */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}
.main-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
}
.view {
    display: flex;
    height: 100%;
    overflow: hidden;
}
.hidden { display: none !important; }

/* ── List / Detail panels ────────────────────────────────────────── */
.list-panel {
    width: var(--list-panel-width);
    min-width: var(--list-panel-width);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-bg-secondary);
}
.list-panel-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.list-panel-header h2 {
    font-size: 16px;
    font-weight: 600;
}
.list-panel-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.detail-panel {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.detail-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    gap: 12px;
}
.detail-empty i { width: 48px; height: 48px; opacity: 0.3; }
.item-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition), opacity var(--transition);
    white-space: nowrap;
}
.btn-primary {
    background: var(--color-accent);
    color: #fff;
}
.btn-primary:hover { background: var(--color-accent-hover); }
.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}
.btn-ghost:hover, .btn-ghost.active {
    background: var(--color-bg-hover);
    color: var(--color-text);
}
.btn-danger {
    background: var(--color-danger);
    color: #fff;
}
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    color: var(--color-text-muted);
    transition: background var(--transition), color var(--transition);
}
.icon-btn:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}
.icon-btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    color: var(--color-text-muted);
    font-size: 12px;
}
.icon-btn-sm:hover {
    background: var(--color-bg-hover);
    color: var(--color-text);
}
.icon-btn i, .icon-btn-sm i { width: 16px; height: 16px; }

/* ── Form elements ───────────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 14px;
}
.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
}
.form-group input,
.form-group textarea,
.form-group select {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.select-sm {
    padding: 4px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 12px;
    outline: none;
    cursor: pointer;
}

/* ── Auth screen ─────────────────────────────────────────────────── */
.auth-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-secondary);
    z-index: 1000;
}
.auth-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 4px 24px var(--color-shadow);
}
.auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 700;
    color: var(--color-accent);
    margin-bottom: 32px;
    justify-content: center;
}
.auth-logo i { width: 28px; height: 28px; }
.auth-form h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}
.auth-subtitle {
    color: var(--color-text-muted);
    margin-bottom: 24px;
    font-size: 13px;
}
.auth-error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: var(--radius);
    padding: 8px 12px;
    color: var(--color-danger);
    font-size: 13px;
    margin-bottom: 14px;
}
[data-theme="dark"] .auth-error {
    background: #450a0a;
    border-color: #7f1d1d;
}
.auth-switch {
    text-align: center;
    font-size: 13px;
    color: var(--color-text-muted);
    margin-top: 16px;
}
.auth-switch a {
    color: var(--color-accent);
    font-weight: 500;
}
.auth-switch a:hover { text-decoration: underline; }

/* ── Modals ──────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    padding: 20px;
    backdrop-filter: blur(2px);
}
.modal {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: 0 16px 48px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modal-in 150ms ease;
}
@keyframes modal-in {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}

/* ── Toasts ──────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9999;
}
.toast {
    background: var(--color-text);
    color: var(--color-bg);
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: toast-in 200ms ease;
    max-width: 300px;
}
.toast.toast-error {
    background: var(--color-danger);
    color: #fff;
}
.toast.toast-success {
    background: var(--color-success);
    color: #fff;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Search overlay ──────────────────────────────────────────────── */
.search-overlay {
    position: fixed;
    inset: 0;
    z-index: 800;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 80px;
}
.search-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
}
.search-modal {
    position: relative;
    z-index: 1;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.2);
    overflow: hidden;
}
.search-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border);
}
.search-input-wrap i { color: var(--color-text-muted); width: 18px; height: 18px; flex-shrink: 0; }
.search-input-wrap input {
    flex: 1;
    font-size: 16px;
    border: none;
    outline: none;
    background: transparent;
    color: var(--color-text);
}
.search-esc {
    font-size: 11px;
    padding: 2px 6px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-muted);
    background: var(--color-bg-secondary);
}
.search-results {
    max-height: 400px;
    overflow-y: auto;
    padding: 8px;
}
.search-result-group { margin-bottom: 12px; }
.search-result-group-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    padding: 4px 8px;
}
.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
}
.search-result-item:hover, .search-result-item.active {
    background: var(--color-bg-hover);
}
.search-result-item i { width: 16px; height: 16px; color: var(--color-text-muted); flex-shrink: 0; }
.search-result-title { font-weight: 500; font-size: 13px; }
.search-result-snippet { font-size: 12px; color: var(--color-text-muted); }
.search-empty {
    padding: 32px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 13px;
}

/* ── Tags ────────────────────────────────────────────────────────── */
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 500;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    cursor: pointer;
    white-space: nowrap;
}
.tag-chip .tag-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

/* ── Scrollbar styling ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ── Kbd ──────────────────────────────────────────────────────────── */
kbd {
    font-size: 11px;
    padding: 1px 5px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: var(--color-bg-secondary);
    color: var(--color-text-muted);
    font-family: monospace;
}

/* ── Color picker dots ───────────────────────────────────────────── */
.color-picker {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.color-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform var(--transition), border-color var(--transition);
}
.color-dot:hover, .color-dot.active {
    transform: scale(1.2);
    border-color: var(--color-text);
}

/* ── Responsive (mobile) ─────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: -100%; transition: left 0.2s ease; z-index: 200; }
    .sidebar.open { left: 0; }
    .list-panel { width: 100%; }
    .detail-panel { display: none; }
    .detail-panel.active { display: flex; position: fixed; inset: 0; z-index: 100; background: var(--color-bg); }
}
