/* shadcn/ui-inspired stylesheet (HSL tokens, zinc neutrals, dark mode toggle) */

:root {
    --background: 0 0% 100%;
    --foreground: 240 10% 3.9%;
    --card: 0 0% 100%;
    --card-foreground: 240 10% 3.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 240 10% 3.9%;
    --primary: 240 5.9% 10%;
    --primary-foreground: 0 0% 98%;
    --secondary: 240 4.8% 95.9%;
    --secondary-foreground: 240 5.9% 10%;
    --muted: 240 4.8% 95.9%;
    --muted-foreground: 240 3.8% 46.1%;
    --accent: 240 4.8% 95.9%;
    --accent-foreground: 240 5.9% 10%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 0 0% 98%;
    --success: 142 71% 45%;
    --warning: 38 92% 50%;
    --border: 240 5.9% 90%;
    --input: 240 5.9% 90%;
    --ring: 240 5.9% 10%;
    --radius: 0.5rem;
}

html.dark {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --card: 240 10% 5.9%;
    --card-foreground: 0 0% 98%;
    --popover: 240 10% 3.9%;
    --popover-foreground: 0 0% 98%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --secondary: 240 3.7% 15.9%;
    --secondary-foreground: 0 0% 98%;
    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 64.9%;
    --accent: 240 3.7% 15.9%;
    --accent-foreground: 0 0% 98%;
    --destructive: 0 62.8% 50%;
    --destructive-foreground: 0 0% 98%;
    --success: 142 71% 45%;
    --warning: 38 92% 50%;
    --border: 240 3.7% 15.9%;
    --input: 240 3.7% 15.9%;
    --ring: 240 4.9% 83.9%;
}

* { box-sizing: border-box; }
*, *::before, *::after { border-color: hsl(var(--border)); }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: hsl(var(--background));
    color: hsl(var(--foreground));
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace; }
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; letter-spacing: -0.01em; color: hsl(var(--foreground)); }
h1 { font-size: 1.875rem; line-height: 2.25rem; letter-spacing: -0.025em; }
h2 { font-size: 1.5rem; line-height: 2rem; letter-spacing: -0.02em; }
h3 { font-size: 1.125rem; line-height: 1.75rem; }
p { margin: 0; color: hsl(var(--muted-foreground)); }

