:root {
  --ink: #0F2438;
  --blue: #005DAA;
  --blue-dark: #004B89;
  --blue-pale: #E7F0FA;
  --sand: #F4EFE6;
  --surface: #FFFFFF;
  --surface-2: #FBFAF7;
  --line: #E9E3D7;
  --field-line: #DAD3C5;
  --text: #0F2438;
  --text-2: #4A4D55;
  --muted: #6B6E76;
  --danger: #B23B36;
  --danger-bg: #FBEDEC;
  --ok: #2F8559;
  --ok-bg: #E7F2EC;
  --shadow-card: 0 1px 2px rgba(20,22,26,.04), 0 8px 22px rgba(20,22,26,.05);
  --shadow-modal: 0 30px 70px rgba(0,0,0,.28);
  --r: 14px;
  --font: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--sand);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--blue); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* -- Brand mark -------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.01em; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--blue); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 22px; height: 22px; }
.brand small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); letter-spacing: 0; }

/* -- Buttons & fields -------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: 15px; cursor: pointer; text-decoration: none; white-space: nowrap;
  background: var(--blue); color: #fff; transition: background .15s, box-shadow .15s;
}
.btn:hover { background: var(--blue-dark); }
.btn:focus-visible, .icon-btn:focus-visible, .tile:focus-visible, .swatch:focus-visible, .glyph:focus-visible, .tab:focus-visible {
  outline: 3px solid rgba(0,93,170,.35); outline-offset: 2px;
}
.btn[disabled] { opacity: .6; cursor: default; }
.btn-block { width: 100%; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #F1D4D2; }
.btn-danger:hover { background: #F7DEDC; }
.btn svg { width: 18px; height: 18px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 9px; border: 1px solid transparent; background: transparent;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--line); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-bg); border-color: #F1D4D2; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label, .field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field input, .field select {
  height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--field-line);
  background: var(--surface); outline: none; width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,93,170,.15); }
.hint { font-size: 12px; color: var(--muted); }
.alert { padding: 10px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 16px; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }

/* -- Sign in ------------------------------------------------------------ */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(0,93,170,.16), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(15,36,56,.12), transparent 60%),
    var(--sand);
}
.auth-card {
  width: 100%; max-width: 410px; background: var(--surface); border-radius: 20px;
  padding: 32px; box-shadow: var(--shadow-card); border: 1px solid var(--line);
}
.auth-card .brand { margin-bottom: 28px; }
.auth-card h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: -.02em; }
.auth-card p.lead { margin: 0 0 24px; color: var(--muted); }
.auth-tiles { display: flex; gap: 8px; margin-bottom: 26px; }
.auth-tiles span { width: 30px; height: 30px; border-radius: 9px; }

/* -- App shell ---------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: rgba(244,239,230,.88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.topbar .brand { margin-right: auto; text-decoration: none; color: inherit; }
.user-menu { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 4px 10px 4px 4px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--ink); color: #fff; font-weight: 700;
  font-size: 13px; display: grid; place-items: center;
}
.user-chip .who { font-size: 14px; font-weight: 600; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 14px 34px rgba(15,36,56,.14); padding: 6px;
}
.menu-head { padding: 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-head strong { display: block; }
.menu-head span { font-size: 13px; color: var(--muted); word-break: break-all; }
.menu button, .menu a {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; background: none;
  border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--text); font-size: 14px; text-align: left;
}
.menu button:hover, .menu a:hover { background: var(--surface-2); }
.menu svg { width: 16px; height: 16px; color: var(--muted); }

.page { max-width: 1120px; margin: 0 auto; padding: 36px 16px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
.page-head h1 { margin: 0; font-size: clamp(26px, 4vw, 34px); letter-spacing: -.025em; }
.page-head p { margin: 6px 0 0; color: var(--muted); }

.search { position: relative; width: min(320px, 100%); }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.search input {
  width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  padding: 0 14px 0 40px; outline: none;
}
.search input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,93,170,.15); }

/* -- Launchpad grid ------------------------------------------------------ */
.launchpad {
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow-card);
  padding: 36px 24px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 30px 12px;
}
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-decoration: none; color: var(--text);
  padding: 8px 4px; border-radius: 16px; text-align: center; min-width: 0;
}
.tile:hover .app-icon { transform: translateY(-3px); box-shadow: 0 14px 26px -8px var(--tile-shadow, rgba(0,0,0,.35)); }
.tile-name { font-size: 14px; font-weight: 600; line-height: 1.25; max-width: 100%; overflow-wrap: anywhere; }
.tile-desc { font-size: 12px; color: var(--muted); line-height: 1.3; margin-top: -6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.app-icon {
  --size: 76px;
  width: var(--size); height: var(--size); border-radius: calc(var(--size) * .26);
  display: grid; place-items: center; color: #fff; flex: none; position: relative; overflow: hidden;
  box-shadow: 0 8px 18px -8px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.22);
  transition: transform .18s ease, box-shadow .18s ease;
}
.app-icon::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(160deg, rgba(255,255,255,.28), rgba(255,255,255,0) 55%, rgba(0,0,0,.14));
}
.app-icon svg { width: 46%; height: 46%; position: relative; }
.app-icon.sm { --size: 40px; box-shadow: none; }
.app-icon.lg { --size: 96px; }

