@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #0a0a16;
  --surface: #141428;
  --surface-2: #1e1e38;
  --border: rgba(255,255,255,0.08);
  --accent: #f472b6;
  --accent-2: #a78bfa;
  --text: #f1f5f9;
  --text-muted: #64748b;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --sidebar-w: 230px;
  --radius: 12px;
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── APP WRAPPER (16:9 max-width) ── */
#app-wrap {
  max-width: calc(100vh * 16 / 9);
  min-width: 320px;
  margin: 0 auto;
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 54px 1fr;
  min-height: 100vh;
}

/* ── TOPBAR ── */
.topbar {
  grid-column: 2;
  grid-row: 1;
  position: sticky;
  top: 0;
  height: 54px;
  background: rgba(10,10,22,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 24px;
  z-index: 90;
}

/* ── USER MENU ── */
.user-menu { position: relative; }

.user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}
.user-btn:hover { background: var(--surface-2); border-color: rgba(255,255,255,0.15); }

.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0a16;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dropdown-arrow {
  font-size: 9px;
  color: var(--text-muted);
  margin-left: 2px;
  transition: transform 0.15s;
}
.user-menu.open .dropdown-arrow { transform: rotate(180deg); }

.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
  z-index: 300;
  display: none;
  overflow: hidden;
}
.user-menu.open .user-dropdown { display: block; }

