/* noteweaver — hand-rolled stylesheet, flexoki palette.
 *
 * Mirrors vial's approach: no CSS framework, a single top-level stylesheet,
 * design tokens as CSS custom properties. The flexoki palette
 * (https://stephango.com/flexoki) is declared once as raw colors, then mapped
 * to semantic tokens for light and dark.
 *
 * Theme mechanism (see web/src/theme.rs):
 *   - default (no [data-theme])         → light, but follows prefers-color-scheme
 *   - [data-theme="light"] / ["dark"]   → explicit override
 */

/* ── Flexoki raw palette (theme-independent) ─────────────────────────────── */
:root {
  --flexoki-paper: #fffcf0;
  --flexoki-base-50: #f2f0e5;
  --flexoki-base-100: #e6e4d9;
  --flexoki-base-150: #dad8ce;
  --flexoki-base-200: #cecdc3;
  --flexoki-base-300: #b7b5ac;
  --flexoki-base-400: #9f9d96;
  --flexoki-base-500: #878580;
  --flexoki-base-600: #6f6e69;
  --flexoki-base-700: #575653;
  --flexoki-base-800: #403e3c;
  --flexoki-base-850: #343331;
  --flexoki-base-900: #282726;
  --flexoki-base-950: #1c1b1a;
  --flexoki-black: #100f0f;

  --flexoki-red-400: #d14d41;
  --flexoki-red-600: #af3029;
  --flexoki-blue-400: #4385be;
  --flexoki-blue-600: #205ea6;
  --flexoki-green-600: #66800b;
  --flexoki-green-400: #879a39;
}

/* ── Semantic tokens: light (default) ────────────────────────────────────── */
:root {
  --nw-bg: var(--flexoki-paper);
  --nw-bg-elevated: var(--flexoki-base-50);
  --nw-surface: #ffffff;
  --nw-sidebar-bg: var(--flexoki-base-100);
  --nw-border: var(--flexoki-base-200);
  --nw-border-strong: var(--flexoki-base-300);

  --nw-text: var(--flexoki-black);
  --nw-text-muted: var(--flexoki-base-600);
  --nw-text-faint: var(--flexoki-base-500);

  --nw-accent: var(--flexoki-blue-600);
  --nw-accent-contrast: var(--flexoki-paper);
  --nw-accent-soft: rgba(32, 94, 166, 0.12);

  --nw-danger: var(--flexoki-red-600);
  --nw-danger-soft: rgba(175, 48, 41, 0.1);
  --nw-success: var(--flexoki-green-600);

  --nw-radius: 6px;
  --nw-radius-lg: 10px;
  --nw-shadow: 0 1px 2px rgba(16, 15, 15, 0.06), 0 4px 12px rgba(16, 15, 15, 0.06);
  --nw-font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --nw-font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo,
    Consolas, monospace;
}

/* Dark token block, shared by the explicit override and the system preference. */
:root[data-theme="dark"] {
  --nw-bg: var(--flexoki-black);
  --nw-bg-elevated: var(--flexoki-base-950);
  --nw-surface: var(--flexoki-base-900);
  --nw-sidebar-bg: var(--flexoki-base-950);
  --nw-border: var(--flexoki-base-800);
  --nw-border-strong: var(--flexoki-base-700);

  --nw-text: var(--flexoki-base-100);
  --nw-text-muted: var(--flexoki-base-400);
  --nw-text-faint: var(--flexoki-base-500);

  --nw-accent: var(--flexoki-blue-400);
  --nw-accent-contrast: var(--flexoki-black);
  --nw-accent-soft: rgba(67, 133, 190, 0.16);

  --nw-danger: var(--flexoki-red-400);
  --nw-danger-soft: rgba(209, 77, 65, 0.14);
  --nw-success: var(--flexoki-green-400);

  --nw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --nw-bg: var(--flexoki-black);
    --nw-bg-elevated: var(--flexoki-base-950);
    --nw-surface: var(--flexoki-base-900);
    --nw-sidebar-bg: var(--flexoki-base-950);
    --nw-border: var(--flexoki-base-800);
    --nw-border-strong: var(--flexoki-base-700);

    --nw-text: var(--flexoki-base-100);
    --nw-text-muted: var(--flexoki-base-400);
    --nw-text-faint: var(--flexoki-base-500);

    --nw-accent: var(--flexoki-blue-400);
    --nw-accent-contrast: var(--flexoki-black);
    --nw-accent-soft: rgba(67, 133, 190, 0.16);

    --nw-danger: var(--flexoki-red-400);
    --nw-danger-soft: rgba(209, 77, 65, 0.14);
    --nw-success: var(--flexoki-green-400);

    --nw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.5);
  }
}

/* ── Base elements ───────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--nw-bg);
  color: var(--nw-text);
  font-family: var(--nw-font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--nw-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  line-height: 1.25;
  font-weight: 600;
}

/* ── App shell: sidebar + content ────────────────────────────────────────── */
.nw-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.nw-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.25rem 1rem;
  background: var(--nw-sidebar-bg);
  border-right: 1px solid var(--nw-border);
}

.nw-brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  padding: 0.25rem 0.5rem;
}

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

.nw-nav-link {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: var(--nw-radius);
  color: var(--nw-text-muted);
  font-weight: 500;
}

.nw-nav-link:hover {
  background: var(--nw-accent-soft);
  color: var(--nw-text);
  text-decoration: none;
}

.nw-nav-link.active {
  background: var(--nw-accent-soft);
  color: var(--nw-accent);
}