/* layout shell */
.app {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar {
    border-right: 1px solid hsl(var(--border));
    background: hsl(var(--card));
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.5rem 1rem;
    border-bottom: 1px solid hsl(var(--border));
    font-weight: 600;
    font-size: 0.95rem;
    color: hsl(var(--foreground));
}

.sidebar-brand .logo-dot {
    width: 28px; height: 28px;
    border-radius: 7px;
    background: linear-gradient(135deg, hsl(var(--primary)) 0%, hsl(var(--muted-foreground)) 100%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: hsl(var(--primary-foreground));
    font-size: 0.7rem;
    font-weight: 700;
}

.sidebar-brand small {
    color: hsl(var(--muted-foreground));
    font-weight: 500;
    font-size: 0.7rem;
    margin-left: auto;
    border: 1px solid hsl(var(--border));
    padding: 0.125rem 0.4rem;
    border-radius: 9999px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 0.125rem; flex: 1; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    color: hsl(var(--muted-foreground));
    font-weight: 500;
    font-size: 0.875rem;
    transition: background-color .15s ease, color .15s ease;
}
.nav-link:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.nav-link.active { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }
.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-link.danger { color: hsl(var(--destructive)); }
.nav-link.danger:hover { background: hsla(var(--destructive) / 0.1); color: hsl(var(--destructive)); }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 1.5rem;
    border-bottom: 1px solid hsl(var(--border));
    background: hsla(var(--background) / 0.85);
    backdrop-filter: saturate(180%) blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-title { font-weight: 500; font-size: 0.875rem; color: hsl(var(--muted-foreground)); }
.topbar-title strong { color: hsl(var(--foreground)); font-weight: 600; }

.content {
    padding: 1.5rem 2rem;
    max-width: 100%;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.5rem; line-height: 2rem; }
.page-header p { font-size: 0.875rem; margin-top: 0.25rem; }

/* Card */
.card {
    background: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.04);
}
.card-header { padding: 1.25rem 1.5rem 0.75rem; }
.card-content { padding: 1rem 1.5rem 1.25rem; }
.card-footer { padding: 0.75rem 1.5rem 1.25rem; display: flex; justify-content: flex-end; gap: 0.5rem; border-top: 1px solid hsl(var(--border)); }
.card-title { font-size: 1rem; font-weight: 600; line-height: 1.5; color: hsl(var(--card-foreground)); margin: 0; }
.card-description { font-size: 0.875rem; color: hsl(var(--muted-foreground)); margin-top: 0.25rem; }

/* Stat card */
.stat-card { padding: 1.25rem 1.5rem; }
.stat-card .label {
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.stat-card .label svg { width: 16px; height: 16px; color: hsl(var(--muted-foreground)); }
.stat-card .value { font-size: 1.875rem; font-weight: 700; line-height: 2.25rem; letter-spacing: -0.025em; }
.stat-card .hint { font-size: 0.75rem; color: hsl(var(--muted-foreground)); margin-top: 0.25rem; }

/* Grids */
.grid { display: grid; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
@media (max-width: 900px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

/* Form controls */
label.field-label { display: block; font-size: 0.875rem; font-weight: 500; color: hsl(var(--foreground)); margin-bottom: 0.5rem; }

.input, input[type="text"], input[type="password"], input[type="email"], input[type="number"], select, textarea {
    display: flex;
    width: 100%;
    height: 2.25rem;
    padding: 0 0.75rem;
    border-radius: calc(var(--radius) - 2px);
    border: 1px solid hsl(var(--input));
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-size: 0.875rem;
    line-height: 1.25rem;
    transition: border-color .15s ease, box-shadow .15s ease;
    font-family: inherit;
    margin: 0;
}
input::placeholder, textarea::placeholder { color: hsl(var(--muted-foreground)); }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 3px hsla(var(--ring) / 0.25);
}
input:read-only { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); cursor: default; }
input:disabled, select:disabled { opacity: 0.5; cursor: not-allowed; }

select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
    background-size: 12px;
    padding-right: 2rem;
    cursor: pointer;
}

.input-mono { font-family: ui-monospace, SFMono-Regular, monospace; letter-spacing: 0.02em; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 2.25rem;
    padding: 0 1rem;
    border-radius: calc(var(--radius) - 2px);
    border: 1px solid transparent;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25rem;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease;
    font-family: inherit;
    white-space: nowrap;
    user-select: none;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px hsla(var(--ring) / 0.25); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn-primary:hover { background: hsla(var(--primary) / 0.9); }

.btn-secondary { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); }
.btn-secondary:hover { background: hsla(var(--secondary) / 0.8); }

.btn-outline { background: transparent; border-color: hsl(var(--border)); color: hsl(var(--foreground)); }
.btn-outline:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }

.btn-ghost { background: transparent; color: hsl(var(--foreground)); }
.btn-ghost:hover { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); }

.btn-destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); }
.btn-destructive:hover { background: hsla(var(--destructive) / 0.9); }

.btn-link { background: transparent; color: hsl(var(--foreground)); text-decoration: underline; text-underline-offset: 4px; padding: 0; height: auto; }

