/* Captain Builders — shadcn/ui-flavored tokens (shared by platform + admin),
   light + dark. Token block mirrors apps/captain_cal (repo-wide design). */

:root {
  --background: #ffffff;
  --foreground: #0a0a0a;
  --card: #ffffff;
  --muted: #f5f5f5;
  --muted-foreground: #6b7280;
  --border: #e5e7eb;
  --primary: #0a0a0a;
  --primary-foreground: #fafafa;
  --accent: #2563eb;
  --ring: #2563eb;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 0.5rem;
  /* Native widgets (selects, scrollbars) need to know the theme. */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --background: #0a0a0a;
    --foreground: #e5e7eb;
    --card: #111214;
    --muted: #16181c;
    --muted-foreground: #9ca3af;
    --border: #262626;
    --primary: #e5e7eb;
    --primary-foreground: #0a0a0a;
    --accent: #60a5fa;
    --ring: #60a5fa;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* our display:flex rules must not defeat the hidden attribute */
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
  background: var(--background);
  color: var(--foreground);
}
button { font: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted-foreground); }

/* ---------- app shell: sidebar + content ---------- */

#app { display: flex; height: 100dvh; }

.sidebar {
  width: 15rem; flex: none;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--card);
  padding: 0.9rem 0.7rem;
  gap: 0.15rem;
}
.brand {
  display: flex; align-items: center; gap: 0.55rem;
  font-weight: 700; letter-spacing: -0.02em; font-size: 1.02rem;
  padding: 0.2rem 0.5rem 0.9rem;
}
/* The app mark may be an emoji (repo rule: the project "sign" is the one
   sanctioned emoji — favicon, logo, title). */
.brand-icon { font-size: 1.35rem; line-height: 1; }
.brand img.brand-logo { width: 1.6rem; height: 1.6rem; border-radius: 0.35rem; }

.nav-items { display: flex; flex-direction: column; gap: 0.15rem; }

.nav-item {
  display: flex; align-items: center; gap: 0.6rem;
  border: 0; background: transparent; color: var(--muted-foreground);
  padding: 0.5rem 0.6rem; min-height: 2.5rem; border-radius: var(--radius);
  cursor: pointer; text-align: left; font-size: 0.92rem; width: 100%;
}
.nav-item:hover { background: var(--muted); color: var(--foreground); }
.nav-item.active { background: var(--muted); color: var(--foreground); font-weight: 600; }
.nav-item:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.sidebar .spacer { flex: 1; }

.sidebar-user {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.5rem 0.6rem; border-top: 1px solid var(--border); margin-top: 0.5rem;
}
.sidebar-user .u-name {
  font-size: 0.85rem; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.avatar {
  width: 2rem; height: 2rem; border-radius: 50%; flex: none;
  background: var(--muted); display: inline-flex; align-items: center;
  justify-content: center; font-size: 0.8rem; font-weight: 700;
  color: var(--muted-foreground); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.content { flex: 1; overflow-y: auto; min-width: 0; }
.content-inner { max-width: 64rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

.page-title { margin: 0 0 0.35rem; font-size: 1.45rem; letter-spacing: -0.02em; }
.page-desc { margin: 0 0 1.4rem; color: var(--muted-foreground); max-width: 44rem; }

/* ---------- sections and card grid ---------- */

.section { margin-bottom: 2rem; }
.section-title { margin: 0 0 0.25rem; font-size: 1.08rem; }
.section-desc { margin: 0 0 0.9rem; font-size: 0.88rem; color: var(--muted-foreground); max-width: 44rem; }

.card-grid {
  display: grid; gap: 0.9rem;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
}
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 0.75rem; overflow: hidden;
  display: flex; flex-direction: column; text-align: left;
  padding: 0; cursor: default; color: var(--foreground);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); box-shadow: 0 2px 10px rgba(0,0,0,0.07); }
.card:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.card-img {
  aspect-ratio: 16 / 9; width: 100%; object-fit: cover; display: block;
  background: var(--muted); border-bottom: 1px solid var(--border);
}
.card-img-placeholder {
  aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 6%, var(--muted));
  border-bottom: 1px solid var(--border); color: var(--muted-foreground);
}
.card-img-placeholder .icon { width: 2rem; height: 2rem; opacity: 0.5; }
.card-body { padding: 0.8rem 0.9rem 0.95rem; display: flex; flex-direction: column; gap: 0.3rem; }
.card-title { font-weight: 600; font-size: 0.97rem; }
.card-desc { font-size: 0.84rem; color: var(--muted-foreground); line-height: 1.45; }

