/* ===== shadcn/ui inspired design system ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --background: #ffffff;
    --foreground: #09090b;
    --card: #ffffff;
    --card-foreground: #09090b;
    --primary: #18181b;
    --primary-foreground: #fafafa;
    --secondary: #f4f4f5;
    --secondary-foreground: #18181b;
    --muted: #f4f4f5;
    --muted-foreground: #71717a;
    --accent: #f4f4f5;
    --accent-foreground: #18181b;
    --destructive: #ef4444;
    --destructive-foreground: #fafafa;
    --success: #22c55e;
    --warning: #f59e0b;
    --border: #e4e4e7;
    --input: #e4e4e7;
    --ring: #18181b;
    --radius: 0.5rem;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 130%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--foreground);
    line-height: 1.6;
    min-height: 100vh;
    margin: 0;
}

/* ===== Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: 338px;
    border-right: 1px solid var(--border);
    background: var(--card);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 40;
}

.sidebar-header {
    padding: 1.25rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-foreground);
    flex-shrink: 0;
}

.sidebar-logo svg {
    width: 21px;
    height: 21px;
}

.sidebar-brand {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--foreground);
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.sidebar-section {
    margin-top: 1rem;
}

.sidebar-section:first-child {
    margin-top: 0;
}

.sidebar-section-label {
    padding: 0.5rem 0.75rem 0.375rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--muted-foreground);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.4375rem 0.75rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--muted-foreground);
    text-decoration: none;
    transition: all 0.1s ease;
}

.sidebar-link:hover {
    background: var(--accent);
    color: var(--accent-foreground);
}

.sidebar-link.active {
    background: var(--secondary);
    color: var(--foreground);
}

.sidebar-link svg {
    width: 21px;
    height: 21px;
    flex-shrink: 0;
    stroke-width: 1.75;
}

.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.4375rem 0.75rem;
    border-radius: 6px;
}

.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--muted-foreground);
    flex-shrink: 0;
}

.sidebar-user-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--foreground);
}

.app-main {
    flex: 1;
    margin-left: 338px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-main.no-sidebar {
    margin-left: 0;
}

/* Top bar */
.app-topbar {
    height: 68px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--card);
    position: sticky;
    top: 0;
    z-index: 30;
    flex-shrink: 0;
}

.topbar-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--foreground);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.app-content {
    flex: 1;
    padding: 1.5rem;
}

.app-content.compact {
    max-width: 936px;
    margin: 0 auto;
    width: 100%;
}

/* ===== Cards ===== */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card + .card {
    margin-top: 1rem;
}

.card-header {
    padding: 1.25rem 1.5rem 1rem;
    border-bottom: none;
    background: none;
}

.card-header.with-border {
    border-bottom: 1px solid var(--border);
    padding-bottom: 1.25rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--foreground);
    margin: 0;
    line-height: 1.4;
}

.card-description {
    font-size: 0.8125rem;
    color: var(--muted-foreground);
    margin-top: 0.125rem;
}

.card-body {
    padding: 0 1.5rem 1.5rem;
}

.card-header + .card-body {
    padding-top: 0;
}

.card-header.with-border + .card-body {
    padding-top: 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ===== Form elements ===== */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

label,
.form-label,
.label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--foreground);
    line-height: 1.2;
}

.form-input,
.input,
.form-control {
    width: 100%;
    height: 2.25rem;
    padding: 0 0.75rem;
    border: 1px solid var(--input);
    border-radius: 6px;
    font-size: 0.875rem;
    font-family: inherit;
    background: transparent;
    color: var(--foreground);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
}

.form-input:focus,
.input:focus,
.form-control:focus {
    border-color: var(--ring);
    box-shadow: 0 0 0 2px rgb(24 24 27 / 0.08);
}

.form-input::placeholder,
.input::placeholder,
.form-control::placeholder {
    color: var(--muted-foreground);
    opacity: 0.55;
}

.form-input[readonly],
.input[readonly],
.form-control[readonly] {
    background: var(--muted);
    cursor: default;
}

.form-input.is-invalid,
.input.is-invalid,
.form-input.field-error,
.input.field-error {
    border-color: var(--destructive);
    box-shadow: 0 0 0 2px rgb(239 68 68 / 0.08);
}

.form-text,
.form-hint {
    font-size: 0.75rem;
    color: var(--muted-foreground);
}

