:root {
  color-scheme: light dark;
  --brand: #17133f;
  --brand-2: #287f77;
  --brand-soft: #e2f2ef;
  --accent: #d95c43;
  --surface: #ffffff;
  --surface-2: #f3f5f8;
  --surface-3: #e7ebf0;
  --ink: #1b2230;
  --muted: #647083;
  --line: #d7dde5;
  --danger: #a52f2f;
  --success: #17745b;
  --empty-icon-filter: none;
  --shadow: 0 16px 46px rgb(19 25 45 / 10%);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #d8d4ff;
    --brand-2: #63c5b7;
    --brand-soft: #173b38;
    --accent: #ff8d70;
    --surface: #111722;
    --surface-2: #181f2c;
    --surface-3: #273041;
    --ink: #f4f6fb;
    --muted: #aeb8c8;
    --line: #354053;
    --danger: #ff9292;
    --success: #6ed3b1;
    --empty-icon-filter: brightness(0) invert(1);
    --shadow: 0 18px 48px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--surface-2); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--surface-2); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
img { max-width: 100%; }

.skip-link {
  position: fixed; z-index: 100; left: 1rem; top: -5rem; padding: .7rem 1rem;
  color: white; background: #111; border-radius: .6rem;
}
.skip-link:focus { top: 1rem; }

.startup {
  min-height: 100vh; display: grid; place-content: center; justify-items: center;
  gap: .7rem; padding: 2rem; text-align: center;
}
.startup h1 { margin: .4rem 0 0; color: var(--brand); }
.startup p { margin: 0; color: var(--muted); }

.shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 1.25rem 1rem;
  background: #17133f; color: #f7f6ff; display: flex; flex-direction: column; gap: 1.25rem;
}
.brand { display: flex; align-items: center; gap: .8rem; padding: .3rem .55rem 1rem; text-decoration: none; }
.brand img { width: 38px; height: 38px; }
.brand strong { display: block; font-size: 1.08rem; }
.brand small { color: #bcb8df; }
.nav { display: grid; gap: .35rem; }
.nav a {
  display: flex; align-items: center; gap: .8rem; min-height: 46px; padding: .65rem .8rem;
  border-radius: 12px; color: #d9d6ed; text-decoration: none; font-weight: 650;
}
.nav a:hover, .nav a[aria-current="page"] { color: white; background: rgb(255 255 255 / 12%); }
.nav img { width: 21px; height: 21px; filter: brightness(0) invert(1); opacity: .9; }
.sidebar-foot { margin-top: auto; padding: .8rem; color: #bcb8df; font-size: .82rem; }

.workspace { min-width: 0; }
.topbar {
  position: sticky; z-index: 10; top: 0; min-height: 72px; padding: .8rem clamp(1rem, 3vw, 2.5rem);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: clamp(1.15rem, 2vw, 1.45rem); }
.topbar p { margin: .15rem 0 0; color: var(--muted); font-size: .86rem; }
.content { width: min(1280px, 100%); margin: 0 auto; padding: clamp(1rem, 3vw, 2.5rem); }

.grid { display: grid; gap: 1rem; }
.grid.cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: clamp(1rem, 2vw, 1.4rem); box-shadow: 0 2px 12px rgb(19 25 45 / 4%);
}
.card h2, .card h3 { margin-top: 0; }
.setup-card { width: min(560px, 100%); text-align: left; }
.spaced { margin-top: 1rem; }
.metric { display: grid; gap: .3rem; }
.metric strong { font-size: clamp(1.6rem, 4vw, 2.3rem); color: var(--brand-2); }
.metric span { color: var(--muted); }
.hero {
  padding: clamp(1.3rem, 4vw, 2.5rem); margin-bottom: 1rem; color: white;
  background: linear-gradient(135deg, #17133f, #2d2863 62%, #287f77); border-radius: 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 1.5rem;
}
.hero h2 { margin: 0 0 .5rem; font-size: clamp(1.45rem, 3vw, 2.2rem); }
.hero p { margin: 0; color: #dad8ef; max-width: 60ch; }

.button, button {
  border: 0; border-radius: 12px; min-height: 44px; padding: .66rem 1rem; cursor: pointer;
  color: white; background: var(--brand-2); font-weight: 700; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .55rem;
}
button:hover, .button:hover { filter: brightness(1.07); }
button:focus-visible, .button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand-2) 65%, white); outline-offset: 2px;
}
button.secondary, .button.secondary { color: var(--ink); background: var(--surface-3); }
button.danger { background: var(--danger); }
button.ghost { color: var(--brand-2); background: transparent; border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: not-allowed; }
.hero .button { flex: 0 0 auto; color: #17133f; background: white; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; }

.toolbar { display: flex; align-items: end; gap: .8rem; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar .field { flex: 1 1 220px; }
.field { display: grid; align-content: start; gap: .38rem; }
.field label, .field > span { font-size: .84rem; font-weight: 750; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 46px; padding: .68rem .8rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 11px;
}
.field textarea { min-height: 110px; resize: vertical; }
.field small { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.form-grid .wide { grid-column: 1 / -1; }
fieldset { margin: 0; padding: 1rem; border: 1px solid var(--line); border-radius: 14px; }
legend { padding: 0 .4rem; font-weight: 800; }
.check { display: flex; align-items: center; gap: .65rem; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--brand-2); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .85rem 1rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--brand-soft) 42%, transparent); }
td a { color: var(--brand-2); font-weight: 750; text-decoration: none; }

