/*
 * Light and Dark: one ink-blue accent on warm neutral greys. Solarized: Ethan
 * Schoonover's light palette (base3 paper, base02 ink, blue accent). Cards sit
 * on --surface-low with a hairline --outline-variant border, no elevation.
 */

:root,
[data-theme="light"] {
  --primary: #1F3A57;
  --on-primary: #FFFFFF;
  --primary-container: #E1E8F0;
  --on-primary-container: #14273B;
  --secondary-container: #E9ECEF;
  --on-secondary-container: #1B2027;
  --background: #F6F6F3;
  --on-surface: #15181C;
  --on-surface-variant: #666B72;
  --surface-lowest: #FFFFFF;
  --surface-low: #FFFFFF;
  --surface-high: #EAEAE5;
  --outline: #B6B9BD;
  --outline-variant: #E4E4DF;
  --error: #B3261E;
  --scrim: rgb(0 0 0 / 0.32);
}

[data-theme="dark"] {
  --primary: #B3C7DE;
  --on-primary: #102336;
  --primary-container: #26394E;
  --on-primary-container: #DCE6F1;
  --secondary-container: #2A3037;
  --on-secondary-container: #DDE2E8;
  --background: #101214;
  --on-surface: #E5E6E8;
  --on-surface-variant: #9BA1A8;
  --surface-lowest: #2B3035;
  --surface-low: #171A1D;
  --surface-high: #212529;
  --outline: #4B5056;
  --outline-variant: #262A2F;
  --error: #F2B8B5;
  --scrim: rgb(0 0 0 / 0.5);
}

[data-theme="solarized"] {
  /* Solarized blue #268BD2 darkened so white text on it stays legible. */
  --primary: #1F6FA8;
  --on-primary: #FFFFFF;
  --primary-container: #DCE9F2;
  --on-primary-container: #0E3A5A;
  --secondary-container: #E3EEE6;
  --on-secondary-container: #073642;
  --background: #FDF6E3;
  --on-surface: #073642;
  --on-surface-variant: #586E75;
  --surface-lowest: #FFFBEF;
  --surface-low: #FFFBEF;
  --surface-high: #EEE8D5;
  --outline: #93A1A1;
  --outline-variant: #E6DFC8;
  --error: #DC322F;
  --scrim: rgb(0 0 0 / 0.32);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--background);
  color: var(--on-surface);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Armenian", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
h1, h2, h3, p { margin: 0; }
a { color: var(--primary); }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

#app {
  height: 100%;
  max-width: 640px;
  margin: 0 auto;
}

.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.icon { fill: currentColor; flex: none; }

/* --- Top bar --- */

.top-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 64px;
  padding: 0 4px;
  flex: none;
}

.top-bar-title {
  flex: 1;
  min-width: 0;
  font-size: 22px;
  font-weight: 400;
  padding-left: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar-title.with-avatar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  font-weight: 600;
}

.top-bar-title.with-avatar span { overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--on-surface);
}

.icon-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--on-surface) 8%, transparent); }
.icon-btn:active:not(:disabled) { background: color-mix(in srgb, var(--on-surface) 12%, transparent); }
.icon-btn:disabled { opacity: 0.38; }

/* --- Scroll areas --- */

.refresh-area {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px 0;
}

.list.tight { gap: 8px; }

.progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 2;
  overflow: hidden;
  background: var(--primary-container);
}

.progress::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 40%;
  background: var(--primary);
  animation: progress 1.2s ease-in-out infinite;
}

@keyframes progress {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}

.pull-indicator {
  position: absolute;
  top: -40px;
  left: 50%;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-lowest);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.2);
  opacity: 0;
  transform: translate(-50%, 0);
  transition: transform 0.2s, opacity 0.2s;
  pointer-events: none;
}

.pull-indicator.pulling { transition: none; }
.pull-indicator .spinner { animation: none; }

/* --- Building blocks --- */

.panel {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  text-align: left;
  border: 1px solid var(--outline-variant);
  border-radius: 16px;
  background: var(--surface-low);
  color: inherit;
  text-decoration: none;
}

.panel.highlighted {
  border: 2px solid var(--primary);
  background: var(--primary-container);
}