/* Bootstrap switch overrides */
.form-check-input {
    border-radius: 9999px !important;
}

.form-check-input:checked {
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
}

.form-check-input:focus {
    box-shadow: 0 0 0 2px rgb(24 24 27 / 0.08) !important;
    border-color: var(--ring) !important;
}

.form-check-label {
    font-size: 0.8125rem;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    white-space: nowrap;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: inherit;
    height: 2.25rem;
    padding: 0 0.875rem;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.1s ease;
    text-decoration: none;
    line-height: 1;
}

.btn:focus-visible {
    outline: 2px solid var(--ring);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-foreground);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: #27272a;
    border-color: #27272a;
    color: var(--primary-foreground);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--secondary-foreground);
    border-color: var(--secondary);
}

.btn-secondary:hover {
    background: #e4e4e7;
    color: var(--secondary-foreground);
}

.btn-outline,
.btn-outline-primary,
.btn-outline-secondary {
    background: var(--background);
    color: var(--foreground);
    border: 1px solid var(--input);
}

.btn-outline:hover,
.btn-outline-primary:hover,
.btn-outline-secondary:hover {
    background: var(--accent);
    color: var(--accent-foreground);
}

.btn-outline-danger {
    background: transparent;
    color: var(--destructive);
    border: 1px solid var(--destructive);
}

.btn-outline-danger:hover {
    background: #fef2f2;
    color: #991b1b;
}

.btn-outline-warning {
    background: transparent;
    color: #92400e;
    border: 1px solid var(--warning);
}

.btn-outline-warning:hover {
    background: #fffbeb;
}

.btn-outline-success {
    background: transparent;
    color: #166534;
    border: 1px solid var(--success);
}

.btn-outline-success:hover {
    background: #f0fdf4;
}

.btn-ghost {
    background: transparent;
    color: var(--foreground);
    border: none;
}

.btn-ghost:hover {
    background: var(--accent);
}

.btn-sm {
    height: 1.875rem;
    padding: 0 0.625rem;
    font-size: 0.75rem;
}

.btn-lg {
    height: 2.75rem;
    padding: 0 1.5rem;
    font-size: 0.875rem;
}

.btn:disabled,
.btn.searching {
    opacity: 0.5;
    pointer-events: none;
}

.btn-block {
    width: 100%;
}

.btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn-sm svg {
    width: 16px;
    height: 16px;
}

/* ===== Badge ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.0625rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 500;
    border-radius: 9999px;
    line-height: 1.6;
    border: 1px solid transparent;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
    border-color: #bbf7d0;
}

.badge-muted {
    background: var(--muted);
    color: var(--muted-foreground);
    border-color: var(--border);
}

/* ===== Tables ===== */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table, .table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
    margin: 0;
}

table th, .table th {
    padding: 0.625rem 0.875rem;
    text-align: left;
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--muted-foreground);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: var(--muted);
}

table td, .table td {
    padding: 0.625rem 0.875rem;
    border-bottom: 1px solid var(--border);
    color: var(--foreground);
    vertical-align: middle;
}

table tbody tr:last-child td,
.table tbody tr:last-child td {
    border-bottom: none;
}

table tbody tr:hover,
.table tbody tr:hover {
    background: #fafafa;
}

/* ===== Separator ===== */
.separator {
    position: relative;
    margin: 1rem 0;
    text-align: center;
}

.separator::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    border-top: 1px solid var(--border);
}

.separator span {
    position: relative;
    z-index: 1;
    display: inline-block;
    padding: 0 0.625rem;
    font-size: 0.75rem;
    color: var(--muted-foreground);
    background: var(--card);
}

/* ===== Alerts ===== */
.alert {
    padding: 0.625rem 0.875rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    border: 1px solid;
}

.alert-info, .alert-primary {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e40af;
}

.alert-success {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #166534;
}

.alert-warning {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}

