@import "tailwindcss";
@source "./**/*.{ts,tsx}";

@custom-variant dark (&:where([data-theme="dark"], [data-theme="dark"] *));

/* --ui-* avoids collisions with operational variables retained in styles.css. */
:root {
  --radius: 0.75rem;
  --ui-background: #fcfcfe;
  --ui-foreground: #1f2937;
  --ui-card: #ffffff;
  --ui-popover: #ffffff;
  --ui-secondary: #f4f5f9;
  --ui-muted: #f4f5f9;
  --ui-muted-foreground: #64748b;
  --ui-accent: #eef2ff;
  --ui-accent-foreground: #4338ca;
  --ui-destructive: #a83850;
  --ui-primary: #5146e5;
  --ui-primary-foreground: #ffffff;
  --ui-success: #1e7a4f;
  --ui-success-soft: #eaf8f1;
  --ui-warning: #9c6310;
  --ui-warning-soft: #fff6df;
  --ui-border: #e5e8f0;
  --ui-input: #e2e6ee;
  --ui-sidebar: #f8f9fc;
  --ui-shadow-card: 0 1px 2px rgb(16 24 40 / 0.04), 0 4px 16px rgb(16 24 40 / 0.06);
  --ui-shadow-dialog: 0 12px 32px rgb(16 24 40 / 0.12);
}

[data-theme="dark"] {
  color-scheme: dark;
  --ui-background: #0f1117;
  --ui-foreground: #e5e7eb;
  --ui-card: #161923;
  --ui-popover: #1b1f2b;
  --ui-secondary: #1f2330;
  --ui-muted: #1f2330;
  --ui-muted-foreground: #9aa3b2;
  --ui-accent: #242a45;
  --ui-accent-foreground: #c7c4ff;
  --ui-destructive: #f07a93;
  --ui-primary: #8b85ff;
  --ui-primary-foreground: #0f1117;
  --ui-success: #5fd49c;
  --ui-success-soft: #16301f;
  --ui-warning: #f0bf6a;
  --ui-warning-soft: #33280f;
  --ui-border: #262b38;
  --ui-input: #2c3242;
  --ui-sidebar: #12151d;
  --ui-shadow-card: 0 1px 2px rgb(0 0 0 / 0.12), 0 4px 16px rgb(0 0 0 / 0.16);
  --ui-shadow-dialog: 0 12px 32px rgb(0 0 0 / 0.32);
  /* Remaining operational styles use these legacy names until their views migrate. */
  --background: var(--ui-background);
  --foreground: var(--ui-foreground);
  --surface: var(--ui-card);
  --surface-soft: var(--ui-secondary);
  --surface-subtle: var(--ui-secondary);
  --surface-muted: var(--ui-muted);
  --surface-raised: var(--ui-popover);
  --border: var(--ui-border);
  --border-soft: var(--ui-border);
  --muted: var(--ui-muted-foreground);
  --muted-2: var(--ui-muted-foreground);
  --primary: var(--ui-primary);
  --primary-strong: var(--ui-primary);
  --primary-soft: var(--ui-accent);
  --primary-foreground: var(--ui-primary-foreground);
  --success: var(--ui-success);
  --success-soft: var(--ui-success-soft);
  --warning: var(--ui-warning);
  --warning-soft: var(--ui-warning-soft);
  --danger: var(--ui-destructive);
  --danger-soft: #f07a931a;
  --shadow-soft: 0 2px 12px rgba(0, 0, 0, 0.24);
  --shadow-float: 0 18px 50px rgba(0, 0, 0, 0.36);
}