.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 800; background: var(--surface-3); }
.badge.success { color: var(--success); background: color-mix(in srgb, var(--success) 12%, var(--surface)); }
.badge.warn { color: #8b5510; background: #fff1cf; }
.badge.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }

.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.empty > img { width: 54px; opacity: .55; filter: var(--empty-icon-filter); }
.detail-list { display: grid; grid-template-columns: minmax(130px, .4fr) 1fr; margin: 0; }
.detail-list dt, .detail-list dd { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.detail-list dt { color: var(--muted); font-weight: 700; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.5rem 0 .8rem; }
.section-head h2 { margin: 0; }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .8rem; }
.photo { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.photo img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--surface-3); }
.photo div { padding: .7rem; }
.photo strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo small { color: var(--muted); }

.steps { display: flex; gap: .4rem; margin-bottom: 1rem; padding: 0; list-style: none; }
.steps li { flex: 1; padding: .55rem; text-align: center; color: var(--muted); border-bottom: 3px solid var(--line); font-size: .82rem; font-weight: 750; }
.steps li.active { color: var(--brand-2); border-color: var(--brand-2); }
.notice { padding: .8rem 1rem; margin-bottom: 1rem; border-radius: 12px; background: var(--brand-soft); color: var(--ink); }
.notice.error { background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); }
.notice ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.admin-grid { margin-top: 1rem; }
.admin-add { display: flex; align-items: end; gap: .6rem; }
.admin-add .field { flex: 1; }
.master-list { display: grid; gap: .4rem; margin: 1rem 0 0; padding: 0; list-style: none; }
.master-list li { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.master-list li:last-child { border-bottom: 0; }
.master-list .muted { color: var(--muted); }

.toast {
  position: fixed; z-index: 50; right: 1rem; bottom: 1rem; max-width: min(420px, calc(100vw - 2rem));
  padding: .85rem 1rem; color: white; background: #172033; border-radius: 12px; box-shadow: var(--shadow);
}

.annotation-dialog { width: min(1100px, calc(100vw - 1rem)); max-width: none; max-height: calc(100vh - 1rem); padding: 0; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.annotation-dialog::backdrop { background: rgb(5 8 18 / 78%); backdrop-filter: blur(5px); }
.annotation-dialog form { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; max-height: calc(100vh - 1rem); }
.annotation-dialog header, .annotation-dialog footer { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.annotation-dialog footer { justify-content: flex-end; border-top: 1px solid var(--line); border-bottom: 0; }
.annotation-dialog header small { display: block; color: var(--muted); }
.annotation-tools { display: flex; gap: .4rem; padding: .65rem 1rem; overflow-x: auto; }
.annotation-tools button { flex: 0 0 auto; }
.annotation-stage { min-height: 0; overflow: auto; display: grid; place-items: center; padding: .5rem; background: #0c1018; touch-action: none; }
.annotation-stage canvas { display: block; max-width: 100%; max-height: 100%; touch-action: none; cursor: crosshair; }

@media (max-width: 980px) {
  .grid.cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .shell { display: block; padding-bottom: 72px; }
  .sidebar { position: fixed; z-index: 20; inset: auto 0 0; height: 70px; padding: .4rem .5rem calc(.4rem + env(safe-area-inset-bottom)); display: block; }
  .brand, .sidebar-foot { display: none; }
  .nav { display: grid; grid-template-columns: repeat(4, 1fr); gap: .15rem; }
  .nav a { min-height: 58px; padding: .35rem; display: grid; justify-items: center; gap: .15rem; font-size: .68rem; }
  .nav img { width: 22px; height: 22px; }
  .nav a:nth-child(5) { display: none; }
  .topbar { min-height: 62px; }
  .topbar p { display: none; }
  .content { padding: 1rem; }
  .hero { display: grid; }
  .grid.cards, .grid.two, .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .detail-list { grid-template-columns: 1fr; }
  .detail-list dt { padding-bottom: .1rem; border-bottom: 0; }
  .detail-list dd { padding-top: .1rem; }
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  table, tbody { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tr { display: grid; margin-bottom: .7rem; padding: .85rem; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
  td { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; border: 0; }
  td::before { content: attr(data-label); color: var(--muted); font-size: .76rem; font-weight: 700; }
  td:first-child { display: block; font-size: 1.05rem; }
  td:first-child::before { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .card, .photo, tr { transition: transform 140ms ease, box-shadow 140ms ease; }
  .card:hover, .photo:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgb(19 25 45 / 8%); }
}
