/*
 * shadcn/ui design system, as plain CSS.
 *
 * The component library itself is React + Radix + Tailwind. This app is Blade with no
 * build step, so what is ported here is the design system rather than the components:
 * the same OKLCH token palette, the same radius scale, the same focus-ring treatment
 * and the same component recipes (card, button, input, badge, table, alert, tabs).
 * The result matches shadcn visually without putting an npm build in the deploy path.
 *
 * If this ever moves to Inertia + React, these class names map one-to-one onto the real
 * components and the markup barely changes.
 */

/* ---- tokens: shadcn "neutral" ------------------------------------------- */

:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --accent: oklch(0.97 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --destructive-foreground: oklch(0.985 0 0);
  --success: oklch(0.596 0.145 163.225);
  --success-foreground: oklch(0.985 0 0);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);
  --radius: 0.625rem;

  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);

  --shadow-xs: 0 1px 2px 0 oklch(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 oklch(0 0 0 / 0.1), 0 1px 2px -1px oklch(0 0 0 / 0.1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: oklch(0.145 0 0);
    --foreground: oklch(0.985 0 0);
    --card: oklch(0.205 0 0);
    --card-foreground: oklch(0.985 0 0);
    --primary: oklch(0.922 0 0);
    --primary-foreground: oklch(0.205 0 0);
    --secondary: oklch(0.269 0 0);
    --secondary-foreground: oklch(0.985 0 0);
    --muted: oklch(0.269 0 0);
    --muted-foreground: oklch(0.708 0 0);
    --accent: oklch(0.269 0 0);
    --accent-foreground: oklch(0.985 0 0);
    --destructive: oklch(0.704 0.191 22.216);
    --destructive-foreground: oklch(0.985 0 0);
    --success: oklch(0.696 0.17 162.48);
    --border: oklch(1 0 0 / 0.12);
    --input: oklch(1 0 0 / 0.16);
    --ring: oklch(0.556 0 0);

    color-scheme: dark;
  }
}

/* ---- base --------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }

a { color: inherit; }

.muted { color: var(--muted-foreground); }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.8125rem; }
.strong { font-weight: 600; }
.tabular { font-variant-numeric: tabular-nums; }

/* Every interactive element gets the same ring, which is most of what makes a UI feel
   coherent — and it is the piece hand-rolled admin CSS almost always omits. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 50%, transparent);
  border-color: var(--ring);
}

/* ---- layout ------------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  height: 3.5rem;
  padding: 0 1.25rem;
  background: color-mix(in oklch, var(--background) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.app-header .brand {
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-right: 1rem;
  text-decoration: none;
  white-space: nowrap;
}

.app-header .spacer { flex: 1; }

.nav-link {
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-md);
  color: var(--muted-foreground);
  text-decoration: none;
  font-weight: 500;
  transition: background-color .12s, color .12s;
}
.nav-link:hover { background: var(--accent); color: var(--accent-foreground); }
.nav-link[aria-current="page"] { background: var(--accent); color: var(--accent-foreground); }

main { max-width: 1180px; margin: 1.75rem auto 4rem; padding: 0 1.25rem; }

.page-head { margin-bottom: 1.25rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; }
.inline { display: inline-flex; gap: 0.5rem; align-items: center; }

/* ---- card --------------------------------------------------------------- */

.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem 0;
}
.card-title { font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }
.card-description { color: var(--muted-foreground); font-size: 0.8125rem; margin-top: 0.15rem; }
.card-content { padding: 1.25rem 1.5rem; }
.card-footer {
  padding: 0.875rem 1.5rem;
  border-top: 1px solid var(--border);
  background: color-mix(in oklch, var(--muted) 45%, transparent);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  color: var(--muted-foreground);
  font-size: 0.75rem;
}