.btn-sm { height: 1.75rem; padding: 0 0.625rem; font-size: 0.75rem; border-radius: calc(var(--radius) - 4px); }
.btn-lg { height: 2.5rem; padding: 0 2rem; font-size: 0.95rem; }
.btn-icon { padding: 0; width: 2.25rem; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1rem;
    border: 1px solid transparent;
    letter-spacing: 0.01em;
    white-space: nowrap;
}
.badge-default { background: hsl(var(--secondary)); color: hsl(var(--secondary-foreground)); border-color: hsl(var(--border)); }
.badge-success { background: hsla(var(--success) / 0.15); color: hsl(var(--success)); border-color: hsla(var(--success) / 0.25); }
.badge-warning { background: hsla(var(--warning) / 0.15); color: hsl(var(--warning)); border-color: hsla(var(--warning) / 0.25); }
.badge-destructive { background: hsla(var(--destructive) / 0.15); color: hsl(var(--destructive)); border-color: hsla(var(--destructive) / 0.25); }
.badge-info { background: hsla(217 91% 60% / 0.15); color: hsl(217 91% 64%); border-color: hsla(217 91% 60% / 0.25); }
.badge-outline { background: transparent; color: hsl(var(--muted-foreground)); border-color: hsl(var(--border)); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
    text-align: left;
    padding: 0.625rem 1rem;
    color: hsl(var(--muted-foreground));
    font-weight: 500;
    font-size: 0.75rem;
    background: hsl(var(--muted) / 0.4);
    border-bottom: 1px solid hsl(var(--border));
}
tbody td { padding: 0.75rem 1rem; border-top: 1px solid hsl(var(--border)); vertical-align: middle; }
tbody tr:hover td { background: hsl(var(--muted) / 0.3); }
.text-right { text-align: right; }

/* Alert */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    background: hsl(var(--card));
    font-size: 0.875rem;
    margin-bottom: 1rem;
}
.alert-destructive { border-color: hsla(var(--destructive) / 0.5); color: hsl(var(--destructive)); background: hsla(var(--destructive) / 0.06); }
.alert-success { border-color: hsla(var(--success) / 0.5); color: hsl(var(--success)); background: hsla(var(--success) / 0.06); }
.alert-warning { border-color: hsla(var(--warning) / 0.5); color: hsl(var(--warning)); background: hsla(var(--warning) / 0.06); }

/* Auth screen */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background:
        radial-gradient(60rem 25rem at 50% -10rem, hsla(var(--ring) / 0.08), transparent),
        hsl(var(--background));
}

.auth-card {
    width: 100%;
    max-width: 400px;
}
.auth-card .card-content { padding: 1.5rem; }
.auth-title { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; text-align: center; }
.auth-sub { text-align: center; margin-top: 0.25rem; margin-bottom: 1.5rem; color: hsl(var(--muted-foreground)); font-size: 0.875rem; }
.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    color: hsl(var(--foreground));
    font-weight: 600;
}
.auth-brand .logo-dot {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, hsl(var(--primary)) 0%, hsl(var(--muted-foreground)) 100%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: hsl(var(--primary-foreground));
    font-size: 0.8rem;
    font-weight: 700;
}

/* Utility */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.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-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: hsl(var(--muted-foreground)); }
.text-foreground { color: hsl(var(--foreground)); }
.text-mono { font-family: ui-monospace, SFMono-Regular, monospace; }
.w-full { width: 100%; }
.divider { height: 1px; background: hsl(var(--border)); margin: 1rem 0; }

/* Theme toggle */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2rem;
    width: 2rem;
    border-radius: calc(var(--radius) - 2px);
    border: 1px solid hsl(var(--border));
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    cursor: pointer;
}
.theme-toggle:hover { background: hsl(var(--accent)); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .icon-light { display: none; }
.theme-toggle .icon-dark { display: inline; }
html.dark .theme-toggle .icon-light { display: inline; }
html.dark .theme-toggle .icon-dark { display: none; }

/* Empty state */
.empty {
    text-align: center;
    padding: 3rem 1rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
}
.empty .empty-title { color: hsl(var(--foreground)); font-weight: 500; margin-bottom: 0.25rem; font-size: 0.9rem; }

hr { border: none; border-top: 1px solid hsl(var(--border)); margin: 1.5rem 0; }

@media (max-width: 800px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .content { padding: 1rem; }
}
