/* Octagon — Phase 1 styles. */

:root {
  --brand-stroke: #F47920;   /* octagon outline color */
  --theme: #F47920;          /* centre fill, set by an admin */
  --theme-ink: #ffffff;      /* text on the theme color, picked for contrast */
  --bg: #ffffff;
  --surface: #ffffff;
  --page: #f6f6f7;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e6;
  --danger: #c4321b;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
body.page-admin, body.page-side, body.page-login { background: var(--page); }

a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; margin-top: 1.5rem; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Header ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  height: 56px; padding: 0 16px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.wordmark {
  display: inline-flex; align-items: center; gap: .5rem;
  font-weight: 700; font-size: 1.05rem; letter-spacing: .01em; text-decoration: none;
}
.wordmark-mark, .login-mark { width: 22px; height: 22px; }
.wordmark-mark polygon, .login-mark polygon {
  fill: none; stroke: var(--brand-stroke); stroke-width: 3; stroke-linejoin: round;
}
.user-area { display: flex; align-items: center; gap: .9rem; min-width: 0; }
.user-name { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gear { display: inline-flex; color: var(--muted); padding: 4px; border-radius: 6px; }
.gear:hover, .gear:focus-visible { color: var(--ink); background: var(--page); }
.gear[hidden] { display: none; }
.gear .icon { width: 20px; height: 20px; }
.link-button {
  background: none; border: 0; padding: 4px; font: inherit; color: var(--ink);
  cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}

/* ---------- Home: the octagon ---------- */

.stage {
  min-height: calc(100vh - 56px);
  min-height: calc(100dvh - 56px);
  display: grid; place-items: center;
  padding: 24px 16px;
}
.octagon {
  position: relative;
  width: min(88vw, calc(100dvh - 120px), 600px);
  min-width: 260px;
  aspect-ratio: 1;
}
.octagon-svg { display: block; width: 100%; height: 100%; overflow: visible; }

.octagon .fill {
  fill: var(--theme);
  opacity: 0;
  transform: scale(.6);
  transform-box: fill-box;
  transform-origin: center;
  transition: opacity .22s ease, transform .28s cubic-bezier(.2, .8, .2, 1);
}
.octagon.is-filled .fill { opacity: 1; transform: scale(1); }

.octagon .edge {
  stroke: var(--brand-stroke);
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-width .15s ease, opacity .15s ease;
}
.octagon .edge.is-dimmed { opacity: .28; }
.octagon .edge.is-selected { stroke-width: 11; }
.octagon .edge.is-dimmed.is-selected { stroke-width: 8; opacity: .45; }

.octagon .hit { fill: transparent; pointer-events: all; }
.octagon .side { cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.octagon .side[aria-disabled="true"] { cursor: default; }

.center {
  position: absolute; inset: 22%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .55rem;
  text-align: center;
  pointer-events: none;
  color: var(--muted);
}
.octagon.is-filled .center { color: var(--theme-ink); }
.octagon.is-coming-soon .center { color: #8e8e93; }
.center-icon { width: clamp(28px, 9%, 48px); height: auto; aspect-ratio: 1; }
.center-label { font-size: clamp(1.05rem, 3.4vw, 1.6rem); font-weight: 650; line-height: 1.15; }
.center-note { font-size: .85rem; opacity: .85; }
.center-hint { font-size: .95rem; letter-spacing: .02em; }

@media (prefers-reduced-motion: reduce) {
  .octagon .fill, .octagon .edge { transition: none; }
}

/* ---------- Cards, forms, buttons ---------- */

.page { max-width: 960px; margin: 0 auto; padding: 24px 16px 64px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
}
.help { color: var(--muted); margin: 0 0 1rem; font-size: .92rem; }

label { display: grid; gap: 4px; font-size: .85rem; font-weight: 600; color: #3a3a3c; }
input, select {
  font: inherit; font-weight: 400; color: var(--ink);
  width: 100%; min-height: 38px; padding: 7px 10px;
  border: 1px solid #c9c9cf; border-radius: 7px; background: #fff;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand-stroke); outline-offset: 2px;
}
input[type="checkbox"] { width: auto; min-height: 0; }

button, .button {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-weight: 600; text-decoration: none;
  min-height: 38px; padding: 7px 16px;
  border: 1px solid var(--ink); border-radius: 7px;
  background: var(--ink); color: #fff; cursor: pointer;
}
button.secondary { background: #fff; color: var(--ink); border-color: #c9c9cf; font-weight: 500; }
button:disabled { opacity: .55; cursor: progress; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: .9rem; }

/* ---------- Login ---------- */

.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; margin: 0; padding: 28px; }
.login-brand { display: flex; align-items: center; gap: .6rem; margin-bottom: 4px; }
.login-brand h1 { margin: 0; font-size: 1.4rem; }
.login-mark { width: 30px; height: 30px; }

/* ---------- Placeholder page ---------- */

.placeholder { text-align: center; padding: 48px 20px; margin-top: 8vh; }
.placeholder p { color: var(--muted); }
.placeholder-badge {
  display: inline-grid; place-items: center; width: 72px; height: 72px; margin-bottom: 12px;
  background: var(--theme); color: var(--theme-ink);
  clip-path: polygon(29.3% 0, 70.7% 0, 100% 29.3%, 100% 70.7%, 70.7% 100%, 29.3% 100%, 0 70.7%, 0 29.3%);
}
.placeholder-icon { width: 32px; height: 32px; }

/* ---------- Admin ---------- */

.theme-form { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 20px; }
.theme-controls { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.theme-controls label { width: 120px; }
#theme-picker { width: 56px; height: 38px; padding: 2px; cursor: pointer; }
.theme-preview { display: grid; justify-items: center; gap: 4px; color: var(--muted); font-size: .8rem; }
.theme-preview svg { width: 96px; height: 96px; }
.preview-fill { fill: var(--theme); }
.preview-edge { fill: none; stroke: var(--brand-stroke); stroke-width: 4; stroke-linejoin: round; }

.sides-list { display: grid; gap: 12px; }
.side-row {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px;
  margin: 0; padding: 12px 14px 14px; border: 1px solid var(--line); border-radius: 8px;
}
.side-row:has([name="enabled"]:not(:checked)) { background: #fafafa; }
.side-row legend { padding: 0 6px; font-weight: 650; font-size: .9rem; }
.side-num {
  display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 2px;
  border-radius: 50%; background: var(--brand-stroke); color: #fff; font-size: .75rem;
}
.side-row .wide { grid-column: span 2; }
.side-row .toggle { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; }
.icon-select { display: flex; align-items: center; gap: 8px; }
.icon-preview { display: inline-grid; place-items: center; width: 26px; flex: none; color: var(--muted); }
.icon-preview .icon { width: 20px; height: 20px; }
.form-actions { margin-top: 14px; display: flex; justify-content: flex-end; }

.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; font-size: .92rem; }
.users th, .users td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.users th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.users select { width: auto; min-height: 32px; padding: 4px 8px; }
.users .actions { text-align: right; white-space: nowrap; }
.users .actions button { min-height: 32px; padding: 4px 10px; font-size: .85rem; margin-left: 4px; }
.users tr.is-inactive td:not(.actions) { color: #9a9aa0; }
.pill { font-size: .7rem; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--page); color: var(--muted); }

.add-user { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 10px 12px; align-items: end; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 8px;
  background: var(--ink); color: #fff; font-size: .92rem; box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}
.toast.is-error { background: var(--danger); }

@media (max-width: 760px) {
  .side-row { grid-template-columns: 1fr 1fr; }
  .side-row .wide { grid-column: 1 / -1; }
  .add-user { grid-template-columns: 1fr 1fr; }
  .add-user button { grid-column: 1 / -1; }

  /* Users table becomes stacked cards on narrow screens */
  table.users thead { display: none; }
  .users, .users tbody, .users tr, .users td { display: block; width: 100%; }
  .users tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  .users td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; }
  .users td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }
  .users .actions { justify-content: flex-start; }
  .users .actions button { margin: 0 6px 0 0; }
}

@media (max-width: 420px) {
  .user-name { max-width: 34vw; }
  .side-row, .add-user { grid-template-columns: 1fr; }
}
