:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --border: #334155;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;

  /* Цветове по код на смяна */
  --c-day: #f59e0b;     /* D - ден */
  --c-night: #6366f1;   /* N - нощ */
  --c-office: #10b981;  /* R/RM/RL - офис */
  --c-train: #a855f7;   /* C - обучение */
  --c-off: #475569;     /* OFF - почивка */
  --c-vac: #06b6d4;     /* V - отпуск */
  --c-ill: #ef4444;     /* ILL - болничен */

  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;          /* без хоризонтален скрол на цялата страница */
  max-width: 100%;
  /* без маркиране/копиране при задържане (усещане на нативно приложение) */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
/* полетата за въвеждане остават нормални */
input, textarea, select {
  -webkit-user-select: text;
  user-select: text;
}
body.modal-open { overflow: hidden; }   /* при отворен попъп фонът не скролва */

.hidden { display: none !important; }

/* ---------- Екран за име ---------- */
.screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(16px, 5vw, 40px);
}
.name-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(20px, 5vw, 32px);
  box-shadow: var(--shadow);
}
.name-card h1 {
  margin: 0 0 4px;
  font-size: clamp(1.6rem, 6vw, 2rem);
  background: linear-gradient(90deg, var(--accent), #818cf8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { color: var(--text-dim); margin: 0 0 20px; }
.name-card label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 6px; }
.name-card select,
.name-card input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 18px;
}
.hint { color: var(--text-dim); font-size: 0.8rem; margin: 12px 0 0; min-height: 1em; }

