:root {
  color-scheme: dark;
  --bg: #090b0e;
  --panel: #10141a;
  --panel-2: #151a21;
  --line: #2a313b;
  --line-strong: #46505d;
  --text: #f3f0e9;
  --muted: #9ba3ad;
  --gold: #d2ad61;
  --gold-dark: #8d713b;
  --danger: #ee5c64;
  --ok: #41c88a;
  --header: 68px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-size: 14px; letter-spacing: 0; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
[hidden] { display: none !important; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #080a0d; }
.auth-panel { width: min(420px, 100%); padding: 34px; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; }
.brand { margin: 0 0 28px; font: 700 24px Georgia, serif; }
.brand span, .admin-brand span { color: var(--gold); font-style: italic; }
.auth-panel h1 { margin: 0 0 8px; font-size: 24px; }
.auth-panel > p:not(.brand):not(.form-error) { color: var(--muted); line-height: 1.5; }
.auth-panel form { display: grid; gap: 16px; margin-top: 24px; }
.form-error { min-height: 20px; color: var(--danger); }

label { display: grid; gap: 7px; color: #d8dbe0; font-weight: 600; }
input, textarea, select {
  width: 100%; border: 1px solid var(--line); border-radius: 4px; background: #0b0e12; color: var(--text);
  padding: 10px 11px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(210, 173, 97, .15); }
textarea { min-height: 116px; resize: vertical; line-height: 1.55; }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--gold); }

.button, .icon-button, .icon-link {
  min-height: 38px; border: 1px solid var(--line-strong); background: #151a20; color: var(--text); border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 14px; text-decoration: none; cursor: pointer;
}
.button:hover, .icon-button:hover, .icon-link:hover { border-color: var(--gold); }
.button.primary { border-color: var(--gold-dark); background: var(--gold); color: #111; font-weight: 800; }
.button.danger { color: #ffd8da; border-color: #6d3539; background: #2b1518; }
.button.small { min-height: 32px; padding: 0 10px; font-size: 12px; }
.button:disabled { opacity: .45; cursor: default; }
.icon-button, .icon-link { width: 38px; padding: 0; font-size: 19px; }

.admin-app { min-height: 100vh; }
.admin-header {
  height: var(--header); position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 250px 1fr auto;
  align-items: center; gap: 24px; padding: 0 20px; background: rgba(9, 11, 14, .98); border-bottom: 1px solid var(--line);
}
.admin-brand { display: flex; align-items: baseline; gap: 12px; }
.admin-brand strong { font: 700 18px Georgia, serif; white-space: nowrap; }
.admin-brand small { color: var(--muted); }
.header-status { justify-self: center; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.status-dot.dirty { background: var(--gold); }
.status-dot.busy { background: #65a4ff; animation: pulse 1s infinite; }
.header-actions { display: flex; gap: 8px; }

.admin-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - var(--header)); }
.admin-nav { position: sticky; top: var(--header); height: calc(100vh - var(--header)); padding: 18px 10px; border-right: 1px solid var(--line); background: #0c0f13; }
.nav-item { width: 100%; min-height: 42px; display: grid; grid-template-columns: 28px 1fr; align-items: center; text-align: left; border: 0; background: transparent; color: var(--muted); border-radius: 4px; cursor: pointer; padding: 0 12px; }
.nav-item span { font-size: 17px; text-align: center; }
.nav-item:hover { color: var(--text); background: #141920; }
.nav-item.is-active { color: #17120a; background: var(--gold); font-weight: 800; }
.workspace { min-width: 0; padding: 28px 30px 70px; }

.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.page-heading h1 { margin: 0; font-size: 26px; }
.page-heading p { margin: 7px 0 0; color: var(--muted); line-height: 1.5; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.eyebrow { margin: 0 0 7px; color: var(--gold); font-size: 11px; font-weight: 800; text-transform: uppercase; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.stat { min-height: 112px; padding: 20px; background: var(--panel); border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat strong { display: block; font-size: 34px; font-weight: 650; }
.stat span { color: var(--muted); }
.overview-band { margin-top: 24px; display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; }
.plain-panel { border-top: 1px solid var(--line); padding-top: 18px; }
.plain-panel h2 { margin: 0 0 14px; font-size: 17px; }
.plain-panel p, .plain-panel li { color: var(--muted); line-height: 1.6; }
.plain-panel code { color: var(--gold); }

.music-shell { display: grid; grid-template-columns: minmax(460px, 1fr) minmax(300px, 390px); gap: 24px; align-items: start; }
.entity-board { min-width: 0; }
.album-band { border-top: 1px solid var(--line); }
.album-band.is-dragover { background: rgba(210, 173, 97, .08); box-shadow: inset 3px 0 var(--gold); }
.is-dragging { opacity: .42; }
.album-head { min-height: 54px; display: grid; grid-template-columns: 30px 42px minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.album-head img { width: 38px; height: 38px; object-fit: cover; background: #171c23; }
.album-head button.title-button { min-width: 0; border: 0; background: transparent; text-align: left; cursor: pointer; padding: 8px 0; }
.album-head strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.album-head small { color: var(--muted); }
.drag-handle { border: 0; background: transparent; color: #737c87; cursor: grab; font-size: 18px; padding: 7px; }
.drag-handle:active { cursor: grabbing; }
.move-buttons { display: flex; gap: 4px; }
.mini-button { width: 28px; height: 28px; border: 1px solid var(--line); background: transparent; border-radius: 3px; color: var(--muted); cursor: pointer; }
.mini-button:hover { color: var(--text); border-color: var(--line-strong); }
.track-dropzone { min-height: 18px; padding: 0 0 10px 38px; }
.track-admin-row { min-height: 50px; display: grid; grid-template-columns: 28px 38px minmax(0, 1fr) auto; align-items: center; gap: 10px; border-top: 1px solid #20262e; cursor: pointer; }
.track-admin-row:hover, .track-admin-row.is-selected { background: #12171d; }
.track-admin-row.is-selected { box-shadow: inset 3px 0 var(--gold); }
.track-admin-row img { width: 34px; height: 34px; object-fit: cover; background: #171c23; }
.track-admin-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-admin-row small { color: var(--muted); }
.empty-drop { padding: 12px; color: #68717c; border: 1px dashed #29303a; }

.inspector { position: sticky; top: calc(var(--header) + 18px); max-height: calc(100vh - var(--header) - 36px); overflow: auto; border-left: 1px solid var(--line); padding-left: 22px; }
.inspector h2 { margin: 0 0 18px; font-size: 19px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-grid .wide { grid-column: 1 / -1; }
.field-note { color: var(--muted); font-size: 12px; line-height: 1.5; }
.switch-row { display: flex; align-items: center; gap: 9px; }
.access-toggle {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #0b0e12;
}
.access-toggle > span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.access-toggle > span.is-active { color: var(--text); }
.access-toggle input[type="checkbox"] {
  position: relative;
  width: 42px;
  height: 22px;
  margin: 0;
  appearance: none;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: #20262e;
  cursor: pointer;
}
.access-toggle input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform .18s ease, background .18s ease;
}
.access-toggle input[type="checkbox"]:checked { border-color: var(--gold-dark); background: #302713; }
.access-toggle input[type="checkbox"]:checked::after { transform: translateX(20px); background: var(--gold); }
.media-field { display: grid; grid-template-columns: 76px 1fr; gap: 12px; align-items: center; }
.media-preview { width: 76px; height: 76px; object-fit: cover; background: #151a21; border: 1px solid var(--line); }
.media-placeholder { display: grid; place-items: center; color: #68717c; }
.inspector-actions { display: flex; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.upload-progress { height: 3px; background: var(--line); margin-top: 8px; overflow: hidden; }
.upload-progress i { display: block; width: 40%; height: 100%; background: var(--gold); animation: upload 1s linear infinite; }

.form-section { padding: 20px 0 28px; border-top: 1px solid var(--line); }
.form-section:first-of-type { border-top: 0; }
.form-section > h2 { margin: 0 0 16px; font-size: 18px; }
.form-section > p { margin: -8px 0 18px; color: var(--muted); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 24px; max-width: 980px; }
.settings-grid .wide { grid-column: 1 / -1; }
.palette-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(135px,1fr)); gap:12px; width:100%; }
.palette-option { position:relative; display:grid; grid-template-columns:42px 1fr; align-items:center; gap:10px; padding:10px; border:1px solid var(--line); border-radius:5px; cursor:pointer; }
.palette-option:has(input:checked) { border-color:var(--gold); background:var(--panel-2); }
.palette-option input { position:absolute; opacity:0; }
.palette-swatch { width:42px; height:42px; border-radius:50%; background:linear-gradient(135deg,var(--palette-accent) 0 48%,var(--palette-bg) 50%); }
@media(max-width:800px){.palette-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
.section-switches { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 10px; }
.section-switch { min-height: 42px; display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }

.collection { border-top: 1px solid var(--line); }
.collection-row { display: grid; grid-template-columns: 30px minmax(130px, .7fr) minmax(180px, 1fr) minmax(180px, 1.3fr) auto; gap: 10px; align-items: center; min-height: 58px; border-bottom: 1px solid #20262e; }
.collection-row.is-dragover { background: rgba(210, 173, 97, .08); box-shadow: inset 3px 0 var(--gold); }
.collection-row.video-row { grid-template-columns: 30px 70px minmax(180px, 1fr) 90px 120px auto; }
.collection-row.announcement-row { grid-template-columns: 30px 70px minmax(180px, 1fr) 145px 120px auto; }
.collection-row img { width: 56px; height: 44px; object-fit: cover; background: #151a21; }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.inline-check { display: flex; gap: 6px; align-items: center; font-size: 12px; }
.inline-check input { width: 16px; height: 16px; }
.support-payment-row{grid-template-columns:150px minmax(260px,1fr) 130px auto}
@media(max-width:900px){.support-payment-row{grid-template-columns:1fr}.support-payment-row .row-actions{justify-content:flex-start}}
.gallery-editor { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.gallery-item { border: 1px solid var(--line); background: var(--panel); padding: 10px; border-radius: 4px; }
.gallery-item.is-dragover { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.gallery-item-head { min-height: 32px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.gallery-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #171c23; }
.gallery-item input { margin-top: 8px; }
.gallery-item .row-actions { margin-top: 8px; }

.notice { padding: 12px 14px; border-left: 3px solid var(--gold); background: #14171b; color: #cbd0d6; line-height: 1.55; }
.analytics-period { display:flex; flex-wrap:wrap; gap:12px 24px; align-items:center; margin:0 0 18px; padding:14px 16px; border:1px solid var(--line); background:var(--panel); color:var(--muted); }
.analytics-period strong { color:var(--text); margin-right:auto; }
.analytics-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:18px; margin-top:18px; }
.analytics-grid .plain-panel { min-width:0; }
.analytics-grid h2 { margin-top:0; }
.table-scroll { overflow:auto; }
.analytics-table { width:100%; border-collapse:collapse; }
.analytics-table th,.analytics-table td { padding:10px 8px; border-top:1px solid var(--line); text-align:left; vertical-align:top; }
.analytics-table th { color:var(--muted); font-size:12px; text-transform:uppercase; }
.analytics-table th:last-child,.analytics-table td:last-child { text-align:right; white-space:nowrap; }
.analytics-table small { display:block; color:var(--muted); margin-top:3px; }
.analytics-privacy { color:var(--muted); font-size:12px; margin-top:18px; }
@media(max-width:900px){.analytics-grid{grid-template-columns:1fr}}
.domain-box { max-width: 760px; display: grid; gap: 12px; }
.domain-row { display: grid; grid-template-columns: 130px 1fr; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.domain-row span { color: var(--muted); }
.domain-row code { color: var(--text); overflow-wrap: anywhere; }

.toast-stack { position: fixed; right: 18px; bottom: 18px; z-index: 50; display: grid; gap: 8px; }
.toast { max-width: 380px; padding: 12px 15px; background: #171d24; border: 1px solid var(--line-strong); border-left: 3px solid var(--ok); border-radius: 4px; box-shadow: 0 12px 34px #0008; }
.toast.error { border-left-color: var(--danger); }

@keyframes pulse { 50% { opacity: .35; } }
@keyframes upload { from { transform: translateX(-120%); } to { transform: translateX(350%); } }

@media (max-width: 1050px) {
  .admin-header { grid-template-columns: 190px 1fr auto; }
  .header-status { display: none; }
  .admin-layout { grid-template-columns: 68px minmax(0, 1fr); }
  .admin-nav { padding: 12px 8px; }
  .nav-item { grid-template-columns: 1fr; padding: 0; text-align: center; font-size: 0; }
  .nav-item span { font-size: 18px; }
  .music-shell { grid-template-columns: 1fr; }
  .inspector { position: static; max-height: none; border-left: 0; border-top: 1px solid var(--line); padding: 22px 0 0; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 720px) {
  :root { --header: 116px; }
  .admin-header { height: var(--header); grid-template-columns: 1fr auto; align-content: center; padding: 10px 14px; }
  .admin-brand small { display: none; }
  .header-actions { grid-column: 1 / -1; }
  .header-actions .button { flex: 1; }
  .admin-layout { display: block; }
  .admin-nav { top: var(--header); height: 54px; z-index: 15; display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px; }
  .nav-item { flex: 0 0 48px; }
  .workspace { padding: 22px 16px 70px; }
  .page-heading { display: grid; }
  .stat-grid, .overview-band, .settings-grid, .section-switches { grid-template-columns: 1fr; }
  .stat { border-right: 0; border-bottom: 1px solid var(--line); }
  .stat:last-child { border-bottom: 0; }
  .music-shell { display: block; }
  .track-dropzone { padding-left: 0; }
  .collection-row, .collection-row.video-row, .collection-row.announcement-row { grid-template-columns: 28px 56px minmax(0, 1fr) auto; padding: 9px 0; }
  .collection-row > :nth-child(n+5):not(.row-actions), .collection-row > :nth-child(4):not(.row-actions) { grid-column: 3 / -1; }
  .field-grid { grid-template-columns: 1fr; }
  .field-grid .wide { grid-column: auto; }
}