/* ---- button ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 2.25rem;
  padding: 0 0.875rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .12s, color .12s, border-color .12s, opacity .12s;
  background: var(--primary);
  color: var(--primary-foreground);
  box-shadow: var(--shadow-xs);
}
.btn:hover { background: color-mix(in oklch, var(--primary) 90%, var(--background)); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
  border-color: transparent;
}
.btn-secondary:hover { background: color-mix(in oklch, var(--secondary) 80%, var(--foreground) 4%); }

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

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

.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }

.btn-sm { height: 2rem; padding: 0 0.65rem; font-size: 0.8125rem; }

/* ---- form --------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 0.375rem; }

.label {
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1;
  color: var(--foreground);
}
.label .hint { font-weight: 400; color: var(--muted-foreground); }

.input, .select, .textarea {
  display: block;
  width: 100%;
  min-height: 2.25rem;
  padding: 0.4rem 0.7rem;
  font: inherit;
  color: var(--foreground);
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  transition: border-color .12s, box-shadow .12s;
}
.textarea { min-height: 4.5rem; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--muted-foreground); }

.select {
  appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
}
.select[multiple] { background-image: none; padding-right: 0.7rem; }

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--muted-foreground);
}
.checkbox-row input { accent-color: var(--primary); width: 1rem; height: 1rem; }

/* ---- badge -------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.35;
  white-space: nowrap;
}
.badge-secondary { background: var(--secondary); color: var(--secondary-foreground); border-color: transparent; }
.badge-outline { background: transparent; color: var(--muted-foreground); }
.badge-destructive { background: var(--destructive); color: var(--destructive-foreground); border-color: transparent; }
.badge-success { background: color-mix(in oklch, var(--success) 15%, var(--background)); color: var(--success); border-color: color-mix(in oklch, var(--success) 30%, transparent); }

.dot { width: 0.5rem; height: 0.5rem; border-radius: 999px; background: currentColor; }

/* ---- alert -------------------------------------------------------------- */

.alert {
  display: flex;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  background: var(--card);
}
.alert-title { font-weight: 500; }
.alert-success {
  border-color: color-mix(in oklch, var(--success) 35%, transparent);
  background: color-mix(in oklch, var(--success) 10%, var(--background));
  color: var(--foreground);
}
.alert-destructive {
  border-color: color-mix(in oklch, var(--destructive) 35%, transparent);
  background: color-mix(in oklch, var(--destructive) 8%, var(--background));
  color: var(--destructive);
}

/* ---- tabs --------------------------------------------------------------- */

.tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.25rem;
  background: var(--muted);
  border-radius: var(--radius-lg);
  margin-bottom: 1.25rem;
}
.tab {
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-md);
  color: var(--muted-foreground);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.8125rem;
  transition: background-color .12s, color .12s, box-shadow .12s;
}
.tab:hover { color: var(--foreground); }
.tab[aria-selected="true"] {
  background: var(--background);
  color: var(--foreground);
  box-shadow: var(--shadow-xs);
}

/* ---- table -------------------------------------------------------------- */

.table-wrap { width: 100%; overflow-x: auto; }

table.table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
table.table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted-foreground);
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
table.table tbody tr:hover { background: color-mix(in oklch, var(--muted) 55%, transparent); }
table.table tbody tr:last-child td { border-bottom: 0; }

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Category headers in the item report — Royce counts stock off these, so the grouping
   has to read as a break in the list, not as another row. */
table.table tr.group td {
  font-weight: 600;
  background: var(--muted);
  color: var(--foreground);
}
table.table tr.group:hover td { background: var(--muted); }

table.table tfoot tr.total td {
  font-weight: 600;
  border-top: 1px solid var(--foreground);
  border-bottom: 0;
  background: transparent;
}

.indent-1 td:first-child { padding-left: 1.9rem; }
.indent-2 td:first-child { padding-left: 3.1rem; color: var(--muted-foreground); }

/* ---- key/value (Sales Summary) ------------------------------------------ */

.kv {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid color-mix(in oklch, var(--border) 60%, transparent);
}
.kv:last-child { border-bottom: 0; }
.kv.rule { border-top: 1px solid var(--foreground); margin-top: 0.5rem; padding-top: 0.7rem; }
.kv .sub { display: block; font-size: 0.75rem; color: var(--muted-foreground); }
.kv .val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.kv.em { font-weight: 600; font-size: 0.9375rem; }

/* ---- misc --------------------------------------------------------------- */

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted-foreground); }

/* A schedule name is an identifier people scan for; wrapping it to four lines makes the
   table unreadable. The recipient list is the one that should give up width instead. */
.col-name { min-width: 11rem; }
.truncate { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.auth-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.auth-card { width: 100%; max-width: 24rem; }

@media (max-width: 640px) {
  .app-header { padding: 0 0.75rem; }
  .app-header .brand { margin-right: 0.35rem; }
  main { padding: 0 0.75rem; }
  .card-header, .card-content { padding-left: 1rem; padding-right: 1rem; }
  .row > .field { flex: 1 1 100%; }
}