.panel.clickable:hover { background: color-mix(in srgb, var(--on-surface) 4%, var(--surface-low)); }
.panel.clickable:active { background: color-mix(in srgb, var(--on-surface) 8%, var(--surface-low)); }

.avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  background: var(--primary-container);
  color: var(--on-primary-container);
  font-size: 14px;
  font-weight: 600;
}

.avatar.small { width: 36px; height: 36px; font-size: 13px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.btn.text { color: var(--primary); padding: 0 12px; }
.btn.text:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.btn.text.danger { color: var(--error); }
.btn.outlined { color: var(--primary); border: 1px solid var(--outline); }

.btn.filled {
  min-height: 48px;
  border-radius: 12px;
  background: var(--primary);
  color: var(--on-primary);
  padding: 0 24px;
}

.btn.filled:disabled { opacity: 0.6; }
.btn.wide { width: 100%; min-height: 52px; }

.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--primary);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner.small { width: 20px; height: 20px; border-width: 2px; }
.spinner.on-primary { border-color: var(--on-primary); border-right-color: transparent; }

@keyframes spin { to { transform: rotate(360deg); } }

.loading-box { display: grid; place-items: center; padding: 48px 0; }

.message-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 56px 32px;
  text-align: center;
  color: var(--on-surface-variant);
}

.message-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface-high);
}

.offline-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  font-size: 14px;
  font-weight: 500;
}

/* --- Children list --- */

.home .list { padding-top: 32px; }

.home-header {
  display: flex;
  align-items: center;
  padding: 0 0 14px 4px;
}

.school-title {
  flex: 1;
  min-width: 0;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
}

.home-header .icon-btn { color: var(--on-surface-variant); }

.child-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
}

.child-row .child-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.child-row .icon { color: var(--outline); }

.empty-children {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 36px 24px;
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 16px;
  border-radius: 50%;
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.empty-children h2 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.empty-children p { font-size: 14px; color: var(--on-surface-variant); margin-bottom: 20px; }

.section-header {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 22px 0 0 4px;
}

.section-header h2 { flex: 1; font-size: 22px; font-weight: 600; }

/* --- Notifications --- */

.notification-head {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  text-align: left;
}

.notification-head:hover { background: color-mix(in srgb, var(--on-surface) 4%, transparent); }

.notification-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
}

.notification-title .title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notification-title .title.unread { font-weight: 700; }
.notification.open .notification-title .title { white-space: normal; }

.unread-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--primary); }

.notification-meta {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--on-surface-variant);
}

