:root {
  --teal: #00838f;
  --teal-dark: #005662;
  --teal-deep: #063b43;
  --teal-soft: #e3f4f4;
  --mint: #d6f3ec;
  --amber: #f7bc3d;
  --bg: #f3f7f8;
  --card: #ffffff;
  --ink: #122b2f;
  --muted: #6b8287;
  --line: #e2ebed;
  --danger: #c53b47;
  --danger-soft: #fdecee;
  --success: #257f59;
  --success-soft: #e7f6ee;
  --shadow: 0 1px 2px rgba(18, 43, 47, .05), 0 12px 28px rgba(18, 43, 47, .06);
  --radius: 16px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--teal-dark); text-decoration: none; }
a:hover { color: var(--teal); }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 30px; line-height: 1.15; margin-bottom: 6px; letter-spacing: -.02em; }
h2 { font-size: 18px; margin-bottom: 4px; }
h3 { font-size: 15px; margin-bottom: 6px; }
code { font-family: "Cascadia Mono", Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.right { text-align: right; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Layout ------------------------------------------------------------------ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 252px;
  flex: 0 0 252px;
  background: linear-gradient(180deg, #073c44 0%, #042b31 100%);
  color: #d8f3f5;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.brand { display: flex; gap: 11px; align-items: center; color: #fff; padding: 0 6px 20px; }
.brand:hover { color: #fff; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, #13a7b4, #00727d);
  color: #fff; font-weight: 800; font-size: 13px; letter-spacing: .5px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.3);
}
.brand-mark.large { width: 50px; height: 50px; border-radius: 14px; font-size: 17px; }
.brand-text { font-size: 17px; font-weight: 700; line-height: 1.05; }
.brand-text small { display: block; font-size: 10px; font-weight: 500; color: #8dc7cd; letter-spacing: .8px; text-transform: uppercase; margin-top: 3px; }

.nav { display: grid; gap: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  color: #bfe3e7; padding: 10px 12px; border-radius: 10px;
  font-weight: 500;
}
.nav-link span { width: 20px; text-align: center; opacity: .9; }
.nav-link em { margin-left: auto; font-style: normal; opacity: .7; }
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.13); color: #fff; box-shadow: inset 3px 0 0 var(--amber); }

.sidebar-foot { margin-top: auto; padding: 18px 8px 0; display: grid; gap: 6px; }
.server-chip { display: flex; align-items: center; gap: 7px; font-size: 12px; color: #c8e8eb; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #5ee0a0; box-shadow: 0 0 0 3px rgba(94,224,160,.15); display: inline-block; }
.sidebar .muted { color: #7fb2b8; }
.logout-form { margin-top: 8px; }
.text-button { background: none; border: 0; color: #ffd166; padding: 0; font: inherit; cursor: pointer; }
.text-button:hover { text-decoration: underline; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 66px; display: flex; align-items: center; gap: 14px;
  padding: 0 28px; background: rgba(255,255,255,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30;
}
.crumb { color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .02em; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.menu-button { display: none; background: none; border: 1px solid var(--line); border-radius: 9px; width: 38px; height: 38px; font-size: 17px; cursor: pointer; color: var(--ink); }

.content { padding: 28px; max-width: 1320px; width: 100%; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 18px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: 10px; font-weight: 700; color: var(--teal); display: block; margin-bottom: 5px; }
.page-head p { margin-bottom: 0; }

/* Buttons ----------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px; padding: 9px 14px;
  font: inherit; font-weight: 600; font-size: 13px; cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
  color: var(--ink); white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--teal); color: #fff; box-shadow: 0 6px 16px rgba(0,131,143,.22); }
.btn.primary:hover { background: var(--teal-dark); color: #fff; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: #b9d4d8; background: #f7fbfb; }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: #f3c9ce; }
.btn.danger:hover { background: #fbdde1; }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.text-link { font-weight: 600; font-size: 12px; color: var(--teal); }
.inline-form { display: inline; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 18px; }

/* Cards and stats --------------------------------------------------------- */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.panel.flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.panel-head h2 { margin-bottom: 2px; }
.panel-head p { margin-bottom: 0; }
.accent-panel { background: linear-gradient(145deg, #effafa 0%, #fff 70%); border-color: #cfe9ea; }

.stat-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 16px;
  display: grid; gap: 2px; box-shadow: var(--shadow);
}
.stat-card strong { font-size: 24px; line-height: 1.1; letter-spacing: -.02em; }
.stat-card span:last-child { color: var(--muted); font-size: 12px; }
.stat-icon { font-size: 17px; margin-bottom: 4px; }

.split-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.type-list { display: grid; gap: 2px; }
.type-row { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 9px; color: var(--ink); }
.type-row:hover { background: var(--teal-soft); }
.type-emoji { width: 22px; text-align: center; }
.type-row strong { margin-left: auto; color: var(--teal-dark); }

/* Tables ------------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted); font-weight: 700; padding: 11px 16px; background: #f8fbfb;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.data-table td { padding: 11px 16px; border-bottom: 1px solid #eef4f5; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tr:hover td { background: #fbfefe; }
.item-cell { display: flex; gap: 11px; align-items: center; min-width: 240px; }
.thumb { width: 58px; height: 42px; object-fit: cover; border-radius: 8px; background: #e7f2f3; flex: 0 0 auto; border: 1px solid #dcebec; }
.strong-link { font-weight: 700; color: var(--ink); }
.strong-link:hover { color: var(--teal); }
.stat-mini { display: flex; gap: 9px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.actions form { display: inline; }
.items-table .actions { display: grid; grid-template-columns: auto auto; gap: 6px; justify-content: end; align-items: center; }
.items-table .actions form { display: contents; }
.items-table .actions form button { width: 100%; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
}
.badge.live { background: var(--success-soft); color: var(--success); }
.badge.draft { background: #f1f4f5; color: var(--muted); }
.badge.featured { background: #fff4d6; color: #956b00; }
.badge.type { background: var(--teal-soft); color: var(--teal-dark); }

.pagination { display: flex; align-items: center; gap: 14px; justify-content: center; margin: 18px 0 6px; color: var(--muted); font-size: 12px; }

/* Forms ------------------------------------------------------------------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12px; font-weight: 700; color: #345055; }
.field small { color: var(--muted); font-size: 11px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.field-grid .span-2 { grid-column: 1 / -1; }
input[type="text"], input[type="search"], input[type="password"], input[type="url"], input[type="number"], select, textarea {
  width: 100%; border: 1px solid #d4e1e3; border-radius: 9px; padding: 10px 11px;
  font: inherit; color: var(--ink); background: #fff; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,131,143,.12); }
textarea { resize: vertical; min-height: 100px; }
input[type="file"] { border: 1px dashed #bcd3d6; border-radius: 9px; padding: 9px; background: #f8fcfc; width: 100%; font-size: 12px; }
input[type="file"]::file-selector-button {
  border: 0; background: var(--teal-soft); color: var(--teal-dark); font: inherit; font-weight: 600;
  padding: 6px 10px; border-radius: 7px; margin-right: 10px; cursor: pointer;
}
input[type="checkbox"] { accent-color: var(--teal); width: 16px; height: 16px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #405b60; cursor: pointer; }
.check input { flex: 0 0 auto; }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 11px 0; border-bottom: 1px solid #eef4f5; cursor: pointer;
}
.switch-row:last-of-type { border-bottom: 0; }
.switch-row span { display: grid; gap: 2px; }
.switch-row small { color: var(--muted); font-size: 11px; }
.switch-row input { width: 18px; height: 18px; }

.filter-bar {
  display: flex; gap: 10px; align-items: center; background: #fff; border: 1px solid var(--line);
  border-radius: 14px; padding: 10px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.filter-bar .search-field { flex: 1; }
.filter-bar select { width: auto; min-width: 130px; }
.filter-bar input[type="search"] { width: 100%; }

.inline-form { display: inline-flex; }
.top-actions .inline-form { margin: 0; }

/* Editor ------------------------------------------------------------------ */
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.editor-main { min-width: 0; }
.editor-side { position: sticky; top: 84px; }
.editor-side .panel { padding: 17px; }
.id-chip { background: #f1f7f7; border: 1px solid #dcebec; border-radius: 7px; padding: 4px 7px; color: var(--muted); font-size: 11px; }
.cover-editor { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 18px; align-items: start; }
.cover-preview img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 11px; border: 1px solid var(--line); background: #e7f2f3; display: block; margin-bottom: 6px; }
.cover-controls .field { margin-bottom: 10px; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.subhead { margin-bottom: 10px; }
.gallery-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.gallery-item { display: grid; gap: 7px; background: #f8fbfb; border: 1px solid var(--line); border-radius: 10px; padding: 7px; }
.gallery-item img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 7px; display: block; }
.file-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: #f7fbfb; border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; margin-bottom: 10px; }
.preview-panel { background: linear-gradient(180deg, #f7fcfc, #fff); }
.app-card { border: 1px solid var(--line); border-radius: 13px; overflow: hidden; background: #fff; box-shadow: 0 4px 14px rgba(18,43,47,.05); }
.app-card-art { position: relative; }
.app-card-art img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; display: block; background: #e7f2f3; }
.app-pill { position: absolute; left: 8px; bottom: 8px; background: rgba(0,86,98,.92); color: #fff; font-size: 9px; font-weight: 700; letter-spacing: .06em; padding: 3px 7px; border-radius: 5px; text-transform: uppercase; }
.app-card-body { padding: 10px; display: grid; gap: 3px; }
.app-stats { display: flex; gap: 9px; color: var(--muted); font-size: 10px; margin-top: 3px; }
.app-stats span:last-child { margin-left: auto; }
.side-actions { display: grid; gap: 8px; margin-top: 4px; }
.danger-panel { display: flex; justify-content: space-between; align-items: center; gap: 20px; border-color: #f0cdd1; background: #fffafb; }
.danger-panel h2 { color: var(--danger); }

/* Categories -------------------------------------------------------------- */
.category-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.category-form .field { margin-bottom: 0; min-width: 180px; }
.category-form .field-narrow { min-width: 90px; width: 90px; }
.category-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.category-list { display: grid; gap: 6px; }
.category-row { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: 9px; }
.category-row:hover { background: #f8fbfb; }
.category-emoji { width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; background: var(--teal-soft); border-radius: 8px; }
.category-name { display: grid; gap: 1px; flex: 1; min-width: 0; }
.category-name strong { font-size: 13px; }

/* Flash / banners / empty ------------------------------------------------ */
.flashes { padding: 0 28px; max-width: 1320px; width: 100%; margin: 14px auto 0; display: grid; gap: 8px; }
.flash { border-radius: 10px; padding: 10px 13px; font-size: 13px; border: 1px solid transparent; }
.flash.success { background: var(--success-soft); color: var(--success); border-color: #c9ecd9; }
.flash.error { background: var(--danger-soft); color: var(--danger); border-color: #f3c9ce; }
.banner { margin: 14px 28px 0; border-radius: 10px; padding: 10px 14px; font-size: 12px; max-width: 1264px; }
.banner.warning { background: #fff6df; color: #7a5700; border: 1px solid #f3dfaa; }
.compact-banner { margin: 0 0 14px; }
.empty { text-align: center; padding: 52px 24px; }
.empty-icon { font-size: 36px; display: block; margin-bottom: 8px; }
.empty h3 { font-size: 17px; }
.empty p { color: var(--muted); margin-bottom: 16px; }

/* Auth / public ----------------------------------------------------------- */
.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 15% 0%, #0a5962 0%, #063b43 45%, #042a30 100%);
}
.auth-card { width: 100%; max-width: 430px; background: #fff; border-radius: 20px; padding: 28px; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand h1 { font-size: 24px; margin: 0; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.auth-card h2 { font-size: 19px; margin-bottom: 5px; }
.stack { display: grid; gap: 12px; margin-top: 18px; }
.auth-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.auth-foot a { font-size: 11px; }
.error-card { text-align: center; }
.error-code { font-size: 64px; font-weight: 800; color: var(--teal); line-height: 1; letter-spacing: -.05em; }
.error-card .hero-actions { justify-content: center; }

.public-page { background: radial-gradient(1000px 500px at 10% 0%, #0a5962 0%, #063b43 50%, #052c32 100%); color: #fff; min-height: 100vh; display: flex; flex-direction: column; }
.public-nav { display: flex; align-items: center; justify-content: space-between; padding: 22px 6vw; }
.public-nav .brand { padding: 0; }
.public-nav .brand-text small { color: #8dc7cd; }
.public-hero { flex: 1; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 5vw; align-items: center; padding: 4vw 6vw 7vw; max-width: 1280px; width: 100%; margin: 0 auto; }
.hero-copy h1 { font-size: clamp(38px, 6vw, 66px); line-height: .98; letter-spacing: -.045em; margin-bottom: 18px; }
.hero-copy .lead { color: #b9e0e3; font-size: 16px; max-width: 560px; margin-bottom: 10px; }
.public-page .eyebrow { color: var(--amber); }
.hero-stats { display: flex; gap: 30px; margin-top: 34px; flex-wrap: wrap; }
.hero-stats div { display: grid; gap: 2px; }
.hero-stats strong { font-size: 22px; }
.hero-stats span { color: #8dc7cd; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.hero-card { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.16); backdrop-filter: blur(12px); border-radius: 20px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.hero-card-top { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #b9e0e3; margin-bottom: 12px; }
.api-code { display: block; background: #04272c; border: 1px solid rgba(255,255,255,.12); color: #a9f0ec; border-radius: 9px; padding: 12px; font-size: 12px; overflow-wrap: anywhere; margin-bottom: 12px; }
.mini-grid { display: grid; grid-template-columns: 1fr; gap: 6px; margin-top: 16px; font-family: "Cascadia Mono", Consolas, monospace; font-size: 11px; color: #9fd3d8; }
.mini-grid span { border-bottom: 1px solid rgba(255,255,255,.08); padding-bottom: 5px; }
.public-foot { display: flex; justify-content: space-between; gap: 12px; padding: 18px 6vw; color: #7fb2b8; font-size: 11px; border-top: 1px solid rgba(255,255,255,.1); }
.public-foot a { color: #c8e8eb; }
.public-page .btn.primary { background: var(--amber); color: #3a2a00; box-shadow: none; }
.public-page .btn.primary:hover { background: #ffd166; color: #3a2a00; }
.public-page .btn.ghost { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.22); color: #fff; }
.public-page .btn.ghost:hover { background: rgba(255,255,255,.14); }

.api-box { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; max-width: 480px; }
.api-box .label { grid-column: 1 / -1; font-size: 9px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 700; }
.api-box code { font-size: 11px; color: var(--teal-dark); overflow-wrap: anywhere; }
.block-code { display: block; background: #063b43; color: #b9f0ea; border-radius: 9px; padding: 10px 12px; font-size: 12px; overflow-wrap: anywhere; margin: 12px 0; }

/* Responsive -------------------------------------------------------------- */
@media (max-width: 1120px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .editor-grid { grid-template-columns: 1fr; }
  .editor-side { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
  .editor-side .panel { margin-bottom: 14px; }
  .side-actions { grid-column: 1 / -1; display: flex; }
  .side-actions .btn { width: auto; }
}

@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 20px 0 60px rgba(0,0,0,.25); }
  .sidebar.open { transform: translateX(0); }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  .scrim.show { display: block; }
  .menu-button { display: inline-flex; align-items: center; justify-content: center; }
  .topbar { padding: 0 18px; }
  .content { padding: 20px; }
  .flashes { padding: 0 20px; }
  .banner { margin-left: 20px; margin-right: 20px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .api-box { max-width: 100%; width: 100%; }
  .split-grid, .category-columns { grid-template-columns: 1fr; }
  .public-hero { grid-template-columns: 1fr; gap: 32px; padding-top: 6vw; }
  .hero-card { max-width: 560px; }
}

@media (max-width: 640px) {
  h1 { font-size: 25px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .field-grid { grid-template-columns: 1fr; }
  .field-grid .span-2 { grid-column: auto; }
  .filter-bar { flex-wrap: wrap; }
  .filter-bar .search-field { flex-basis: 100%; }
  .filter-bar select { flex: 1; min-width: 0; }
  .cover-editor { grid-template-columns: 1fr; }
  .gallery-grid { grid-template-columns: 1fr 1fr; }
  .editor-side { grid-template-columns: 1fr; }
  .danger-panel { flex-direction: column; align-items: flex-start; }
  .public-nav { padding: 18px 20px; }
  .public-hero { padding: 6vw 20px 14vw; }
  .hero-stats { gap: 20px; }
  .public-foot { padding: 16px 20px; }
  .top-actions .btn.ghost { display: none; }
  .auth-card { padding: 22px; }
}
