:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --surface: #ffffff;
  --border: #ececec;
  --border-strong: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --accent: #d40b0b;
  --accent-soft: #ffe9e9;
  --accent-strong: #a30808;
  --danger: #d40b0b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.08);

  --sidebar-w: 240px;
  --radius: 10px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --bg: #0a0a0c;
  --bg-soft: #131318;
  --surface: #16161c;
  --border: #24242c;
  --border-strong: #2e2e38;
  --text: #f3f3f5;
  --text-muted: #9aa0a6;
  --accent: #ff4040;
  --accent-soft: #2a0d0d;
  --accent-strong: #ff6868;
}

* { box-sizing: border-box; }

/* Beat author display rules with the [hidden] attribute. The base
 * [hidden] { display: none } UA rule has the same specificity (0,1,0)
 * as a single class selector, so .auth-screen { display: grid } wins
 * and the screen never goes away. Higher-specificity attribute rule
 * fixes the toggle. */
.auth-screen[hidden],
.app[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

/* ---------- Auth screen ---------- */
.auth-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at top, #1a0606 0%, #0a0a0c 60%, #050505 100%);
  padding: 24px;
  z-index: 100;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: rgba(20, 20, 24, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid #2a2a32;
  border-radius: 18px;
  padding: 28px 24px 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  color: #f3f3f5;
}

.auth-logo {
  display: grid;
  place-items: center;
  margin-bottom: 12px;
}
.auth-logo img {
  width: 220px;
  height: auto;
  max-width: 100%;
  display: block;
  border-radius: 12px;
}

.auth-title {
  margin: 8px 0 22px;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  background: linear-gradient(180deg, #f5f5f5 0%, #9a9a9a 60%, #cfcfcf 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12px;
  color: #9aa0a6;
  font-weight: 500;
  letter-spacing: 0.2px;
}
.field input {
  background: #0e0e12;
  border: 1px solid #2a2a32;
  border-radius: 10px;
  padding: 12px 14px;
  color: #f3f3f5;
  font-size: 14px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.field input::placeholder { color: #555560; }
.field input:focus {
  border-color: #ff4040;
  box-shadow: 0 0 0 3px rgba(255, 64, 64, 0.18);
}

.field-password { position: relative; }
.field-password input { padding-right: 44px; width: 100%; }
.field-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  color: #9aa0a6;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 120ms ease, background 120ms ease;
}
.field-toggle:hover { color: #f3f3f5; background: rgba(255, 255, 255, 0.05); }
.field-toggle[data-show="true"] .eye-slash { display: none; }

.auth-error {
  background: rgba(255, 64, 64, 0.12);
  border: 1px solid rgba(255, 64, 64, 0.4);
  color: #ff8080;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
}

.auth-status {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #d4d4d8;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  text-align: center;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 80ms ease, background 120ms ease, color 120ms ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(180deg, #ff4747 0%, #c20c0c 60%, #7e0606 100%);
  color: #fff;
  box-shadow: 0 6px 18px rgba(204, 17, 17, 0.35);
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 18px 14px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 18px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
}
.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.brand-title { font-weight: 700; font-size: 14px; color: var(--text); }
.brand-sub { font-size: 12px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }

.nav-item, .footer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 0;
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
  text-align: left;
  font-size: 14px;
  transition: background 120ms ease, color 120ms ease;
  width: 100%;
}

.nav-item:hover, .footer-item:hover { background: var(--bg-soft); }

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.icon { width: 18px; height: 18px; flex-shrink: 0; }

.footer-item-danger { color: var(--text-muted); }
.footer-item-danger:hover {
  background: rgba(212, 11, 11, 0.08);
  color: var(--danger);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ---------- Main ---------- */
.main {
  padding: 28px 36px 48px;
  max-width: 1200px;
  width: 100%;
}

.page { display: none; }
.page.is-active { display: block; }

.page-header { margin-bottom: 22px; }

.page-title {
  margin: 0 0 4px;
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(180deg, #ff4040 0%, #c20c0c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: -0.2px;
}

.page-sub { margin: 0; color: var(--text-muted); font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.2px;
}

.card p { margin: 6px 0; }
.card p:first-of-type { margin-top: 0; }
.card p:last-of-type { margin-bottom: 0; }

.muted { color: var(--text-muted); }

.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.kv:first-of-type { border-top: 0; }
.kv-k { color: var(--text-muted); }
.kv-v { color: var(--text); font-weight: 500; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* Platforms */
.platform-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.platform-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.platform-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.platform-icon { width: 22px; height: 22px; flex-shrink: 0; }

.platform-desc {
  margin: 4px 0 14px;
  color: var(--text-muted);
  font-size: 13px;
}

.btn-add {
  background: linear-gradient(180deg, #5b6ee0 0%, #4253c9 100%);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(66, 83, 201, 0.25);
  transition: filter 120ms ease, transform 80ms ease;
}
.btn-add:hover { filter: brightness(1.08); }
.btn-add:active { transform: translateY(1px); }

.platform-accounts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.platform-accounts:empty + .platform-empty { display: block; }
.platform-accounts:not(:empty) + .platform-empty { display: none; }
.platform-empty {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.account-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
}

.account-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-soft);
  overflow: hidden;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}
.account-avatar img { width: 100%; height: 100%; object-fit: cover; }

.account-meta { min-width: 0; flex: 1; }
.account-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-info {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-ghost-sm {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.btn-ghost-sm:hover { background: var(--bg-soft); }
.btn-ghost-sm.is-danger:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(212, 11, 11, 0.06);
}

@media (max-width: 640px) {
  .platform-head { flex-direction: column; align-items: stretch; }
  .btn-add { align-self: flex-end; }
  .account-row { flex-wrap: wrap; }
  .account-actions { width: 100%; }
  .btn-ghost-sm { flex: 1; text-align: center; }
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  margin-bottom: -1px;
  transition: color 120ms ease, border-color 120ms ease;
}
.tab:hover { color: var(--text); }
.tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tab-icon { width: 18px; height: 18px; flex-shrink: 0; }
/* Meta logo has a 1.5:1 aspect ratio — let it keep its natural width
 * instead of squishing it into a square. */
.tab-icon-meta { width: auto; height: 14px; }

.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 4px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-value { font-size: 18px; font-weight: 700; margin-top: 2px; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
  }
  .sidebar-footer {
    flex-direction: row;
    border-top: 1px solid var(--border);
    padding-top: 8px;
  }
  .footer-item { flex: 1; justify-content: center; }
  .main { padding: 20px 16px 32px; }
  .page-title { font-size: 24px; }
}