/* ---------- buttons / inputs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius); border: 1px solid transparent;
  padding: 0.4rem 0.9rem; min-height: 2.5rem; min-width: 2.5rem;
  background: transparent; color: var(--foreground); cursor: pointer;
  gap: 0.4rem; transition: background 0.12s, border-color 0.12s;
}
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { opacity: 0.9; }
.btn-outline { border-color: var(--border); }
.btn-outline:hover { background: var(--muted); }
.btn-ghost:hover { background: var(--muted); }
.btn-sm { min-height: 2rem; padding: 0.2rem 0.6rem; font-size: 0.85rem; }
.btn-icon { padding: 0.2rem 0.5rem; }
.btn-danger { color: var(--danger); }
.btn:disabled { opacity: 0.4; cursor: default; }

.input, .select {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--foreground);
  padding: 0.4rem 0.6rem; min-height: 2.5rem; font: inherit;
}
.input:focus-visible, .select:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.input-sm { min-height: 2rem; padding: 0.2rem 0.5rem; font-size: 0.85rem; }

.badge {
  font-size: 0.7rem; font-weight: 600; padding: 0.12rem 0.5rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted-foreground); white-space: nowrap;
}
.badge.ok { color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.badge.accent { color: var(--accent); border-color: transparent; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.badge.warn { color: #d97706; border-color: #d9770655; }

/* ---------- login screen ---------- */

.center-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--background); padding: 1rem; z-index: 40;
}
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 0.75rem;
  padding: 2rem 1.75rem; max-width: 24rem; width: 100%; text-align: center;
  display: flex; flex-direction: column; gap: 0.9rem; align-items: center;
}
.login-card h1 { margin: 0; font-size: 1.3rem; letter-spacing: -0.02em; }
.login-card p { margin: 0; font-size: 0.9rem; color: var(--muted-foreground); }
.login-mark { font-size: 2.6rem; line-height: 1; }
.login-wait { display: flex; align-items: center; gap: 0.5rem; font-size: 0.88rem; color: var(--muted-foreground); }
.spinner {
  width: 1rem; height: 1rem; border-radius: 50%; flex: none;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- internal page view ---------- */

.inner-page { max-width: 44rem; }
.inner-page .back-row { margin-bottom: 1rem; }
.inner-page h1 { font-size: 1.35rem; margin: 0 0 0.9rem; letter-spacing: -0.02em; }
.inner-page ul { padding-left: 1.2rem; line-height: 1.9; }
.inner-page p { line-height: 1.6; }

/* ---------- tables (admin, rating ledger) ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.table th {
  text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted-foreground); font-weight: 600;
  padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border);
  background: var(--muted); white-space: nowrap;
}
.table td { padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }

/* ---------- admin: rule editor ---------- */

.entity-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); padding: 0.85rem 1rem; margin-bottom: 0.8rem;
}
.entity-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; cursor: pointer; }
.entity-key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem; color: var(--muted-foreground); }
.rule-block { margin-top: 0.8rem; }
.rule-block-title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted-foreground); margin-bottom: 0.4rem; }
.rule-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.rule-row .select, .rule-row .input { min-height: 2rem; padding: 0.2rem 0.45rem; font-size: 0.84rem; }
.rule-row .grow { flex: 1; min-width: 8rem; }
.rule-actions { display: flex; gap: 0.4rem; margin-top: 0.5rem; flex-wrap: wrap; }

.stat-row { display: flex; gap: 0.9rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.stat {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--card);
  padding: 0.7rem 1rem; min-width: 8rem;
}
.stat .stat-value { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
.stat .stat-label { font-size: 0.75rem; color: var(--muted-foreground); }

.toast {
  position: fixed; top: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: var(--primary-foreground);
  padding: 0.6rem 1rem; border-radius: var(--radius); font-size: 0.9rem;
  z-index: 100; box-shadow: 0 4px 14px rgba(0,0,0,0.25); max-width: 90vw;
}

/* ---------- profile ---------- */

.profile-card {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: 0.75rem; background: var(--card);
  padding: 1.2rem 1.3rem; max-width: 32rem;
}
.profile-card .avatar { width: 4rem; height: 4rem; font-size: 1.4rem; }
.profile-info { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.profile-name { font-size: 1.15rem; font-weight: 700; }
.profile-meta { font-size: 0.85rem; color: var(--muted-foreground); word-break: break-all; }
.profile-badges { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.3rem; }

/* ---------- mobile ---------- */
/* Sidebar becomes a top bar with horizontally scrollable nav; everything must
   fit 320px with zero horizontal page scroll. */

@media (max-width: 760px) {
  #app { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; align-items: center;
    border-right: 0; border-bottom: 1px solid var(--border);
    padding: 0.4rem 0.5rem; gap: 0.25rem;
    overflow-x: auto; scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand { padding: 0.2rem 0.4rem; flex: none; }
  .brand .brand-name { display: none; }
  .nav-items { flex-direction: row; gap: 0.2rem; }
  .nav-item { width: auto; flex: none; padding: 0.4rem 0.55rem; min-height: 2.25rem; font-size: 0.85rem; }
  .nav-item .icon { display: none; }
  .sidebar .spacer { display: none; }
  .sidebar-user { border-top: 0; margin: 0; padding: 0.2rem 0.3rem; flex: none; margin-left: auto; }
  .sidebar-user .u-name { display: none; }
  .avatar { width: 1.75rem; height: 1.75rem; }
  .content-inner { padding: 1rem 0.8rem 2.5rem; }
  .card-grid { grid-template-columns: 1fr; }
  .page-title { font-size: 1.25rem; }
}

/* ---------- icon sizing (inline SVG, Lucide) ---------- */

.icon { width: 1em; height: 1em; flex: none; vertical-align: -0.125em; }
.btn .icon { width: 1.1em; height: 1.1em; }
.nav-item .icon { width: 1.15em; height: 1.15em; }