.alert-danger {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

/* ===== Toast / Notification ===== */
.notification {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    transform: translateX(-50%) translateY(0.5rem);
    background: var(--foreground);
    color: var(--background);
    padding: 0.5rem 0.875rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 9999;
    max-width: 90vw;
}

.notification.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* ===== Flash messages ===== */
.flash-messages {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: min(90vw, 494px);
}

.flash-messages .alert {
    margin: 0;
    box-shadow: var(--shadow-md);
}

/* ===== HTTP Error ===== */
.http-error {
    display: none;
    margin-top: 0.75rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #fecaca;
    background: #fef2f2;
    border-radius: 6px;
    font-size: 0.8125rem;
}

.http-error .error-code {
    color: #991b1b;
    font-weight: 600;
}

.http-error .error-message {
    display: block;
    color: #7f1d1d;
    margin: 0;
}

/* ===== Validation ===== */
.error-message {
    display: none;
    margin-top: 0.25rem;
    color: var(--destructive);
    font-size: 0.75rem;
}

.validation-icon,
.split-validation-icon {
    color: var(--success);
}

.validation-icon.invalid,
.split-validation-icon.invalid {
    color: var(--destructive);
}

/* ===== Stats bar ===== */
.stats-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.375rem 0.625rem;
    border: 1px dashed var(--border);
    border-radius: 6px;
    background: var(--muted);
    font-size: 0.75rem;
    color: var(--muted-foreground);
}

/* ===== Copy icon ===== */
.copy-icon {
    cursor: pointer;
    color: var(--muted-foreground);
    transition: color 0.15s ease;
}

.copy-icon:hover {
    color: var(--foreground);
}

/* ===== Auth page ===== */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--muted);
}

.auth-card {
    width: 100%;
    max-width: 494px;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    margin-bottom: 1.5rem;
}

.auth-logo-icon {
    width: 47px;
    height: 47px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-foreground);
}

.auth-logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--foreground);
}

.auth-subtitle {
    text-align: center;
    font-size: 0.8125rem;
    color: var(--muted-foreground);
    margin-bottom: 1.5rem;
}

/* ===== Highlight ===== */
@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 0 0 rgb(34 197 94 / 0); }
    50% { box-shadow: 0 0 0 3px rgb(34 197 94 / 0.15); }
}

.highlight {
    animation: pulse-green 0.8s ease;
}

/* ===== Admin ===== */
.admin-panel .card-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 1.25rem;
}

.admin-panel .card-body {
    padding-top: 1.25rem;
}

/* ===== Code ===== */
pre {
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.625rem 0.875rem;
    font-size: 0.75rem;
    overflow-x: auto;
    margin: 0;
}

code {
    font-size: 0.75rem;
    background: var(--muted);
    padding: 0.0625rem 0.25rem;
    border-radius: 3px;
    font-family: 'Cascadia Code', 'Fira Code', 'SF Mono', monospace;
}

pre code {
    background: none;
    padding: 0;
}

/* ===== Spinner ===== */
.spinner-border-sm {
    width: 0.875rem;
    height: 0.875rem;
    border-width: 2px;
}

/* ===== Zoom control ===== */
.zoom-control {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-right: 0.5rem;
}

.zoom-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    background: var(--border);
    border-radius: 9999px;
    outline: none;
    cursor: pointer;
}

.zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid var(--background);
    box-shadow: 0 0 0 1px var(--border);
}

.zoom-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid var(--background);
    box-shadow: 0 0 0 1px var(--border);
}

.zoom-value {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--muted-foreground);
    min-width: 2.5em;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Zoom scaling applied to content */
.app-content {
    transform-origin: top center;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .app-sidebar {
        display: none;
    }

    .app-main {
        margin-left: 0 !important;
    }

    .app-content {
        padding: 1rem;
    }

    .card-body {
        padding: 0 1rem 1rem;
    }

    .card-header {
        padding: 1rem 1rem 0.75rem;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .table-responsive-stack td {
        display: block;
    }
}

/* ===== Grid helpers ===== */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* ===== Spacing ===== */
.space-y > * + * { margin-top: 0.75rem; }
.space-y-sm > * + * { margin-top: 0.5rem; }
.space-y-lg > * + * { margin-top: 1.25rem; }

/* ===== Page header ===== */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
}

.page-description {
    font-size: 0.8125rem;
    color: var(--muted-foreground);
    margin-top: 0.125rem;
}

/* ===== Util ===== */
.text-muted { color: var(--muted-foreground) !important; }
.text-uppercase { text-transform: uppercase; }
.position-relative { position: relative; }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.me-1 { margin-right: 0.25rem; }
.me-2 { margin-right: 0.5rem; }
.flex-grow-1 { flex-grow: 1; }
.text-center { text-align: center; }

/* Container override for bootstrap */
.container { max-width: 1480px; }
