/*
 * Crony's design tokens and shared components. docs/brand/README.md explains the rules.
 * The one rule that shapes everything: color is reserved for status. The brand itself
 * is ink on paper, so a green, amber or red mark always means a check's state.
 * Page-specific styles live in site.css (public site) and app.css (dashboard).
 */

@font-face {
  font-family: "Geist";
  src: url("/fonts/geist-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Martian Mono";
  src: url("/fonts/martian-mono-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
}

:root {
  color-scheme: light;

  /* Ink and paper: cool neutrals. */
  --paper: #f5f6f8;
  --surface: #ffffff;
  --sunken: #eceef2;
  --line: #d9dde5;
  --line-strong: #b8bfcc;
  --ink: #10141c;
  --ink-soft: #3a4252;
  --muted: #5d6677;
  --on-ink: #ffffff;

  /* Status. Never used for decoration. */
  --up: #12885a;
  --up-bg: #e2f4ec;
  --late: #b86e00;
  --late-bg: #fbefd9;
  --down: #cf2f3a;
  --down-bg: #fbe4e5;
  --running: #2563d9;
  --running-bg: #e3ecfc;
  --idle: #6d7789; /* new and paused */
  --idle-bg: #e9ecf1;

  --font-text: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Martian Mono", ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  /* Type scale, 1.2 ratio on a 16px base. */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.2rem;
  --text-xl: 1.44rem;
  --text-2xl: 2.074rem;
  --text-3xl: 2.986rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4.5rem;

  --radius: 6px;
  --width: 68rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #0c0f14;
    --surface: #141920;
    --sunken: #0a0c10;
    --line: #262d39;
    --line-strong: #3b4454;
    --ink: #e9ecf1;
    --ink-soft: #c3c9d4;
    --muted: #96a0b1;
    --on-ink: #0c0f14;
    --up: #3cc88c;
    --up-bg: #10291f;
    --late: #f0a83e;
    --late-bg: #2e2210;
    --down: #f4656e;
    --down-bg: #331518;
    --running: #6ea4ff;
    --running-bg: #14223d;
    --idle: #8b95a7;
    --idle-bg: #1d232d;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0c0f14;
  --surface: #141920;
  --sunken: #0a0c10;
  --line: #262d39;
  --line-strong: #3b4454;
  --ink: #e9ecf1;
  --ink-soft: #c3c9d4;
  --muted: #96a0b1;
  --on-ink: #0c0f14;
  --up: #3cc88c;
  --up-bg: #10291f;
  --late: #f0a83e;
  --late-bg: #2e2210;
  --down: #f4656e;
  --down-bg: #331518;
  --running: #6ea4ff;
  --running-bg: #14223d;
  --idle: #8b95a7;
  --idle-bg: #1d232d;
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--text-md);
  line-height: 1.55;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
  text-wrap: balance;
  font-weight: 650;
  letter-spacing: -0.01em;
}
h1 {
  font-size: var(--text-2xl);
}
h2 {
  font-size: var(--text-xl);
}
h3 {
  font-size: var(--text-lg);
}
p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 0.18em;
}
a:hover {
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/*
 * The browser's own [hidden] rule loses to any author display rule, such as .btn's
 * inline-flex, so hidden elements would still show. This keeps hidden meaning hidden.
 */
[hidden] {
  /* biome-ignore lint/complexity/noImportantStyles: hidden must win over every display rule. */
  display: none !important;
}

code,
kbd,
pre,
.mono {
  font-family: var(--font-mono);
  font-size: 0.86em;
  font-variant-ligatures: none;
}
code {
  background: var(--sunken);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}
pre {
  margin: 0;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
  overflow-x: auto;
  line-height: 1.6;
}
pre code {
  background: none;
  padding: 0;
  font-size: 1em;
}

.wrap {
  max-width: var(--width);
  margin-inline: auto;
  padding-left: max(var(--space-4), env(safe-area-inset-left, 0px));
  padding-right: max(var(--space-4), env(safe-area-inset-right, 0px));
}

.muted {
  color: var(--muted);
}
.small {
  font-size: var(--text-sm);
}
.nums {
  font-variant-numeric: tabular-nums;
}

/* Header */
.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar .wrap {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  min-height: 3.5rem;
  flex-wrap: wrap;
}
.topbar nav {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  flex-wrap: wrap;
  margin-left: auto;
  font-size: var(--text-sm);
}
.topbar nav a {
  text-decoration: none;
  color: var(--ink-soft);
}
.topbar nav a:hover,
.topbar nav a[aria-current="page"] {
  color: var(--ink);
}

/* Logo: the mark plus the wordmark. */
.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.logo svg {
  height: 1.25em;
  width: auto;
  flex: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 2.25rem;
  padding: 0 var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover {
  border-color: var(--ink);
}
.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--on-ink);
}
.btn-primary:hover {
  opacity: 0.88;
}
.btn-danger {
  color: var(--down);
}
.btn-danger:hover {
  border-color: var(--down);
}
.btn-small {
  min-height: 1.75rem;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Forms */
label {
  font-size: var(--text-sm);
  font-weight: 550;
}
input[type="text"],
input[type="email"],
input[type="url"],
input[type="number"],
input[type="password"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: 2.25rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
}
textarea {
  min-height: 6rem;
  resize: vertical;
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline-offset: 0;
}
.field {
  display: grid;
  gap: var(--space-1);
}
.field .hint {
  font-size: var(--text-xs);
  color: var(--muted);
}
.field .error,
.form-error {
  font-size: var(--text-sm);
  color: var(--down);
}

/* Panels: used only where a group needs to read as one object. */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
th {
  text-align: left;
  font-weight: 550;
  color: var(--muted);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
tr:last-child > td {
  border-bottom: 0;
}
.table-scroll {
  overflow-x: auto;
}

/*
 * Status. A pill names the state in words, and the color repeats it, so the state
 * never depends on color alone.
 */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.15em 0.6em;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
  background: var(--idle-bg);
  color: var(--idle);
}
.status::before {
  content: "";
  width: 0.5em;
  height: 0.5em;
  border-radius: 50%;
  background: currentColor;
}
.status-up {
  background: var(--up-bg);
  color: var(--up);
}
.status-late {
  background: var(--late-bg);
  color: var(--late);
}
.status-down {
  background: var(--down-bg);
  color: var(--down);
}
.status-running {
  background: var(--running-bg);
  color: var(--running);
}
.status-paused::before {
  border-radius: 1px;
}
.status-new::before {
  background: none;
  box-shadow: inset 0 0 0 1.5px currentColor;
}

.tag {
  display: inline-block;
  padding: 0.05em 0.5em;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: var(--text-xs);
  color: var(--ink-soft);
}

.notice {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: var(--text-sm);
}
.notice-down {
  border-left-color: var(--down);
}
.notice-up {
  border-left-color: var(--up);
}

.footer {
  border-top: 1px solid var(--line);
  margin-top: var(--space-8);
  padding-block: var(--space-6);
  font-size: var(--text-sm);
  color: var(--muted);
}
.footer .wrap {
  display: flex;
  gap: var(--space-5);
  flex-wrap: wrap;
  justify-content: space-between;
}
.footer a {
  text-decoration: none;
}
.footer a:hover {
  text-decoration: underline;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * {
    /* biome-ignore lint/complexity/noImportantStyles: reduced motion must win over every component's motion. */
    animation: none !important;
    /* biome-ignore lint/complexity/noImportantStyles: as above. */
    transition: none !important;
  }
}