.dd-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.dd-header .dd-name { font-weight: 600; font-size: 14px; color: var(--text); }
.dd-header .dd-role { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.dd-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.dd-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.lang-btns, .unit-btns { display: flex; gap: 4px; }

.lang-btn, .unit-btn {
  flex: 1;
  padding: 6px 4px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  text-align: center;
}
.lang-btn:hover, .unit-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.lang-btn.active, .unit-btn.active {
  background: rgba(244,114,182,0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  width: 100%;
  border: none;
  background: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
  text-align: left;
}
.dd-item:hover { background: rgba(255,255,255,0.04); }
.dd-item.danger { color: var(--danger); }
.dd-item.danger:hover { background: rgba(248,113,113,0.08); }

/* ── SIDEBAR ── */
.sidebar {
  grid-column: 1;
  grid-row: 1 / 3;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-logo {
  padding: 24px 24px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo .logo-title {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-logo .logo-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.nav-items { padding: 12px 0; flex: 1; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 24px;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  border-right: 2px solid transparent;
  text-decoration: none;
}

.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-link.active { color: var(--accent); background: rgba(244,114,182,0.08); border-right-color: var(--accent); }
.nav-link .nav-icon { font-size: 17px; width: 22px; text-align: center; }

.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.user-chip {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.user-chip strong { color: var(--text); display: block; font-size: 13px; }

/* ── MAIN ── */
.main {
  grid-column: 2;
  grid-row: 2;
  padding: 32px 36px;
  min-height: 0;
}

/* ── SECTIONS ── */
.section { display: none; }
.section.active { display: block; }

/* ── PAGE HEADER ── */
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p { color: var(--text-muted); margin-top: 4px; font-size: 13px; }

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ── STAT CARDS ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-unit { font-size: 14px; font-weight: 400; color: var(--text-muted); }
.stat-delta { font-size: 12px; margin-top: 5px; }
.delta-up { color: var(--success); }
.delta-down { color: var(--danger); }
.delta-neutral { color: var(--text-muted); }

/* ── GRID ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

/* ── FORM ── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 6px; }

.form-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }

.input-with-unit {
  position: relative;
}
.input-with-unit .form-input { padding-right: 36px; }
.input-with-unit .unit {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── BUTTONS ── */
.btn {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #0a0a16; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: rgba(255,255,255,0.06); }
.btn-danger { background: rgba(248,113,113,0.12); color: var(--danger); border: 1px solid rgba(248,113,113,0.2); }
.btn-danger:hover { background: rgba(248,113,113,0.22); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── TABLE ── */
.table-wrap { overflow-x: auto; margin: -4px; padding: 4px; }
table { width: 100%; border-collapse: collapse; min-width: 400px; }
th { padding: 8px 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }
.td-muted { color: var(--text-muted); }

/* ── CHART ── */
.chart-wrap { position: relative; height: 300px; width: 100%; }
.chart-wrap canvas { display: block; }

/* ── ALERTS ── */
.alert { padding: 11px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.alert-error { background: rgba(248,113,113,0.1); border: 1px solid rgba(248,113,113,0.25); color: var(--danger); }
.alert-success { background: rgba(52,211,153,0.1); border: 1px solid rgba(52,211,153,0.25); color: var(--success); }

/* ── BADGE ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-admin { background: rgba(167,139,250,0.15); color: var(--accent-2); }
.badge-user { background: rgba(244,114,182,0.15); color: var(--accent); }

/* ── TABS ── */
.tabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.tab { flex: 1; padding: 8px; border-radius: 7px; border: none; background: none; color: var(--text-muted); font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.15s; font-family: inherit; text-align: center; }
.tab.active { background: var(--surface); color: var(--text); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── EMPTY STATE ── */
.empty { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-icon { font-size: 42px; margin-bottom: 10px; }
.empty-text { font-size: 14px; }

/* ── MODAL ── */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center; justify-content: center;
  z-index: 200;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  margin: 16px;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 18px; }

/* ── WORKOUT ITEM ── */
.workout-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.workout-item:last-child { border-bottom: none; }
.workout-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-top: 5px; flex-shrink: 0; }
.workout-info { flex: 1; }
.workout-title { font-weight: 600; font-size: 14px; }
.workout-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.workout-notes { font-size: 13px; color: var(--text-muted); margin-top: 5px; }

/* ── BOTTOM NAV (mobile) ── */
.bottom-nav { display: none; }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  #app-wrap {
    grid-template-columns: 1fr;
    grid-template-rows: 54px 1fr;
  }
  .sidebar { display: none; }
  .topbar { grid-column: 1; }

  .main {
    grid-column: 1;
    padding: 16px;
    padding-bottom: 76px;
  }

  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .page-header h1 { font-size: 20px; }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 100;
    justify-content: space-around;
    padding: 6px 0 10px;
  }

  .bn-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 10px;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 10px;
    font-weight: 500;
    transition: color 0.15s;
    flex: 1;
  }

  .bn-link .bn-icon { font-size: 20px; }
  .bn-link.active { color: var(--accent); }
}

/* ── LOGIN PAGE ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo .logo-icon { font-size: 40px; margin-bottom: 8px; }
.login-logo h1 {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.login-logo p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── DIVIDER ── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }

/* ── PAIR MEASUREMENT BLOCKS ── */
.pair-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 210px));
  gap: 12px;
  margin-top: 16px;
  justify-content: start;
}

.measure-pair {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 12px;
}

.pair-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.pair-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.pair-row:last-child { margin-bottom: 0; }

.pair-side {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  width: 16px;
  flex-shrink: 0;
  text-transform: uppercase;
}


/* ── PERIOD FILTER ── */
.period-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}
.period-btn {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  letter-spacing: 0.02em;
}
.period-btn.active {
  background: rgba(148,163,184,0.15);
  border-color: var(--text-muted);
  color: var(--text);
}
.period-btn:hover:not(.active) {
  border-color: var(--text-muted);
  color: var(--text);
}

/* ── METRIC SELECTOR ── */
.metric-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.metric-chip {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.metric-chip.active {
  background: rgba(244,114,182,0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── CONFIGURABLE STAT CARDS ── */
.stat-configurable {
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s;
}
.stat-configurable:hover { border-color: rgba(244,114,182,0.3); }
.stat-config-hint {
  font-size: 9px;
  color: var(--text-muted);
  opacity: 0.6;
  margin-left: 3px;
}

/* ── STAT PICKER DROPDOWN ── */
.stat-picker {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,0.6);
  z-index: 500;
  display: none;
  min-width: 190px;
  max-height: 320px;
  overflow-y: auto;
}
.stat-picker.open { display: block; }
.picker-item {
  display: block;
  width: 100%;
  padding: 9px 14px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.1s;
  white-space: nowrap;
}
.picker-item:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.picker-item.active { color: var(--accent); background: rgba(244,114,182,0.08); }

/* ── SETTINGS MODAL ── */
.settings-block { margin-bottom: 20px; }
.settings-block .lang-btns,
.settings-block .unit-btns { margin-top: 8px; gap: 8px; }
.settings-block .lang-btn,
.settings-block .unit-btn { padding: 9px 8px; font-size: 13px; }

/* ── SECTION ACTIONS BAR ── */
.section-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
}
.section-actions .spacer { flex: 1; }
