/* ===========================================================================
   Klunik — design system & app styles
   =========================================================================== */
:root {
  color-scheme: light;
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --surface-3: #f1f3f9;
  --border: #e6e8f0;
  --border-strong: #d8dbe7;

  --text: #15182b;
  --text-2: #5b6178;
  --text-3: #9aa0b5;

  --accent: #6366f1;
  --accent-strong: #4f46e5;
  --accent-2: #8b5cf6;
  --accent-soft: #eef0ff;
  --accent-glow: rgba(99, 102, 241, 0.35);

  --incoming: #0aa06e;
  --incoming-soft: #e5f7f0;
  --outgoing: #9333ea;
  --outgoing-soft: #f3e8ff;
  --internal: #d97706;
  --internal-soft: #fdf3e2;
  --star: #f59e0b;
  --danger: #ef4444;
  --danger-soft: #fdecec;

  --toast-bg: #15182b;
  --toast-color: #ffffff;
  --plate-bg: #14161d;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;

  --shadow-sm: 0 1px 2px rgba(21, 24, 43, 0.05), 0 1px 6px rgba(21, 24, 43, 0.05);
  --shadow-md: 0 6px 24px rgba(21, 24, 43, 0.08);
  --shadow-lg: 0 18px 50px rgba(21, 24, 43, 0.18);

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --topbar-h: 64px;
  --player-h: 84px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ===========================================================================
   Dark mode (set via <html data-theme="dark">)
   =========================================================================== */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0e12;
  --surface: #16171d;
  --surface-2: #1c1e24;
  --surface-3: #23252d;
  --border: #2a2c35;
  --border-strong: #3a3d48;

  --text: #f4f5f7;
  --text-2: #b6bac6;
  --text-3: #7d8290;

  --accent: #e77817;
  --accent-strong: #f5933f;
  --accent-2: #f5933f;
  --accent-soft: rgba(231, 120, 23, 0.16);
  --accent-glow: rgba(231, 120, 23, 0.42);

  --incoming: #34d399;
  --incoming-soft: rgba(52, 211, 153, 0.15);
  --outgoing: #c084fc;
  --outgoing-soft: rgba(192, 132, 252, 0.16);
  --internal: #fbbf24;
  --internal-soft: rgba(251, 191, 36, 0.15);
  --star: #fbbf24;
  --danger-soft: rgba(239, 68, 68, 0.16);

  --toast-bg: #262933;
  --toast-color: #f4f5f7;
  --plate-bg: #1c1e26;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45), 0 1px 6px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.65);
}
:root[data-theme="dark"] .topbar { background: rgba(13, 14, 18, 0.88); }
:root[data-theme="dark"] .player-bar { background: rgba(13, 14, 18, 0.94); }
:root[data-theme="dark"] .login-visual {
  background: radial-gradient(1200px 800px at 20% 10%, #4a2c10 0%, #221d18 45%, #0b0b0e 100%);
}
:root[data-theme="dark"] .glow-a { background: #e77817; }
:root[data-theme="dark"] .glow-b { background: #5b6270; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input { font-family: inherit; }
::selection { background: var(--accent-soft); }

.is-hidden { display: none !important; }

/* ------------------------------------------------------------------ icons */
svg { display: block; flex: none; }

/* ============================================================ BUTTONS ==== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 16px;
  transition: transform 0.12s var(--ease), box-shadow 0.15s ease, background 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.28);
}
.btn-primary:hover { box-shadow: 0 10px 26px rgba(99, 102, 241, 0.4); }
.btn-primary:disabled { opacity: 0.6; cursor: default; box-shadow: none; }
.btn-ghost { background: var(--surface); color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--border-strong); color: var(--text); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--text-2);
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ============================================================ LOGIN ===== */
.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  background: var(--bg);
  overflow: hidden;
}
.login-visual {
  position: relative;
  background: radial-gradient(1200px 800px at 20% 10%, #3b3f9e 0%, #1f2157 45%, #131436 100%);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-grid-overlay {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(700px 600px at 50% 50%, #000 20%, transparent 78%);
  -webkit-mask-image: radial-gradient(700px 600px at 50% 50%, #000 20%, transparent 78%);
}
.login-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.55;
  animation: float 14s ease-in-out infinite;
}
.glow-a { width: 380px; height: 380px; background: #6366f1; top: -90px; left: -60px; }
.glow-b { width: 320px; height: 320px; background: #8b5cf6; bottom: -80px; right: -60px; animation-delay: -5s; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -24px) scale(1.06); }
  66% { transform: translate(-22px, 20px) scale(0.96); }
}

.login-brand-wrap {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
}
.login-plate {
  position: relative;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--plate-bg);
  box-shadow: 0 30px 70px rgba(20, 22, 34, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.login-plate::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.login-orbit {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  animation: spin linear infinite;
}
.orbit-1 { animation-duration: 18s; }
.orbit-2 { animation-duration: 11s; animation-direction: reverse; }
.orbit-dot {
  position: absolute;
  display: block;
  top: -3.5px;
  left: -3.5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}
.orbit-dot.dot-sm {
  top: -2.5px;
  left: -2.5px;
  width: 5px;
  height: 5px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login-logo {
  width: 240px;
  max-width: 68%;
  height: auto;
  display: block;
  animation: fadeUp 1s var(--ease) 0.1s both;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.login-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  animation: cardIn 0.7s var(--ease) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(18px) scale(0.98); } to { opacity: 1; transform: none; } }
.login-card-head { text-align: center; margin-bottom: 28px; }
.login-card h1 { font-size: 22px; margin: 0 0 6px; font-weight: 700; }
.login-card p { margin: 0; color: var(--text-2); font-size: 14px; }

.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 7px; }
.field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 15px;
  background: var(--surface-2);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  outline: none;
}
.field input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-pass { position: relative; }
.field-pass input { padding-right: 44px; }
.pass-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border-radius: 8px; font-size: 16px; color: var(--text-3); }
.pass-toggle:hover { background: var(--surface-3); color: var(--text); }

.login-error {
  min-height: 20px;
  margin: 2px 0 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--danger);
  text-align: center;
}
.login-foot { margin-top: 22px; font-size: 12.5px; color: var(--text-3); letter-spacing: 0.04em; text-transform: uppercase; }

/* ============================================================ TOPBAR ==== */
.app-screen { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: rgba(255,255,255,0.86);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 16px; min-width: 0; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { height: 32px; width: auto; display: block; }
.brand-logo.is-white { display: none; }
:root[data-theme="dark"] .brand-logo.is-black { display: none; }
:root[data-theme="dark"] .brand-logo.is-white { display: block; }

.nav-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-3);
  padding: 4px;
  border-radius: var(--r-md);
}
.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.is-active { background: var(--surface); color: var(--accent-strong); box-shadow: var(--shadow-sm); }
.nav-count {
  min-width: 18px; height: 18px;
  display: inline-grid; place-items: center;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--star);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.global-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(320px, 34vw);
  height: 40px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-3);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-history {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 70;
  max-height: 320px;
  overflow-y: auto;
}
.search-history-head {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  padding: 6px 10px 4px;
}
.search-history-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-2);
  text-align: left;
}
.search-history-item:hover { background: var(--surface-3); color: var(--text); }
.search-history-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.global-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); color: var(--accent); }
.global-search input { flex: 1; border: 0; outline: 0; background: none; font-size: 14px; color: var(--text); min-width: 0; }
.global-search kbd { font-size: 11px; color: var(--text-3); border: 1px solid var(--border); border-radius: 5px; padding: 2px 5px; }