.notification-meta .author {
  flex: 1;
  min-width: 0;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notification-body {
  display: flex;
  flex-direction: column;
  padding: 0 16px 8px;
}

.notification-child { font-size: 14px; font-weight: 500; color: var(--primary); margin-bottom: 12px; }
.notification-body .share { align-self: center; margin-top: 4px; }

.rich-text {
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.rich-text p, .rich-text ul, .rich-text ol, .rich-text blockquote { margin: 0 0 0.6em; }
.rich-text > :last-child { margin-bottom: 0; }
.rich-text ul, .rich-text ol { padding-left: 1.4em; }
.rich-text table { border-collapse: collapse; max-width: 100%; display: block; overflow-x: auto; }
.rich-text td, .rich-text th { border: 1px solid var(--outline-variant); padding: 4px 6px; }

/* --- Child screen --- */

.tabs-wrap { padding: 4px 16px 12px; flex: none; }

.segmented {
  display: flex;
  height: 44px;
  padding: 4px;
  border-radius: 22px;
  background: var(--surface-high);
}

.segmented button {
  flex-basis: 0;
  min-width: 0;
  padding: 0 4px;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: var(--on-surface-variant);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}

.segmented.dense button { font-size: 12px; }
.segmented button span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.segmented button.selected { background: var(--surface-lowest); color: var(--on-surface); font-weight: 600; }

.day-strip { display: flex; align-items: center; flex: none; }
.schedule-days { gap: 4px; padding: 0 4px 0 12px; }
.week { padding: 0 4px; }
.week-days { display: flex; flex: 1; gap: 2px; }

.day-cell {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 0;
  padding: 8px 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--on-surface);
  transition: background 0.15s;
}

.day-cell .day-label { font-size: 12px; font-weight: 500; color: var(--on-surface-variant); }
.day-cell .day-number { font-size: 16px; font-weight: 600; }
.day-cell .day-main { font-size: 14px; font-weight: 600; white-space: nowrap; }
.day-cell .day-dot { width: 4px; height: 4px; border-radius: 50%; }
.day-cell.today { color: var(--primary); }
.day-cell.today .day-dot { background: var(--primary); }
.day-cell.selected { background: var(--primary); color: var(--on-primary); }
.day-cell.selected .day-label { color: color-mix(in srgb, var(--on-primary) 75%, transparent); }
.day-cell.selected .day-dot { background: transparent; }
.day-cell.selected.today .day-dot { background: var(--on-primary); }

.lesson {
  display: flex;
  align-items: center;
  padding: 15px 16px;
}

.lesson-number { width: 30px; flex: none; font-weight: 600; color: var(--primary); }
.lesson-subject { flex: 1; min-width: 0; font-weight: 500; }
.lesson-times { padding-left: 12px; font-size: 14px; font-weight: 500; color: var(--on-surface-variant); white-space: nowrap; }
.lesson.free .lesson-number { color: var(--outline); }
.lesson.free .lesson-subject { font-weight: 400; color: var(--on-surface-variant); }
.lesson.current .lesson-number { color: var(--primary); }
.lesson.current .lesson-subject { color: var(--on-primary-container); }
.lesson.current .lesson-times { color: var(--primary); font-weight: 600; }

.date-header {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 8px 6px 20px;
  flex: none;
}

.date-title {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.date-weekday { font-size: 14px; font-weight: 500; color: var(--on-surface-variant); }
.date-day { font-size: 22px; font-weight: 600; }

/* Present for its picker, which opens over the header. */
.date-input {
  position: absolute;
  left: 20px;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.homework { padding: 16px; }
.homework h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.homework h3:last-child { margin-bottom: 0; }

.chip-row {
  display: flex;
  gap: 8px;
  padding: 0 16px 4px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: none;
}

.chip-row::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 16px;
  flex: none;
  border: 1px solid var(--outline);
  border-radius: 8px;
  background: transparent;
  color: var(--on-surface-variant);
  font-size: 14px;
  font-weight: 500;
}

.chip.selected {
  padding-left: 8px;
  border-color: transparent;
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

.journal-subject { padding: 14px 16px; }
.journal-subject h3 { font-size: 16px; font-weight: 500; }
.marks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.mark {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--surface-high);
}

.mark-day { font-size: 12px; font-weight: 500; color: var(--on-surface-variant); white-space: nowrap; }
.mark-value { display: flex; align-items: baseline; gap: 4px; }
.mark-grade { font-size: 16px; font-weight: 600; color: var(--primary); }
.mark.absence .mark-grade { color: var(--error); }
.mark-kind { font-size: 11px; font-weight: 500; color: var(--on-surface-variant); white-space: nowrap; }

.legend { padding: 4px 0 0 4px; font-size: 12px; color: var(--on-surface-variant); }

.absence-total, .absence-row { display: flex; align-items: center; padding: 14px 16px; }
.absence-total span { flex: 1; font-weight: 600; color: var(--on-primary-container); }
.absence-total strong { font-size: 24px; font-weight: 600; color: var(--primary); }
.absence-row { padding: 15px 16px; }
.absence-row span:first-child { flex: 1; font-weight: 500; }
.absence-row .count { padding-left: 12px; font-weight: 600; color: var(--on-surface-variant); }

/* --- Form --- */

.form { display: flex; flex-direction: column; gap: 14px; padding: 8px 20px 0; }
.form .hint { font-size: 14px; color: var(--on-surface-variant); margin-bottom: 2px; }

.field {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label { padding-left: 4px; font-size: 13px; font-weight: 500; color: var(--on-surface-variant); }

.field input {
  height: 56px;
  padding: 0 16px;
  border: 1px solid var(--outline-variant);
  border-radius: 12px;
  background: var(--surface-low);
  outline: none;
  font-size: 16px;
}

.field input:focus { border: 2px solid var(--primary); padding: 0 15px; }
.field input:disabled { opacity: 0.6; }
.field:has(.field-action) input { padding-right: 52px; }

.field-action { position: absolute; right: 4px; bottom: 4px; color: var(--on-surface-variant); }

.form-error { min-height: 0; font-size: 14px; color: var(--error); }
.form-error:empty { display: none; }

/* --- Settings and About --- */

.settings { gap: 20px; }
.option-group { display: flex; flex-direction: column; gap: 8px; }
.group-title { padding-left: 4px; font-size: 14px; font-weight: 500; color: var(--on-surface-variant); }

.options { overflow: hidden; }

.option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px;
  border: 0;
  border-top: 1px solid var(--outline-variant);
  background: transparent;
  text-align: left;
}

.option:first-child { border-top: 0; }
.option:hover { background: color-mix(in srgb, var(--on-surface) 4%, transparent); }
.option-label { flex: 1; }
.option .icon { color: var(--primary); }

.swatch {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  border: 1px solid var(--outline);
  border-radius: 50%;
}

.swatch span { width: 10px; height: 10px; border-radius: 50%; }
.swatch[data-theme="system"] { background: linear-gradient(135deg, #F6F6F3 50%, #101214 50%); }
.swatch[data-theme="system"] span { background: #1F3A57; box-shadow: 0 0 0 1px #B3C7DE; }
.swatch[data-theme="light"] { background: #F6F6F3; }
.swatch[data-theme="light"] span { background: #1F3A57; }
.swatch[data-theme="dark"] { background: #101214; }
.swatch[data-theme="dark"] span { background: #B3C7DE; }
.swatch[data-theme="solarized"] { background: #FDF6E3; }
.swatch[data-theme="solarized"] span { background: #1F6FA8; }

.select-wrap { position: relative; }

.select {
  width: 100%;
  height: 56px;
  padding: 0 48px 0 16px;
  border: 1px solid var(--outline-variant);
  border-radius: 16px;
  background: var(--surface-low);
  appearance: none;
}

.select-wrap .icon {
  position: absolute;
  right: 14px;
  top: 16px;
  transform: rotate(90deg);
  color: var(--on-surface-variant);
  pointer-events: none;
}

.about { gap: 16px; }
.about-head { padding-left: 4px; }
.about-head h2 { font-size: 22px; font-weight: 600; }
.about-head p { font-size: 14px; color: var(--on-surface-variant); }

.rows .row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-top: 1px solid var(--outline-variant);
}

.rows .row:first-child { border-top: 0; }
.row-name { color: var(--on-surface-variant); }
.row-value { flex: 1; text-align: right; overflow-wrap: anywhere; }

.link-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.link-row > div { flex: 1; min-width: 0; }
.link-title { color: var(--primary); }
.link-url { font-size: 12px; color: var(--on-surface-variant); overflow-wrap: anywhere; }
.link-row .icon { color: var(--outline); }

.about-note { padding: 8px 16px; text-align: center; font-size: 14px; color: var(--on-surface-variant); }

/* --- Overlays --- */

.menu-scrim { position: fixed; inset: 0; z-index: 10; }

.menu {
  position: fixed;
  min-width: 200px;
  padding: 8px 0;
  border-radius: 4px;
  background: var(--surface-high);
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.15), 0 6px 16px rgb(0 0 0 / 0.12);
}

.menu button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 48px;
  padding: 0 16px 0 12px;
  border: 0;
  background: transparent;
  text-align: left;
}

.menu button:hover, .menu button:focus-visible { background: color-mix(in srgb, var(--on-surface) 8%, transparent); outline: none; }
.menu .icon { color: var(--on-surface-variant); }

.dialog {
  width: min(90vw, 360px);
  padding: 24px 24px 16px;
  border: 0;
  border-radius: 28px;
  background: var(--surface-high);
  color: var(--on-surface);
}

.dialog::backdrop { background: var(--scrim); }
.dialog h2 { font-size: 22px; font-weight: 400; margin-bottom: 16px; }
.dialog p { font-size: 14px; color: var(--on-surface-variant); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateX(-50%);
  padding: 12px 16px;
  border-radius: 4px;
  background: var(--on-surface);
  color: var(--background);
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01s !important; transition: none !important; }
}