.btn-primary {
  width: 100%;
  padding: 13px 16px;
  font-size: 1rem;
  font-weight: 600;
  color: #06121f;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.btn-primary:active { transform: translateY(1px); }

.btn-ghost {
  padding: 8px 12px;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
}
.btn-ghost:active { transform: translateY(1px); }
.btn-ghost.on { background: var(--c-office); color: #06121f; border-color: var(--c-office); font-weight: 700; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px clamp(12px, 4vw, 24px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.current-user {
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  font-weight: 800;
  background: linear-gradient(90deg, var(--accent), #818cf8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.topbar-right {
  position: absolute;
  right: clamp(12px, 4vw, 24px);
  top: 50%;
  transform: translateY(-50%);
}
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform 0.2s ease, background 0.2s ease;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn[aria-expanded="true"] { transform: rotate(45deg); background: var(--accent); color: #06121f; }

.settings-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 60;
}
.settings-menu.hidden { display: none; }
.settings-head {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim); padding: 6px 10px 2px;
}
.settings-status { padding: 0 10px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.sync-status { font-size: 0.72rem; color: var(--text-dim); }
.menu-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 11px 12px;
  font-size: 0.95rem;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item:active { transform: translateY(1px); }
.menu-item.on { background: var(--c-office); color: #06121f; font-weight: 700; }

/* ---------- Личен панел ---------- */
.panel { padding: clamp(12px, 4vw, 24px); display: grid; gap: 14px; }

.clock-card {
  background: linear-gradient(135deg, #0b3b54, #1e293b);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  box-shadow: var(--shadow);
}
.clock-time {
  font-size: clamp(2.4rem, 11vw, 3.4rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  color: #f1f5f9;
}
.clock-status {
  margin-top: 8px;
  display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap;
  color: var(--text-dim); font-size: 0.95rem;
}
.clock-countdown {
  margin-top: 10px;
  font-size: clamp(1rem, 4.5vw, 1.25rem);
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.clock-countdown.ending { color: #f87171; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.status-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.status-hero .date-line { color: var(--text-dim); font-size: 0.85rem; }
.status-hero .status-main {
  display: flex; align-items: center; gap: 12px; margin-top: 6px; flex-wrap: wrap;
}
.status-hero .status-main .big-badge {
  font-size: 1.05rem; padding: 8px 16px; border-radius: 999px; font-weight: 700;
}
.status-hero .status-text { font-size: 1.05rem; }

.cards-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}
@media (min-width: 720px) {
  .cards-grid { grid-template-columns: repeat(3, 1fr); }
}

.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.info-card h3 {
  margin: 0 0 12px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.people-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.people-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 8px; background: var(--bg-2);
}
.people-list .empty { color: var(--text-dim); background: none; padding: 0; }
.person-name { font-size: 0.92rem; }
.next-line { font-size: 0.95rem; }
.next-date { color: var(--accent); font-weight: 600; }

/* ---------- Баджове за код ---------- */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; padding: 3px 8px; border-radius: 7px;
  font-weight: 700; font-size: 0.8rem; color: #0b1220;
}
.badge.code-D { background: var(--c-day); }
.badge.code-N { background: var(--c-night); color: #fff; }
.badge.code-R, .badge.code-RM, .badge.code-RL { background: var(--c-office); }
.badge.code-C { background: var(--c-train); color: #fff; }
.badge.code-OFF { background: var(--c-off); color: #cbd5e1; }
.badge.code-V { background: var(--c-vac); }
.badge.code-ILL { background: var(--c-ill); color: #fff; }
.badge.code-empty { background: transparent; color: var(--text-dim); }

/* ---------- Пълен график ---------- */
.schedule-section { padding: 0 clamp(12px, 4vw, 24px) 24px; }
.schedule-controls {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.schedule-controls h2 { margin: 0; font-size: 1.1rem; }
.month-tabs {
  display: flex; gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.month-tab {
  flex: 0 0 auto;
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  font-size: 0.85rem;
  white-space: nowrap;
}
.month-tab[aria-selected="true"] {
  background: var(--accent); color: #06121f; border-color: var(--accent); font-weight: 700;
}
.month-tab.spec {
  background: rgba(234, 179, 8, 0.18);
  border-color: #ca8a04;
  color: #fde68a;
}
.month-tab.spec[aria-selected="true"] {
  background: #eab308; color: #1a1500; border-color: #eab308; font-weight: 700;
}

.spec-banner {
  padding: 8px 16px;
  background: rgba(234, 179, 8, 0.14);
  border-bottom: 1px solid var(--border);
  color: #fde68a;
  font-size: 0.82rem;
}
.spec-banner.hidden { display: none; }

.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 70dvh;
  touch-action: none; /* осите се заключват ръчно в JS (само ляво/дясно ИЛИ горе/долу) */
  overscroll-behavior: contain;
}
.schedule-table { border-collapse: separate; border-spacing: 0; width: max-content; font-size: 0.82rem; }
.schedule-table th, .schedule-table td {
  padding: 6px 8px; text-align: center; white-space: nowrap; border-bottom: 1px solid var(--border);
}

/* sticky горен ред с дати */
.schedule-table thead th {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg-2); color: var(--text-dim); font-weight: 600;
}
.schedule-table thead th.today-col { color: var(--accent); }

/* sticky лява колона с имена */
.schedule-table .name-col {
  position: sticky; left: 0; z-index: 10;
  background: var(--surface); text-align: left; min-width: 150px;
  border-right: 1px solid var(--border); font-weight: 600;
}
/* ъгълът (име + дати) най-горе вляво */
.schedule-table thead th.name-col { z-index: 25; background: var(--bg-2); }

/* Текущият потребител — дните се мяркат бледо зад името, но името се чете */
.schedule-table tbody tr.me td { background: rgba(56, 189, 248, 0.12); }
.schedule-table tbody tr.me .name-col {
  color: #e0f2fe;
  font-weight: 800;
  background: rgba(11, 22, 38, 0.82);
  box-shadow: inset 4px 0 0 var(--accent-strong);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95);
}
.schedule-table tbody tr.me .badge { opacity: 1; }
/* Останалите редове — по-прозрачни, за да изпъква твоят */
.schedule-table tbody tr:not(.me) .badge { opacity: 0.6; }

.schedule-table td.today-col { box-shadow: inset 0 0 0 2px var(--accent); }

/* Празнични дни (оранжево, като в Google Sheets) */
.schedule-table thead th.holiday-col { background: #fbe4d5; color: #7c2d12; }
.schedule-table td.holiday-col { background: rgba(251, 228, 213, 0.12); }
.holiday-swatch {
  display: inline-block; width: 18px; height: 18px;
  border-radius: 4px; background: #fbe4d5; border: 1px solid #e9c8b4;
}

.cell { display: inline-flex; min-width: 30px; justify-content: center; }

/* ---------- Бутон за пълния график ---------- */
.open-schedule-section { padding: 0 clamp(12px, 4vw, 24px) 8px; }
.btn-open-schedule {
  width: 100%;
  padding: 15px 18px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #06121f;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}
.btn-open-schedule:active { transform: translateY(1px); }

/* ---------- Попъп ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 3vw, 24px);
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(3px);
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(1100px, 100%);
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-head .month-tabs { width: 100%; min-width: 0; }
.modal-x {
  flex: 0 0 auto;
  margin-left: auto;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: #dc2626;
  color: #fff;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(220, 38, 38, 0.5);
}
.modal-x:hover { background: #ef4444; }
.modal-x:active { transform: translateY(1px); }
.modal-card .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  border: none;
  border-radius: 0;
}
.modal-card .legend {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  margin-top: 0;
}

/* ---------- Легенда ---------- */
.legend {
  display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px;
  font-size: 0.8rem; color: var(--text-dim);
}
.legend .legend-item { display: flex; align-items: center; gap: 6px; }

/* ---------- Footer ---------- */
.footer {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px clamp(12px, 4vw, 24px);
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  color: var(--text-dim); font-size: 0.85rem;
}
.upload-label {
  cursor: pointer; padding: 8px 12px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 18px; box-shadow: var(--shadow); z-index: 50;
  max-width: 90vw; font-size: 0.9rem;
}