.user-menu { position: relative; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 10px;
  background: none;
  border: 0;
  cursor: pointer;
  transition: background 0.15s ease;
}
.user-chip:hover { background: var(--surface-3); }
.user-avatar {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text-2); font-weight: 700; font-size: 14px;
  text-transform: uppercase;
  flex: none;
}
.user-name { font-size: 13.5px; font-weight: 600; color: var(--text-2); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chevron { color: var(--text-3); flex: none; transition: transform 0.2s ease; }
.user-menu.is-open .user-chevron { transform: rotate(180deg); }

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 80;
  animation: menuIn 0.16s var(--ease);
}
@keyframes menuIn { from { opacity: 0; transform: translateY(-6px) scale(0.98); } to { opacity: 1; transform: none; } }
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}
.user-menu-item:hover { background: var(--surface-3); color: var(--text); }
.user-menu-item.danger { color: var(--danger); }
.user-menu-item.danger:hover { background: var(--danger-soft); color: var(--danger); }
.user-menu-sep { height: 1px; background: var(--border); margin: 5px 6px; }
.user-menu-item.user-menu-admin { display: none; }
body.is-admin .user-menu-item.user-menu-admin { display: flex; }

/* ------------------------------------------------- theme switch --------- */
.theme-switch {
  position: relative;
  width: 64px;
  height: 32px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  cursor: pointer;
  flex: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.theme-switch:hover { border-color: var(--border-strong); }
.theme-switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 30px;
  height: 24px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  transition: transform 0.28s var(--ease);
}
:root[data-theme="dark"] .theme-switch-knob { transform: translateX(28px); }
.theme-switch-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  z-index: 1;
  pointer-events: none;
  transition: color 0.2s ease;
}
.theme-switch-icon.sun { left: 10px; color: #fff; }
.theme-switch-icon.moon { right: 10px; color: var(--text-3); }
:root[data-theme="dark"] .theme-switch-icon.sun { color: var(--text-3); }
:root[data-theme="dark"] .theme-switch-icon.moon { color: #fff; }

/* ============================================================ MAIN ====== */
.main {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 26px 24px calc(var(--player-h) + 34px);
}

.view-enter { animation: viewIn 0.35s var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.page-sub { color: var(--text-2); font-size: 13.5px; margin-top: 4px; }

/* ------------------------------------------------------------ cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 22px; }

/* ------------------------------------------------------------ chips --- */
.chips { display: inline-flex; gap: 4px; background: var(--surface-3); padding: 4px; border-radius: var(--r-md); }
.chip {
  padding: 7px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}
.chip:hover { color: var(--text); }
.chip.is-active { background: var(--surface); color: var(--accent-strong); box-shadow: var(--shadow-sm); }
.chip .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }

/* ------------------------------------------------------ segmented ----- */
.segmented { display: inline-flex; gap: 2px; background: var(--surface-3); padding: 3px; border-radius: var(--r-md); }
.segmented button {
  padding: 7px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  transition: all 0.15s ease;
}
.segmented button:hover { color: var(--text); }
.segmented button.is-active { background: var(--surface); color: var(--accent-strong); box-shadow: var(--shadow-sm); }

/* ========================================================= CALENDAR ==== */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-title { font-size: 19px; font-weight: 700; min-width: 160px; text-align: center; letter-spacing: -0.01em; }
.cal-title small { display: block; font-size: 12px; font-weight: 500; color: var(--text-3); margin-top: 1px; }
.cal-nav-btn { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; color: var(--text-2); border: 1px solid var(--border); background: var(--surface); transition: all 0.15s ease; }
.cal-nav-btn:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-2); }

