:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #e0e0e0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --success: #16a34a;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --nav-bg: #1e293b;
  --nav-text: #e2e8f0;
  --nav-active: #2563eb;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, background .15s;
  text-decoration: none;
}
.btn:hover { opacity: .88; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-icon { padding: 8px; }

/* ── Forms ───────────────────────────────────────────────────── */
input[type="text"], input[type="password"], input[type="search"], textarea, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }

label { font-size: 13px; font-weight: 500; color: var(--text-muted); display: block; margin-bottom: 4px; }

.form-group { margin-bottom: 16px; }

/* ── Alerts ──────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Card ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

/* ── ═══════════════ ADMIN LAYOUT ═══════════════ ── */

.admin-layout { min-height: 100vh; display: flex; flex-direction: column; }

.admin-header {
  background: var(--nav-bg);
  color: var(--nav-text);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.admin-header h1 { font-size: 18px; font-weight: 600; }
.admin-header a  { color: var(--nav-text); font-size: 13px; opacity: .75; }
.admin-header a:hover { opacity: 1; text-decoration: none; }

.admin-main { flex: 1; padding: 32px 24px; max-width: 900px; margin: 0 auto; width: 100%; }

/* ── ═══════════════ PUBLIC LAYOUT ═══════════════ ── */

.public-layout { min-height: 100vh; display: flex; }

.public-nav {
  width: 220px;
  min-height: 100vh;
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.public-nav .nav-brand {
  padding: 20px 20px 16px;
  font-size: 16px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.public-nav ul { list-style: none; padding: 12px 0; }
.public-nav ul li a {
  display: block;
  padding: 10px 20px;
  color: var(--nav-text);
  font-size: 14px;
  opacity: .75;
  transition: background .15s, opacity .15s;
}
.public-nav ul li a:hover,
.public-nav ul li a.active { background: rgba(255,255,255,.07); opacity: 1; text-decoration: none; }
.public-nav ul li a.active { border-left: 3px solid var(--nav-active); }

.public-content { flex: 1; padding: 40px 48px; max-width: 800px; }

/* ── Login page ──────────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-box {
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  box-shadow: var(--shadow);
}
.login-box h1 { font-size: 22px; margin-bottom: 24px; text-align: center; }

/* ── Package list ────────────────────────────────────────────── */

.package-list { list-style: none; }
.package-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.package-list li:last-child { border-bottom: none; }
.package-list .pkg-name { font-weight: 500; }
.package-list .pkg-date { font-size: 12px; color: var(--text-muted); }
.package-list .pkg-actions { display: flex; gap: 8px; }

/* ── Phrase list ─────────────────────────────────────────────── */

.phrase-list { list-style: none; }
.phrase-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.phrase-list li:last-child { border-bottom: none; }
.phrase-text { flex: 1; }
.phrase-text .en { font-weight: 500; }
.phrase-text .ru { font-size: 13px; color: var(--text-muted); }
.phrase-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Edit phrase ─────────────────────────────────────────────── */

.audio-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 16px;
}
.audio-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.audio-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.audio-card audio { width: 100%; margin-bottom: 10px; }
.audio-card .no-audio { color: var(--text-muted); font-size: 13px; margin-bottom: 10px; }

/* ── Top bar (admin packages) ────────────────────────────────── */

.top-bar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.top-bar .form-group { margin-bottom: 0; flex: 1; min-width: 160px; }
.top-bar form { display: contents; }

/* ── Public: package search ──────────────────────────────────── */

.search-box { margin-bottom: 20px; }
.pkg-grid { display: flex; flex-direction: column; gap: 2px; }
.pkg-item {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
  font-weight: 500;
}
.pkg-item:hover { background: #eff6ff; border-color: var(--primary); }
.pkg-item.hidden { display: none; }

/* ── Public: phrase list ─────────────────────────────────────── */

.phrase-view-list { list-style: none; }
.phrase-view-list li {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.phrase-view-list li:last-child { border-bottom: none; }
.phrase-view-list .en { font-weight: 500; font-size: 16px; }
.phrase-view-list .learning-text { font-weight: 500; font-size: 16px; }
.phrase-row-link { display: block; text-decoration: none; color: inherit; }
.phrase-view-list li:hover { background: var(--bg-hover, #f5f5f5); border-radius: 6px; cursor: pointer; }
.phrase-view-list .ru { font-size: 14px; color: var(--text-muted); margin-top: 2px; }
.phrase-view-list .native-text { font-size: 14px; color: var(--text-muted); margin-top: 2px; }

/* ── Player ──────────────────────────────────────────────────── */

.player-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
}

.player-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  justify-content: center;
}

.player-phrase {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
}
.player-phrase .lang-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.player-phrase .phrase-text {
  font-size: 24px;
  font-weight: 500;
  line-height: 1.4;
}
.player-phrase.active { border-color: var(--primary); }
.player-phrase.ru .phrase-text { font-size: 20px; color: var(--text-muted); }

.player-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 24px 0;
}
.player-controls .btn-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 20px;
  justify-content: center;
}
.player-controls .btn-play {
  width: 64px;
  height: 64px;
  font-size: 26px;
  background: var(--primary);
  color: #fff;
}

.player-progress {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 8px;
}

.player-loading {
  text-align: center;
  padding: 60px;
  color: var(--text-muted);
}

/* ── Lang picker (inline on package/phrase pages) ───────────── */
.lang-picker {
  display: flex;
  gap: 20px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.lang-picker label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: normal;
}
.lang-picker select {
  font-size: 14px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

/* ── Settings ────────────────────────────────────────────────── */

.settings-group {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.settings-group:last-child { border-bottom: none; }
.settings-group label { flex: 1; font-size: 15px; font-weight: normal; color: var(--text); }
.settings-group input[type="number"] {
  width: 80px;
  text-align: center;
}

/* ── Page header ─────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
}
.page-header h2 { font-size: 20px; font-weight: 600; }

/* ── Misc ────────────────────────────────────────────────────── */

.text-muted { color: var(--text-muted); }
.empty-state { text-align: center; padding: 48px; color: var(--text-muted); }
.back-link { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 20px; font-size: 14px; }

@media (max-width: 640px) {
  .public-nav { display: none; }
  .audio-section { grid-template-columns: 1fr; }
  .player-phrase .phrase-text { font-size: 18px; }
}