.empty {
  text-align: center; padding: 56px 20px; color: var(--muted); background: var(--surface);
  border: 1px dashed var(--field-line); border-radius: 24px;
}
.empty h2 { color: var(--text); margin: 0 0 6px; font-size: 20px; }
.empty .btn { margin-top: 18px; }

/* -- Admin ------------------------------------------------------------- */
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 20px; }
.tab { border: 0; background: none; padding: 8px 16px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; text-decoration: none; }
.tab[aria-current="page"] { background: var(--ink); color: #fff; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-card); overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 18px; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-main strong { display: block; }
.row-main > span { display: block; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 4px; flex: none; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); flex: none; }
.badge.admin { background: var(--blue-pale); border-color: #C7DDF4; color: var(--blue-dark); }

/* -- Modal ------------------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,36,56,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-backdrop.intro { animation: fade .15s ease; }
.modal-backdrop.intro .modal { animation: pop .18s ease; }
.modal { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-modal); width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; }
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-body { padding: 20px 24px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 24px 24px; flex-wrap: wrap; }
.modal-foot .spacer { margin-right: auto; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.preview { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 22px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 18px; }
.preview .tile-name { font-size: 15px; }
.swatches, .glyphs { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 32px; height: 32px; border-radius: 9px; border: 0; cursor: pointer; position: relative; }
.swatch[aria-pressed="true"]::after { content: ''; position: absolute; inset: -4px; border-radius: 12px; border: 2px solid var(--ink); }
.swatch-custom { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.swatch-custom input { width: 36px; height: 32px; padding: 0; border: 1px solid var(--field-line); border-radius: 9px; background: none; cursor: pointer; }
.glyph { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; cursor: pointer; color: var(--text-2); }
.glyph svg { width: 20px; height: 20px; }
.glyph[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600; z-index: 60; box-shadow: var(--shadow-modal); animation: pop .2s ease; }

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

@media (max-width: 600px) {
  .launchpad { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); padding: 24px 12px; gap: 22px 6px; border-radius: 20px; }
  .app-icon { --size: 62px; }
  .tile-name { font-size: 13px; }
  .tile-desc { display: none; }
  .user-chip .who { display: none; }
  .user-chip { padding: 4px; }
  .auth-card { padding: 24px; }
  .row { padding: 12px 14px; gap: 10px; }
  .search { width: 100%; }
}

/* -- Email-code sign-in -------------------------------------------------- */
.link { border: 0; background: none; padding: 0; color: var(--blue); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link[disabled] { color: var(--muted); text-decoration: none; cursor: default; font-weight: 500; }
.who-chip {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; margin-bottom: 18px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line);
  font-size: 14px; font-weight: 600;
}
.who-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-input { font-size: 26px !important; font-weight: 700; letter-spacing: .4em; text-align: center; height: 58px !important; font-variant-numeric: tabular-nums; }
.pin-input::placeholder { color: #D9D4CA; }
.resend { margin: 16px 0 0; font-size: 14px; color: var(--muted); text-align: center; line-height: 1.5; }
.alert-warn { background: #FAF1DD; color: #7A5410; }
.alert code { font-size: 13px; background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; }

/* -- Settings ------------------------------------------------------------ */
.card-body { padding: 20px; }
.muted { color: var(--muted); margin: 0 0 16px; line-height: 1.5; }
.chips { list-style: none; margin: 4px 0 18px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 14px; border-radius: 999px;
  background: var(--blue-pale); border: 1px solid #C7DDF4; color: var(--blue-dark); font-weight: 700; font-size: 14px;
}
.chip-x { width: 28px; height: 28px; border-radius: 50%; border: 0; background: transparent; color: inherit; display: grid; place-items: center; cursor: pointer; }
.chip-x:hover { background: rgba(0,75,137,.12); }
.chip-x svg { width: 14px; height: 14px; }
.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-form .at { font-weight: 700; color: var(--muted); }
.inline-form input {
  flex: 1 1 200px; height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--field-line); outline: none; background: var(--surface);
}
.inline-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,93,170,.15); }
.badge.subtle { font-weight: 600; background: transparent; color: var(--muted); }
.badge.warn { color: #7A5410; background: #FAF1DD; border-color: #EBD9AE; }
@media (max-width: 600px) { .badge.subtle { display: none; } }