.cal-legend { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }
.legend-dot.in { background: var(--incoming); }
.legend-dot.out { background: var(--outgoing); }
.legend-dot.int { background: var(--internal); }

.cal-stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-pill {
  display: flex; align-items: center; gap: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 9px 14px;
  box-shadow: var(--shadow-sm);
}
.stat-pill .stat-dot { width: 9px; height: 9px; border-radius: 50%; }
.stat-pill .stat-num { font-weight: 700; font-size: 15px; }
.stat-pill .stat-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }

/* ---------------------------------------------- month grid ----------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.cal-dow { text-align: center; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); padding: 6px 0; }
.cal-day {
  position: relative;
  min-height: 84px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 9px;
  cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.15s ease, border-color 0.15s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cal-day:hover:not(.is-empty) { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--accent); }
.cal-day.is-empty { opacity: 0.42; cursor: default; background: var(--surface-2); }
.cal-day.is-empty:hover { transform: none; box-shadow: none; }
.cal-day.is-outside { opacity: 0.55; }
.cal-day.is-today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-day.is-selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-glow); }
.cal-day-top { display: flex; align-items: center; justify-content: space-between; }
.cal-day-num { font-size: 13px; font-weight: 700; color: var(--text); }
.cal-day.is-today .cal-day-num { color: var(--accent-strong); }
.cal-day-total {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.4;
  padding: 0 7px;
  border-radius: 999px;
  background: #2014b6;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}
.cal-day-counts { display: flex; gap: 4px; flex-wrap: wrap; margin-top: auto; }
.cal-count {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.5;
  padding: 0 6px;
  border-radius: 7px;
  font-variant-numeric: tabular-nums;
}
.cal-count.in { background: var(--incoming-soft); color: var(--incoming); }
.cal-count.out { background: var(--outgoing-soft); color: var(--outgoing); }
.cal-count.int { background: var(--internal-soft); color: var(--internal); }

/* ---------------------------------------------- week view ------------- */
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; }
.week-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px;
  cursor: pointer;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.15s var(--ease), box-shadow 0.15s ease, border-color 0.15s ease;
}
.week-day:hover:not(.is-empty) { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--accent); }
.week-day.is-empty { opacity: 0.45; cursor: default; }
.week-day.is-today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.week-day.is-selected { background: var(--accent-soft); border-color: var(--accent); }
.week-day-head { display: flex; align-items: center; justify-content: space-between; }
.week-day-name { font-size: 12px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; }
.week-day-num { font-size: 20px; font-weight: 800; }
.week-day-count { font-size: 11px; font-weight: 600; color: var(--text-3); }
.week-counts { border-collapse: collapse; margin-top: 10px; }
.week-count td { padding: 1px 0; font-size: 13px; font-weight: 600; line-height: 1.4; }
.week-count .wc-num { text-align: right; padding-right: 8px; font-variant-numeric: tabular-nums; }
.week-count .wc-label { text-align: left; }
.week-count.in td { color: var(--incoming); }
.week-count.out td { color: var(--outgoing); }
.week-count.int td { color: var(--internal); }
.week-count.total td { color: #2014b6; }
:root[data-theme="dark"] .week-count.total td { color: #8b96ff; }
.week-preview { display: flex; flex-direction: column; gap: 5px; margin-top: auto; }
.week-preview-item { font-size: 11.5px; color: var(--text-2); display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; }
.week-preview-item .t { font-weight: 600; color: var(--text); }
.week-more { font-size: 11px; color: var(--text-3); font-weight: 600; }

/* ---------------------------------------------- year view ------------- */
.year-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.year-month { padding: 12px; text-align: center; }
.year-month-title { font-size: 13px; font-weight: 700; margin-bottom: 10px; }
.year-mini { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.year-mini-dow { font-size: 8.5px; color: var(--text-3); font-weight: 700; text-transform: uppercase; }
.year-mini-day { height: 16px; border-radius: 4px; font-size: 9px; display: grid; place-items: center; color: var(--text-3); }
.year-mini-day.has { background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; cursor: pointer; }
.year-mini-day.has:hover { background: var(--accent); color: #fff; }
.year-mini-day.today { box-shadow: inset 0 0 0 1px var(--accent); }

/* ======================================================= DAY PANEL ==== */
.day-panel { position: fixed; inset: 0; z-index: 80; }
.day-panel-scrim {
  position: absolute; inset: 0;
  background: rgba(15, 17, 40, 0.32);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.28s ease;
}
.day-panel-body {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(680px, 94vw);
  background: var(--bg);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.34s var(--ease), bottom 0.34s var(--ease);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
}
/* When the player is open, the panel stops above it so the player stays visible. */
body.player-open .day-panel-body { bottom: var(--player-h); }
.day-panel.is-open .day-panel-scrim { opacity: 1; }
.day-panel.is-open .day-panel-body { transform: translateX(0); }

/* The content wrapper must participate in the flex chain so the inner list
   actually scrolls (otherwise it grows past the panel with no scrollbar). */
#day-panel-content { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.day-panel-inner { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.day-panel-head {
  padding: 18px 20px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.day-panel-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.day-panel-date { font-size: 18px; font-weight: 700; }
.day-panel-date small { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-top: 3px; }
.day-panel-tools { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.day-filter { flex: 1; min-width: 160px; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); color: var(--text-3); }
.day-filter:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.day-filter input { flex: 1; border: 0; outline: 0; background: none; font-size: 13.5px; color: var(--text); min-width: 0; }

.day-panel-body-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 20px 20px; }
.day-summary { font-size: 13px; color: var(--text-2); margin-bottom: 12px; font-weight: 500; }
.day-list { display: flex; flex-direction: column; gap: 8px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}
.empty-state svg { margin: 0 auto 14px; color: var(--border-strong); }
.empty-state h3 { margin: 0 0 6px; font-size: 16px; color: var(--text-2); }
.empty-state p { margin: 0; font-size: 13.5px; }

/* ------------------------------------------------------ call row ------ */
.call-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: transform 0.14s var(--ease), box-shadow 0.14s ease, border-color 0.14s ease;
  animation: rowIn 0.3s var(--ease) both;
}
@keyframes rowIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.call-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.call-row.is-playing { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-glow); }

.dir-badge {
  width: 40px; height: 40px;
  border-radius: 11px;
  display: grid; place-items: center;
  flex: none;
}
.dir-badge.in { background: var(--incoming-soft); color: var(--incoming); }
.dir-badge.out { background: var(--outgoing-soft); color: var(--outgoing); }
.dir-badge.int { background: var(--internal-soft); color: var(--internal); }

.call-main { flex: 1; min-width: 0; }
.call-line1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.call-time { font-weight: 700; font-size: 14px; letter-spacing: 0.01em; }
.call-dir-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 8px; border-radius: 6px; }
.call-dir-label.in { background: var(--incoming-soft); color: var(--incoming); }
.call-dir-label.out { background: var(--outgoing-soft); color: var(--outgoing); }
.call-dir-label.int { background: var(--internal-soft); color: var(--internal); }
.call-dir-label.noaudio { background: var(--surface-3); color: var(--text-3); }
.call-row.is-unplayable { opacity: 0.72; }
.call-row.is-unplayable .call-num, .call-row.is-unplayable .call-arrow { color: var(--text-3); }
.call-line2 { display: flex; align-items: center; gap: 7px; color: var(--text-2); font-size: 13.5px; margin-top: 3px; min-width: 0; }
.call-num { font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-arrow { color: var(--text-3); flex: none; }
.call-duration { margin-left: auto; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; flex: none; }

.call-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.star-btn { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: var(--text-3); transition: all 0.15s ease; }
.star-btn:hover { background: var(--surface-3); color: var(--star); }
.star-btn.is-on { color: var(--star); }
.star-btn.is-on svg { fill: var(--star); }
.play-btn {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 6px 16px rgba(99,102,241,0.3);
  transition: transform 0.12s var(--ease), box-shadow 0.15s ease;
}
.play-btn:hover { box-shadow: 0 8px 20px rgba(99,102,241,0.42); transform: translateY(-1px); }
.play-btn.is-active { background: #4b5563; }

/* ====================================================== FAVORITES ====== */
.fav-group { margin-bottom: 22px; }
.fav-group-head { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.fav-group-date { font-size: 15px; font-weight: 700; }
.fav-group-count { font-size: 12px; font-weight: 700; color: var(--accent-strong); background: var(--accent-soft); border-radius: 8px; padding: 2px 8px; }
.fav-row { display: flex; align-items: center; gap: 13px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: 8px; }
.fav-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.fav-note-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; margin-top: 3px; }
.fav-note-input {
  border: 1px solid transparent;
  background: transparent;
  font-size: 13px;
  color: var(--text-2);
  padding: 4px 8px;
  border-radius: 7px;
  outline: none;
  min-width: 0;
  flex: 1;
  transition: all 0.15s ease;
}
.fav-note-input:hover { background: var(--surface-2); }
.fav-note-input:focus { border-color: var(--accent); background: var(--surface); color: var(--text); box-shadow: 0 0 0 3px var(--accent-soft); }
.fav-note-input::placeholder { color: var(--text-3); font-style: italic; }

/* ======================================================== SEARCH ======= */
.search-results-meta { font-size: 13px; color: var(--text-2); margin-bottom: 14px; font-weight: 500; }
.search-result .call-line2 { gap: 6px; }
.search-date-pill { font-size: 11.5px; font-weight: 700; color: var(--accent-strong); background: var(--accent-soft); padding: 2px 8px; border-radius: 6px; flex: none; }

/* ========================================================== PLAYER ===== */
.player-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 90; /* above the day panel (80) so it is never covered or dimmed */
  height: var(--player-h);
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 30px rgba(21,24,43,0.08);
  animation: playerUp 0.3s var(--ease);
}
@keyframes playerUp { from { transform: translateY(100%); } to { transform: none; } }
.player-inner {
  height: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 22px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.player-play {
  width: 46px; height: 46px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 8px 20px rgba(99,102,241,0.32);
  transition: transform 0.12s var(--ease);
  flex: none;
}
.player-play:hover { transform: scale(1.05); }
.player-meta { width: 220px; min-width: 0; flex: none; }
.player-title { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-sub { font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-progress { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.player-times { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.player-volume { display: flex; align-items: center; gap: 4px; flex: none; }
.player-boost { flex: none; margin-left: 2px; }
.player-boost button { font-size: 11.5px; padding: 5px 9px; font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 4px;
  background: var(--surface-3);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 1px 5px rgba(0,0,0,0.25);
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
}
.player-progress input[type="range"] { width: 100%; background: linear-gradient(90deg, var(--accent) var(--fill, 0%), var(--surface-3) var(--fill, 0%)); }
.player-volume input[type="range"] { width: 90px; }

/* ========================================================== TOAST ======= */
.toast-root { position: fixed; bottom: calc(var(--player-h) + 18px); right: 20px; z-index: 120; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 240px; max-width: 340px;
  background: var(--toast-bg);
  color: var(--toast-color);
  border-radius: var(--r-md);
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.3s var(--ease);
}
.toast.is-error { background: var(--danger); }
.toast.is-out { animation: toastOut 0.3s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(12px) scale(0.97); } }

/* ============================================================ MODAL ===== */
.modal-root { position: fixed; inset: 0; z-index: 120; }
.modal-scrim {
  position: absolute; inset: 0;
  background: rgba(15, 17, 40, 0.42);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.modal-card {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s var(--ease);
}
.modal-root.is-open .modal-scrim { opacity: 1; }
.modal-root.is-open .modal-card { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.modal-title { font-size: 18px; font-weight: 700; margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.confirm-msg { color: var(--text-2); font-size: 14px; line-height: 1.5; margin: 0; }
.form-hint { font-size: 12.5px; color: var(--text-3); line-height: 1.5; margin-top: 12px; }
.form-error { font-size: 13px; color: var(--danger); min-height: 18px; margin-top: 8px; font-weight: 500; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

/* ==================================================== ADMIN VIEWS ====== */
.input {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 14px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.select { width: auto; min-width: 180px; }
.section-title { font-size: 14px; font-weight: 700; margin: 0 0 14px; }
.checkbox { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--text-2); font-weight: 500; cursor: pointer; white-space: nowrap; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); }

.users-add-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.users-add-form .input { width: auto; flex: 1; min-width: 160px; }
.users-add-form .checkbox { align-self: center; }
.users-add-form .field-pass { position: relative; flex: 1; min-width: 160px; }
.users-add-form .field-pass .input { width: 100%; flex: none; }

.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.admin-table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table .ta-right { text-align: right; }
.admin-table .muted { color: var(--text-3); }
.admin-table .nowrap { white-space: nowrap; }
.user-cell { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text); }
.table-avatar {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  flex: none;
}

.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 6px; font-size: 11px; font-weight: 700; background: var(--surface-3); color: var(--text-2); }
.badge-admin { background: var(--accent-soft); color: var(--accent-strong); }
.badge.act-login { background: var(--incoming-soft); color: var(--incoming); }
.badge.act-logout { background: var(--surface-3); color: var(--text-2); }
.badge.act-play { background: var(--outgoing-soft); color: var(--outgoing); }
.badge.act-pwd { background: var(--internal-soft); color: var(--internal); }
.badge.act-user { background: var(--incoming-soft); color: var(--incoming); }
.badge.act-del { background: var(--danger-soft); color: var(--danger); }

.row-actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }

.logs-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.field-inline { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.logs-empty { text-align: center; padding: 30px; color: var(--text-3); }

/* ======================================================== RESPONSIVE === */
@media (max-width: 900px) {
  .login-screen { grid-template-columns: 1fr; }
  .login-visual { display: none; }
  .user-name { display: none; }
  .global-search { width: 150px; }
  .player-meta { width: 150px; }
  .player-volume { display: none; }
  .player-boost { display: none; }
}
@media (max-width: 620px) {
  .nav-tab span { display: none; }
  .global-search { display: none; }
  .player-meta { display: none; }
  .cal-day { min-height: 56px; padding: 6px; }
  .cal-day-counts { gap: 3px; }
  .cal-count { padding: 0 4px; font-size: 11px; }
  .cal-day-total { font-size: 13px; padding: 0 5px; }
  .week-grid { grid-template-columns: repeat(2, 1fr); }
}