@theme inline {
  --font-sans: "Inter", system-ui, sans-serif;
  --color-background: var(--ui-background);
  --color-foreground: var(--ui-foreground);
  --color-card: var(--ui-card);
  --color-card-foreground: var(--ui-foreground);
  --color-popover: var(--ui-popover);
  --color-popover-foreground: var(--ui-foreground);
  --color-primary: var(--ui-primary);
  --color-primary-foreground: var(--ui-primary-foreground);
  --color-secondary: var(--ui-secondary);
  --color-secondary-foreground: var(--ui-foreground);
  --color-muted: var(--ui-muted);
  --color-muted-foreground: var(--ui-muted-foreground);
  --color-accent: var(--ui-accent);
  --color-accent-foreground: var(--ui-accent-foreground);
  --color-destructive: var(--ui-destructive);
  --color-success: var(--ui-success);
  --color-success-soft: var(--ui-success-soft);
  --color-warning: var(--ui-warning);
  --color-warning-soft: var(--ui-warning-soft);
  --color-border: var(--ui-border);
  --color-input: var(--ui-input);
  --color-ring: var(--ui-primary);
  --color-sidebar: var(--ui-sidebar);
  --radius-sm: calc(var(--radius) - 6px);
  --radius-md: calc(var(--radius) - 4px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
  --shadow-card: var(--ui-shadow-card);
}

/* Every native <dialog>: a centred card on desktop (preflight's margin: 0 would pin it top-left) and a
   bottom sheet that slides up on mobile. The desktop rule has zero specificity so a screen can set its
   own width; the mobile rule wins over those widths so every sheet spans the screen. */
:where(dialog:modal) {
  inset: 0;
  width: min(32rem, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100dvh - 32px);
  margin: auto;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 20px;
  padding: 24px;
  border: 1px solid var(--ui-border);
  border-radius: calc(var(--radius) + 4px);
  background: var(--ui-popover);
  color: var(--ui-foreground);
  box-shadow: var(--ui-shadow-dialog);
}
dialog::backdrop { background: color-mix(in srgb, var(--ui-foreground) 20%, transparent); }
@media (max-width: 767px) {
  dialog:modal {
    inset: auto 0 0;
    width: 100%;
    max-width: none;
    max-height: 85dvh;
    margin: 0;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-radius: calc(var(--radius) + 4px) calc(var(--radius) + 4px) 0 0;
  }
  dialog { translate: 0 100%; transition: translate 220ms ease-out, overlay 220ms allow-discrete, display 220ms allow-discrete; }
  dialog[open] { translate: 0 0; }
  dialog::backdrop { opacity: 0; transition: opacity 220ms ease-out, overlay 220ms allow-discrete, display 220ms allow-discrete; }
  dialog[open]::backdrop { opacity: 1; }
  @starting-style {
    dialog[open] { translate: 0 100%; }
    dialog[open]::backdrop { opacity: 0; }
  }
}
@keyframes ui-sheet-up { from { translate: 0 100%; } }
@media (max-width: 767px) { [data-slot="dialog-content"][data-state="open"] { animation: ui-sheet-up 220ms ease-out; } }
@media (prefers-reduced-motion: reduce) {
  dialog, dialog::backdrop { transition: none; }
  [data-slot="dialog-content"][data-state="open"] { animation: none; }
}

/* Shell rules are unlayered so they override the operational stylesheet. */
.shell { grid-template-columns: 240px minmax(0, 1fr); background: var(--ui-background); color: var(--ui-foreground); }
.sidebar { background: var(--ui-sidebar); border-color: var(--ui-border); }
.sidebar-brand { background: transparent; padding-inline: 16px; }
.sidebar-brand .logo-tile { border-radius: 8px; box-shadow: none; }
.sidebar-brand-text strong { font-size: 14px; font-weight: 600; }
.sidebar-brand-text .muted { font-size: 12px; color: var(--ui-muted-foreground); }
.nav-section { padding: 12px 12px 0; }
.nav-title { padding: 4px 8px; color: var(--ui-muted-foreground); font-size: 12px; font-weight: 400; letter-spacing: 0; text-transform: none; }
.nav-link { min-height: 36px; padding: 6px 8px; border-radius: 8px; color: var(--ui-muted-foreground); font-size: 14px; font-weight: 500; }
.nav-link:hover, .nav-link.active { background: var(--ui-accent); color: var(--ui-accent-foreground); }
.sidebar-footer { padding: 12px; }
.topbar { background: var(--ui-background); border-color: var(--ui-border); backdrop-filter: none; padding-inline: 24px; }
.topbar-email { color: var(--ui-muted-foreground); }
.mobile-brand { display: none; }
.main-area { min-width: 0; }
.content { padding: 24px; }
.page-header { gap: 12px; margin-bottom: 20px; }
.page-title { font-size: 24px; font-weight: 600; letter-spacing: -0.025em; }
.page-kicker { margin-top: 4px; color: var(--ui-muted-foreground); font-size: 14px; }
.page-actions { gap: 8px; }
.empty-state, .permission-state { display: grid; justify-items: center; gap: 8px; padding: 40px 24px; background: var(--ui-card); border: 1px solid var(--ui-border); box-shadow: var(--ui-shadow-card); }
.empty-state h2, .permission-state h2 { margin: 0; font-size: 16px; font-weight: 600; }
.empty-state p, .permission-state p { margin: 0; color: var(--ui-muted-foreground); }
.metric-card[data-slot="card"] { background: var(--ui-card); border-color: var(--ui-border); box-shadow: var(--ui-shadow-card); }
.metric-card .metric-label { color: var(--ui-muted-foreground); font-size: 14px; font-weight: 400; letter-spacing: 0; text-transform: none; }
.metric-card .metric-value { font-size: 24px; font-weight: 600; }
.badge[data-slot="badge"] { min-height: 0; padding: 2px 8px; border: 0; border-radius: 6px; font-size: 12px; font-weight: 500; letter-spacing: 0; }
.theme-toggle { width: 36px; height: 36px; min-height: 36px; border: 0; background: transparent; color: var(--ui-foreground); }
.language-trigger { min-height: 36px; color: var(--ui-foreground); font-weight: 500; }
.language-menu-panel { position: relative; top: auto; right: auto; min-width: 206px; display: grid; gap: 4px; padding: 6px; border-color: var(--ui-border); background: var(--ui-popover); box-shadow: var(--ui-shadow-card); }
.language-option { display: flex; min-height: 36px; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 8px; font-size: 13px; }
.language-option.selected { background: var(--ui-accent); color: var(--ui-accent-foreground); font-weight: 500; }
.language-option.unavailable { color: var(--ui-muted-foreground); opacity: 0.7; }
.field [data-slot="label"] { font-size: 14px; font-weight: 500; }
.account-menu > summary { border: 0; border-radius: 8px; background: transparent; }
.account-menu > summary:hover { background: var(--ui-accent); }
.account-menu-panel { border-color: var(--ui-border); border-radius: 12px; background: var(--ui-popover); box-shadow: var(--ui-shadow-card); }
.account-menu:not([open]) > .account-menu-panel { display: none; }
.account-menu-header { border-color: var(--ui-border); }
.account-menu-header .muted { color: var(--ui-muted-foreground); }
.account-menu-link:hover { background: var(--ui-accent); }
.avatar[data-slot="avatar"] { border-radius: 999px; background: var(--ui-accent); color: var(--ui-accent-foreground); font-weight: 500; }
.avatar[data-slot="avatar"] [data-slot="avatar-fallback"] { background: transparent; }
.mobile-navigation-sheet { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.mobile-navigation-links { display: grid; max-height: 60dvh; gap: 4px; overflow-y: auto; padding-top: 16px; }
.mobile-navigation-links a { display: flex; min-height: 44px; align-items: center; gap: 12px; border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.mobile-navigation-links a.active, .mobile-navigation-links a:hover { background: var(--ui-accent); color: var(--ui-accent-foreground); }
.attendance-summary .data-table th:first-child { width: auto; }
.attendance-summary .data-table :is(th, td):not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.audit-table thead th { font-weight: 500; color: var(--ui-muted-foreground); text-transform: none; letter-spacing: 0; }
@media (max-width: 767px) {
  [data-slot="table-container"]:has(.audit-table) { overflow: visible; }
  .audit-table tbody tr { border-color: var(--ui-border); background: var(--ui-card); box-shadow: var(--ui-shadow-card); }
}

@media (max-width: 1023px) and (min-width: 768px) {
  .shell { grid-template-columns: 76px minmax(0, 1fr); }
  .nav-link { width: 48px; }
}

@media (max-width: 767px) {
  .shell { display: block; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  .sidebar { display: none; }
  .topbar { min-height: 56px; padding: 8px 16px; }
  .theme-toggle { width: 40px; height: 40px; min-height: 40px; }
  .language-trigger { min-height: 40px; }
  .topbar-context > :not(.mobile-brand) { display: none; }
  .mobile-brand { display: inline; font-size: 14px; font-weight: 600; }
  .account-menu-name { display: none; }
  .content, .content:has(.audit-table) { padding: 16px; }
  .page-header { padding: 0; }
  .page-title { font-size: 20px; }
  .mobile-tabs { grid-template-columns: repeat(var(--tab-count, 5), minmax(0, 1fr)); background: var(--ui-card); border-color: var(--ui-border); padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); }
  .mobile-tab { min-height: 48px; color: var(--ui-muted-foreground); border: 0; background: transparent; font-weight: 500; cursor: pointer; }
  .mobile-tab.active { background: transparent; color: var(--primary); }
}
