/* StudyBalance — stile di base. Mobile first: si parte da 360 px. */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1c2030;
  --text-muted: #5b6275;
  --border: #dfe3ec;
  --accent: #3b5bdb;
  --accent-soft: #e7ecff;
  --review: #0f9d7a;
  --radius: 14px;
  --nav-height: 64px;
  --side-width: 220px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1b1e2a;
    --text: #eceef5;
    --text-muted: #a3aabd;
    --border: #2c3142;
    --accent: #8da2fb;
    --accent-soft: #252b47;
    --review: #4fd1ae;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
}

a { color: var(--accent); }

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

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: 8px;
  z-index: 10;
}
.skip-link:focus { top: 8px; }

/* Intestazione */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}
.brand {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--text);
  text-decoration: none;
}
.header-action {
  font-size: 0.9375rem;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 999px;
}
.header-action[aria-current="page"] { background: var(--accent-soft); }

/* Contenuto */
main {
  padding: 4px 16px 24px;
  max-width: 720px;
  margin: 0 auto;
}
main:focus { outline: none; }

h1 {
  font-size: 1.5rem;
  line-height: 1.25;
  margin: 8px 0 4px;
}
.subtitle {
  color: var(--text-muted);
  margin: 0 0 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card h2 {
  font-size: 1rem;
  margin: 0 0 4px;
}
.card p {
  margin: 0;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 8px;
}

.noscript { padding: 16px; }

/* Barra di navigazione in basso */
.app-nav {
  position: fixed;
  inset: auto 0 0 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.app-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-height);
  padding: 6px 2px;
  font-size: 0.6875rem;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  color: var(--text-muted);
}
.app-nav svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.app-nav a[aria-current="page"] {
  color: var(--accent);
  font-weight: 600;
}

/* Schermi larghi: la barra diventa una colonna laterale */
@media (min-width: 900px) {
  body {
    padding-bottom: 0;
    padding-left: var(--side-width);
  }
  .app-nav {
    inset: 0 auto 0 0;
    width: var(--side-width);
    grid-template-columns: 1fr;
    align-content: start;
    gap: 4px;
    padding: 72px 12px 12px;
    border-top: 0;
    border-right: 1px solid var(--border);
  }
  .app-nav a {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    min-height: 44px;
    padding: 8px 12px;
    font-size: 0.9375rem;
    border-radius: 10px;
  }
  .app-nav a[aria-current="page"] { background: var(--accent-soft); }
}

/* ------------------------------------------------------------------ */
/* Moduli, pulsanti e componenti (da T1)                               */
/* ------------------------------------------------------------------ */

:root {
  --danger: #c92a2a;
  --danger-soft: #fdecec;
  --field-bg: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --danger: #ff8787;
    --danger-soft: #3a2024;
    --field-bg: #12141c;
  }
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.hint, .count, .empty, .eyebrow {
  color: var(--text-muted);
  font-size: 0.9375rem;
}
.eyebrow {
  margin: 8px 0 0;
  font-weight: 600;
  color: var(--accent);
}
.card .hint { margin-bottom: 12px; }
.card .count { margin-top: 12px; }
.card .empty { margin: 8px 0 16px; }

/* Pulsanti */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
@media (prefers-color-scheme: dark) {
  .btn-primary { color: #12141c; }
}
.btn-danger {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-quiet-danger {
  border-color: transparent;
  background: transparent;
  color: var(--danger);
}
.btn-small {
  min-height: 40px;
  padding: 6px 10px;
  font-size: 0.875rem;
}

/* Campi */
label, legend {
  display: block;
  padding: 0;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 4px;
}
input[type="text"], input[type="time"], select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--field-bg);
  color: var(--text);
  font: inherit;
}
input[type="color"] {
  width: 56px;
  height: 44px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--field-bg);
}
[aria-invalid="true"] { border-color: var(--danger); }
.field { margin-bottom: 12px; }
.field-grow { flex: 1; min-width: 0; }
.field-error {
  margin: 4px 0 12px;
  color: var(--danger);
  font-size: 0.875rem;
  font-weight: 600;
}
.card p.field-error { color: var(--danger); }

.inline-form { margin-top: 16px; }
.inline-form-row {
  display: flex;
  gap: 8px;
}
.inline-form-row input { flex: 1; min-width: 0; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.form-title {
  font-size: 0.9375rem;
  margin: 16px 0 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.stack {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

/* Materie */
.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
}
.chip {
  min-height: 40px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.chip[aria-pressed="true"]::before { content: "✓ "; }

.dot {
  display: inline-block;
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.subject-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 1.0625rem;
}
.subject-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.subject-card .btn-quiet-danger { margin-top: 4px; padding-left: 0; }

fieldset.level-picker {
  border: 0;
  margin: 0;
  padding: 0;
}
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  border-left: 1px solid var(--border);
}
.segmented label:first-of-type { border-left: 0; }
.segmented input:checked + label {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.segmented input:focus-visible + label {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

/* Orario */
.day-tabs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  margin-bottom: 16px;
}
.day-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 52px;
  padding: 6px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}
.day-tab[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}
@media (prefers-color-scheme: dark) {
  .day-tab[aria-pressed="true"] { color: #12141c; }
}
.day-count { font-size: 0.75rem; opacity: 0.8; }

.lesson-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.lesson-row:first-child { border-top: 0; }
.lesson-row.is-editing { display: block; }
.lesson-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.lesson-time { color: var(--text-muted); font-size: 0.875rem; }
.row-actions { display: flex; gap: 2px; }
.lesson-form-times {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Procedura guidata */
.is-onboarding .app-nav,
.is-onboarding .header-action { display: none; }
body.is-onboarding { padding-bottom: 0; padding-left: 0; }

.wizard-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 12px;
  color: var(--text-muted);
  font-size: 0.875rem;
}
.wizard-progress progress {
  flex: 1;
  height: 8px;
  accent-color: var(--accent);
}
.wizard-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}
.wizard-actions-end { display: flex; gap: 8px; }

/* Impostazioni */
.link-list li { border-top: 1px solid var(--border); }
.link-list li:first-child { border-top: 0; }
.link-list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 0;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.link-meta { color: var(--text-muted); font-weight: 400; font-size: 0.875rem; }

/* Conferme e messaggi */
.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog h2 { margin: 0 0 8px; font-size: 1.125rem; }
.dialog p { margin: 0 0 16px; color: var(--text-muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.status {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9375rem;
  z-index: 20;
}
.is-onboarding .status { bottom: 16px; }
@media (min-width: 900px) {
  .status { bottom: 24px; }
}
