/* ============================================================
   Журнал посещаемости — стили miniapp
   Тёплая, спокойная палитра рабочего инструмента для телефона.
   ============================================================ */

:root {
  --bg:            #FAF7F2;
  --surface:       #FFFFFF;
  --surface-sunk:  #F1ECE3;
  --text:          #2B2622;
  --text-muted:    #8A8178;
  --border:        #E7E0D4;

  --present:       #5B8C6E;
  --present-bg:    #E7F1EA;
  --absent:        #C1694F;
  --absent-bg:     #F6E9E4;
  --weekend-bg:    #EDE7DD;

  --accent:        #B4633F;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow: 0 1px 3px rgba(43, 38, 34, 0.08), 0 1px 2px rgba(43, 38, 34, 0.06);

  color-scheme: light;
}

/* Уважаем тему Telegram, если доступна */
body.tg-dark {
  --bg:            #17140F;
  --surface:       #221D17;
  --surface-sunk:  #2B241C;
  --text:          #F2ECE2;
  --text-muted:    #9B9184;
  --border:        #3A332A;
  --present-bg:    #22352B;
  --absent-bg:     #3A241E;
  --weekend-bg:    #2B241C;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------------- Верхняя панель ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 14px 16px 0;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 19px;
  font-weight: 700;
  margin: 4px 0 12px;
  letter-spacing: -0.01em;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 0 12px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------------- Общий контент ---------------- */
main {
  flex: 1;
  padding: 16px 16px 96px;
}

.view { display: none; }
.view.active { display: block; }

/* ---------------- Навигация по дате ---------------- */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.nav-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-btn:active { transform: scale(0.94); }

.date-display {
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  text-transform: capitalize;
}

.weekend-banner {
  background: var(--weekend-bg);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 8px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.hidden { display: none !important; }

/* ---------------- Сводка ---------------- */
.summary-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.summary-chip {
  flex: 1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.summary-chip b { font-size: 16px; margin-right: 4px; }

.summary-chip.present { background: var(--present-bg); color: var(--present); }
.summary-chip.absent  { background: var(--absent-bg);  color: var(--absent); }

/* ---------------- Список детей ---------------- */
.child-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.child-row {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.child-name {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Переключатель присутствия — пилюля на весь ряд, легко нажать пальцем */
.presence-toggle {
  display: flex;
  border-radius: 999px;
  background: var(--surface-sunk);
  padding: 3px;
  flex-shrink: 0;
}

.presence-toggle button {
  appearance: none;
  border: none;
  background: transparent;
  min-width: 46px;
  height: 34px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}

.presence-toggle button.on.present {
  background: var(--present);
  color: #fff;
}

.presence-toggle button.on.absent {
  background: var(--absent);
  color: #fff;
}

/* Строка ребёнка на вкладке "Месяц" — только сводные цифры, без переключателя */
.month-row {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.month-counts {
  display: flex;
  gap: 10px;
  font-size: 13px;
  font-weight: 700;
}

.month-counts .p { color: var(--present); }
.month-counts .a { color: var(--absent); }

/* Строка ребёнка на вкладке "Дети" — управление */
.manage-row {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.manage-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  appearance: none;
  border: none;
  background: var(--surface-sunk);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  color: var(--text);
}

.icon-btn.danger { color: var(--absent); }

/* ---------------- Кнопки ---------------- */
.primary-btn {
  appearance: none;
  border: none;
  width: 100%;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  padding: 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}

.primary-btn:active { transform: scale(0.985); }

.secondary-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 13px;
  border-radius: var(--radius-md);
  cursor: pointer;
  flex: 1;
}

.danger-btn {
  appearance: none;
  border: none;
  background: var(--absent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  padding: 13px;
  border-radius: var(--radius-md);
  cursor: pointer;
  flex: 1;
}

.export-btn { margin-top: 18px; }

/* ---------------- Пустые состояния ---------------- */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 32px 12px;
}

/* ---------------- Модалки ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 17, 13, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px));
}

.modal h2 {
  font-size: 17px;
  margin: 0 0 14px;
}

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

.field {
  display: block;
  margin-bottom: 12px;
}

.field span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-sunk);
  color: var(--text);
}

.field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

/* ---------------- Тост-уведомления ---------------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.error { background: var(--absent); color: #fff; }

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 0.18s ease; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