.nw-sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.nw-user {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 0.5rem;
  color: var(--nw-text-muted);
  font-size: 0.85rem;
}

.nw-user-name {
  font-weight: 600;
  color: var(--nw-text);
}

.nw-badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: var(--nw-accent-soft);
  color: var(--nw-accent);
}

.nw-content {
  padding: 2rem 2.5rem;
  overflow: auto;
}

/* ── Generic page chrome ─────────────────────────────────────────────────── */
.nw-page {
  max-width: 820px;
}

.nw-page-header {
  margin-bottom: 1.25rem;
}

.nw-page-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.nw-muted {
  color: var(--nw-text-muted);
}

.nw-boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
  color: var(--nw-text-muted);
}

/* ── Forms & buttons ─────────────────────────────────────────────────────── */
.nw-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nw-field-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--nw-text-muted);
}

.nw-input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--nw-text);
  background: var(--nw-surface);
  border: 1px solid var(--nw-border-strong);
  border-radius: var(--nw-radius);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.nw-input:focus {
  outline: none;
  border-color: var(--nw-accent);
  box-shadow: 0 0 0 3px var(--nw-accent-soft);
}

.nw-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--nw-radius);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.nw-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.nw-button-primary {
  background: var(--nw-accent);
  color: var(--nw-accent-contrast);
}

.nw-button-primary:hover:not(:disabled) {
  filter: brightness(1.05);
}

.nw-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--nw-text-muted);
  cursor: pointer;
}

/* ── Admin: add-user form, feedback banner, user table ───────────────────── */
.nw-section {
  margin-top: 2rem;
}

.nw-section h2 {
  margin: 0 0 0.85rem;
  font-size: 1.1rem;
}

.nw-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 420px;
}

.nw-notice {
  padding: 0.55rem 0.7rem;
  border-radius: var(--nw-radius);
  font-size: 0.85rem;
}

.nw-notice--error {
  background: var(--nw-danger-soft);
  color: var(--nw-danger);
}

.nw-notice--success {
  background: var(--nw-bg-elevated);
  color: var(--nw-success);
  border: 1px solid var(--nw-success);
}

.nw-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.nw-table th,
.nw-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--nw-border);
}

.nw-table th {
  color: var(--nw-text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ── Theme toggle ────────────────────────────────────────────────────────── */
.nw-theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--nw-text-muted);
  background: var(--nw-surface);
  border: 1px solid var(--nw-border);
  border-radius: var(--nw-radius);
  cursor: pointer;
}

.nw-theme-toggle:hover {
  color: var(--nw-text);
  border-color: var(--nw-border-strong);
}

.nw-theme-icon {
  font-size: 0.95rem;
  line-height: 1;
}

/* ── Auth (login) ────────────────────────────────────────────────────────── */
.nw-auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1.5rem;
  background: var(--nw-bg-elevated);
}

.nw-auth-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 2rem 1.75rem;
  background: var(--nw-surface);
  border: 1px solid var(--nw-border);
  border-radius: var(--nw-radius-lg);
  box-shadow: var(--nw-shadow);
}

.nw-auth-title {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: -0.01em;
}

.nw-auth-subtitle {
  margin: -0.5rem 0 0.25rem;
  color: var(--nw-text-muted);
  font-size: 0.9rem;
}

.nw-error {
  padding: 0.55rem 0.7rem;
  border-radius: var(--nw-radius);
  background: var(--nw-danger-soft);
  color: var(--nw-danger);
  font-size: 0.85rem;
}

.nw-success {
  padding: 0.55rem 0.7rem;
  border-radius: var(--nw-radius);
  background: var(--nw-accent-soft);
  color: var(--nw-success);
  font-size: 0.85rem;
}

/* ── Settings page ───────────────────────────────────────────────────────── */
.nw-settings {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.nw-settings-section {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.5rem;
  background: var(--nw-surface);
  border: 1px solid var(--nw-border);
  border-radius: var(--nw-radius-lg);
  box-shadow: var(--nw-shadow);
}

.nw-section-head {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.nw-section-title {
  margin: 0;
  font-size: 1.1rem;
}

.nw-section-desc {
  margin: 0;
  color: var(--nw-text-muted);
  font-size: 0.85rem;
}

.nw-field-hint {
  color: var(--nw-text-faint);
  font-size: 0.78rem;
}

.nw-form-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Segmented control used by the theme picker. */
.nw-segmented {
  display: inline-flex;
  align-self: flex-start;
  padding: 0.2rem;
  gap: 0.2rem;
  background: var(--nw-bg-elevated);
  border: 1px solid var(--nw-border);
  border-radius: var(--nw-radius);
}

.nw-segmented-option {
  padding: 0.4rem 0.85rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--nw-text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: calc(var(--nw-radius) - 2px);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.nw-segmented-option:hover {
  color: var(--nw-text);
}

.nw-segmented-option.active {
  color: var(--nw-accent);
  background: var(--nw-surface);
  border-color: var(--nw-border-strong);
}

/* ── Small screens: collapse the sidebar above the content ───────────────── */
@media (max-width: 720px) {
  .nw-shell {
    grid-template-columns: 1fr;
  }

  .nw-sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--nw-border);
  }

  .nw-sidebar-footer {
    margin-top: 0;
    margin-left: auto;
    flex-direction: row;
    align-items: center;
  }

  .nw-content {
    padding: 1.5rem 1.25rem;
  }
}
