/* === Theme Variables === */
:root {
    --color-surface: #ffffff;
    --color-muted: #f8fafc;
    --color-subtle: #f1f5f9;
    --color-text-default: #0f172a;
    --color-text-muted: #64748b;
    --color-text-subtle: #94a3b8;
    --color-border: #e2e8f0;
    --color-border-muted: #f1f5f9;
}

@view-transition { navigation: auto; }

.dark {
    --color-surface: #0f1117;
    --color-muted: #16181f;
    --color-subtle: #1c1e26;
    --color-text-default: #e2e8f0;
    --color-text-muted: #94a3b8;
    --color-text-subtle: #64748b;
    --color-border: #1e293b;
    --color-border-muted: #1a1f2e;
}

/* === Base Body === */
body {
    background-color: var(--color-muted);
    color: var(--color-text-default);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === Scrollbar === */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--color-subtle);
    border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--color-border);
}

/* === Selection === */
::selection {
    background: rgba(59, 130, 246, 0.2);
    color: var(--color-text-default);
}

/* === Autofill override === */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 30px var(--color-surface) inset !important;
    -webkit-text-fill-color: var(--color-text-default) !important;
}

/* === Semantic background/text/border === */
.bg-surface { background-color: var(--color-surface); }
.bg-muted { background-color: var(--color-muted); }
.bg-subtle { background-color: var(--color-subtle); }
.text-default { color: var(--color-text-default); }
.text-muted { color: var(--color-text-muted); }
.text-subtle { color: var(--color-text-subtle); }
.border-default { border-color: var(--color-border); }
.border-muted { border-color: var(--color-border-muted); }

/* === Buttons === */
.btn, .btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
    cursor: pointer;
    border: none;
    text-decoration: none;
    user-select: none;
}
.btn:focus, .btn-primary:focus, .btn-secondary:focus, .btn-danger:focus, .btn-ghost:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
}
.btn:active, .btn-primary:active, .btn-secondary:active, .btn-danger:active, .btn-ghost:active {
    transform: scale(0.98);
}
.btn-primary {
    background: #2563eb;
    color: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.btn-primary:hover {
    background: #1d4ed8;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text-default);
    border: 1px solid var(--color-border);
}
.btn-secondary:hover {
    background: var(--color-muted);
}
.btn-danger {
    background: #dc2626;
    color: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.btn-danger:hover {
    background: #b91c1c;
}
.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}
.btn-ghost:hover {
    color: var(--color-text-default);
    background: var(--color-muted);
}

/* === Inputs & Select === */
.input, .select {
    width: 100%;
    background: var(--color-surface);
    color: var(--color-text-default);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    transition: all 0.15s;
}
.input::placeholder {
    color: var(--color-text-subtle);
}
.input:focus, .select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.select {
    appearance: none;
    padding-right: 2.5rem;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    cursor: pointer;
}

/* === Cards === */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.card-hover {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: all 0.2s;
}
.card-hover:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transform: translateY(-2px);
}

/* === Badges === */
.badge, .badge-green, .badge-yellow, .badge-red, .badge-purple, .badge-blue, .badge-gray {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.625rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
}
.badge-green {
    background: #d1fae5;
    color: #047857;
}
.dark .badge-green {
    background: rgba(5, 150, 105, 0.2);
    color: #34d399;
}
.badge-yellow {
    background: #fef3c7;
    color: #b45309;
}
.dark .badge-yellow {
    background: rgba(217, 119, 6, 0.2);
    color: #fbbf24;
}
.badge-red {
    background: #fecaca;
    color: #b91c1c;
}
.dark .badge-red {
    background: rgba(220, 38, 38, 0.2);
    color: #f87171;
}
.badge-purple {
    background: #e9d5ff;
    color: #7c3aed;
}
.dark .badge-purple {
    background: rgba(124, 58, 237, 0.2);
    color: #a78bfa;
}
.badge-blue {
    background: #dbeafe;
    color: #1d4ed8;
}
.dark .badge-blue {
    background: rgba(37, 99, 235, 0.2);
    color: #60a5fa;
}
.badge-gray {
    background: var(--color-subtle);
    color: var(--color-text-muted);
}

/* === Flash Messages === */
.flash, .flash-info, .flash-error, .flash-success {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    border: 1px solid;
    animation: slideUp 0.3s ease-out;
}
.flash-success {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
}
.dark .flash-success {
    background: rgba(5, 150, 105, 0.1);
    border-color: rgba(5, 150, 105, 0.3);
    color: #6ee7b7;
}
.flash-error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}
.dark .flash-error {
    background: rgba(220, 38, 38, 0.1);
    border-color: rgba(220, 38, 38, 0.3);
    color: #fca5a5;
}
.flash-info {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e40af;
}
.dark .flash-info {
    background: rgba(37, 99, 235, 0.1);
    border-color: rgba(37, 99, 235, 0.3);
    color: #93c5fd;
}

.flash-dismissing {
    transition: all 0.3s ease;
}

/* === Sidebar === */
#sidebar.open {
    transform: translateX(0);
}

#sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-decoration: none;
    transition: all 0.15s;
}
.sidebar-link:hover {
    color: var(--color-text-default);
    background: var(--color-muted);
}
.sidebar-link-active {
    background: #eff6ff !important;
    color: #1d4ed8 !important;
}
.dark .sidebar-link-active {
    background: rgba(30, 64, 175, 0.2) !important;
    color: #60a5fa !important;
}

/* === Tables === */
.table-header {
    padding: 0.875rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}
.table-cell {
    padding: 0.875rem 1rem;
    font-size: 0.875rem;
    color: var(--color-text-default);
}
.table-row {
    border-top: 1px solid var(--color-border);
    transition: background 0.1s;
}
.table-row:hover {
    background: rgba(248, 250, 252, 0.5);
}
.dark .table-row:hover {
    background: rgba(22, 24, 31, 0.5);
}

/* === Animations === */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
.animate-fade-in { animation: fadeIn 0.2s ease-out; }
.animate-slide-up { animation: slideUp 0.3s ease-out; }
.animate-scale-in { animation: scaleIn 0.2s ease-out; }

/* === Searchable Select === */
.searchable-dropdown {
    position: absolute;
    z-index: 50;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.25rem;
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    background: var(--color-surface);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    max-height: 12rem;
    overflow-y: auto;
}
.dark .searchable-dropdown {
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.searchable-dropdown:not(.hidden) {
    animation: fadeIn 0.1s ease-out;
}
[data-searchable-option]:hover {
    background: var(--color-muted);
}
[data-searchable-option][data-searchable-active] {
    background: #eff6ff;
    color: #1d4ed8;
}
.dark [data-searchable-option][data-searchable-active] {
    background: rgba(30, 64, 175, 0.2);
    color: #60a5fa;
}

.richtext-wrapper {
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
}
.richtext-wrapper:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}
.richtext-toolbar {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    padding: 0.25rem 0.5rem;
    background: var(--color-muted);
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
}
.richtext-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.375rem;
    color: var(--color-text-muted);
    transition: all 0.15s;
    cursor: pointer;
}
.richtext-btn:hover {
    background: var(--color-surface);
    color: var(--color-text-default);
}
.richtext-btn:active {
    background: var(--color-border);
}
.richtext-divider {
    width: 1px;
    height: 1.25rem;
    background: var(--color-border);
    margin: 0 0.25rem;
    flex-shrink: 0;
}
.richtext-spacer {
    flex: 1;
}
.richtext-wrapper textarea {
    border: none !important;
    border-radius: 0 !important;
    resize: vertical;
    min-height: 100px;
}
.richtext-wrapper textarea:focus {
    box-shadow: none !important;
    outline: none !important;
}
.richtext-wrapper.richtext-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
    border-radius: 0;
    border: none;
}
.richtext-wrapper.richtext-fullscreen textarea {
    flex: 1;
    resize: none;
    height: auto !important;
    min-height: 0;
    padding: 1rem;
}
.richtext-autosave {
    position: absolute;
    bottom: 0.5rem;
    right: 0.75rem;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--color-text-subtle);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}
.richtext-autosave.show {
    opacity: 1;
}
.richtext-autosave .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.richtext-autosave .dot.saved {
    background: #22c55e;
}
.richtext-autosave .dot.unsaved {
    background: #eab308;
}
