:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-soft: #edf6fa;
  --ink: #071625;
  --muted: #52627a;
  --line: #d7e1ea;
  --accent: #0b6680;
  --accent-soft: #e5f4f8;
  --shadow: 0 18px 46px rgba(28, 44, 64, 0.08);
  --focus: #f3be35;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

.auth-locked {
  overflow: hidden;
}

.auth-locked .app-shell {
  display: none;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(11, 102, 128, 0.12), transparent 42%),
    var(--bg);
}

.login-card {
  width: min(100%, 430px);
  display: grid;
  gap: 12px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card .brand-mark {
  width: 42px;
  height: 42px;
  font-size: 1rem;
}

.login-card h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3rem);
  line-height: 1;
}

.login-card p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.login-card label {
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
}

.login-card input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid #bad0dd;
  border-radius: 8px;
  outline: none;
  color: var(--ink);
  background: #f8fbfd;
  font: inherit;
}

.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(243, 190, 53, 0.38);
}

.login-card button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 900;
}

.login-error {
  min-height: 20px;
  color: #a33b23 !important;
  font-weight: 800;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 202px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 8px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 2px;
  min-height: 38px;
}

.brand-mark {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-size: 0.82rem;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
  letter-spacing: 0;
}

.brand strong {
  font-size: 0.72rem;
  font-weight: 900;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.62rem;
}

.side-nav {
  display: grid;
  align-content: start;
  gap: 8px;
  padding-top: 12px;
}

.side-nav a {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  color: #35445b;
  font-size: 0.82rem;
  font-weight: 850;
}

.side-nav a.active {
  color: #005a78;
  background: var(--accent-soft);
}

.workspace {
  height: 100vh;
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 18px;
  overflow: hidden;
}

.view {
  display: none;
  min-height: 0;
}

.active-view {
  display: grid;
  gap: 14px;
  min-height: 0;
  overflow: auto;
}

#report-view.active-view {
  min-height: 100%;
  overflow: auto;
}

.topbar {
  min-height: 45px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -18px -18px 4px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar h1 {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.1;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.7rem;
}

.mode-switch {
  display: flex;
  gap: 8px;
}

.mode-switch button {
  min-height: 31px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: #102033;
  background: #ffffff;
  font-size: 0.74rem;
  font-weight: 900;
}

.mode-switch button.active {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

.hero-panel {
  padding: clamp(18px, 2.4vw, 26px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 10px;
  color: #007096;
  font-size: 0.72rem;
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
}

.hero-panel h2 {
  margin: 0;
  font-size: clamp(1.8rem, 2.8vw, 2.7rem);
  line-height: 1;
  letter-spacing: 0;
}

.hero-panel p:last-child {
  max-width: 720px;
  margin: 10px 0 0;
  color: #35445b;
  font-size: 0.86rem;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-content: start;
}

.category-card {
  min-height: clamp(118px, 13vw, 132px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 13px 14px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
  touch-action: manipulation;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.card-icon {
  width: clamp(58px, 6vw, 74px);
  height: clamp(58px, 6vw, 74px);
  display: grid;
  place-items: center;
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  border-radius: 8px;
  color: var(--accent);
  background: var(--accent-soft);
}

.card-icon svg {
  width: 62%;
  height: 62%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.category-card:hover {
  border-color: rgba(11, 102, 128, 0.36);
  box-shadow: 0 24px 56px rgba(28, 44, 64, 0.12);
  transform: translateY(-2px);
}

.category-card:active {
  transform: translateY(1px);
}

.category-card:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.card-kicker {
  grid-column: 1;
  grid-row: 1;
  align-self: start;
  color: #006d92;
  font-size: 0.72rem;
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
}

.card-title {
  grid-column: 1;
  grid-row: 2;
  align-self: center;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  min-height: auto;
  border-radius: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font-size: clamp(1.8rem, 2.7vw, 2.45rem);
  font-weight: 950;
  line-height: 1;
}

.health .card-title {
  color: #167460;
}

.health .card-icon {
  color: #167460;
  background: #e6f5ef;
}

.hygiene .card-title {
  color: #176f9a;
}

.hygiene .card-icon {
  color: #176f9a;
  background: #e8f4fa;
}

.food .card-title {
  color: #8a661f;
}

.food .card-icon {
  color: #8a661f;
  background: #fbf3df;
}

.sleep .card-title {
  color: #596aa3;
}

.sleep .card-icon {
  color: #596aa3;
  background: #eef1fb;
}

.social .card-title {
  color: #9a4d76;
}

.social .card-icon {
  color: #9a4d76;
  background: #faedf4;
}

.family .card-title {
  color: #18756f;
}

.family .card-icon {
  color: #18756f;
  background: #e6f5f3;
}

.usage-report {
  width: 100%;
  display: grid;
  grid-template-rows: auto;
  gap: 14px;
  margin-top: 4px;
  overflow: visible;
}

.report-heading,
.report-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.report-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
}

.report-heading h2,
.report-card h3 {
  margin: 0;
  letter-spacing: 0;
}

.report-heading h2 {
  font-size: clamp(1.45rem, 2.2vw, 2rem);
  line-height: 1;
}

.report-heading p:last-child {
  max-width: 440px;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
  text-align: right;
}

.report-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 560px), 1fr));
  gap: 14px;
}

.report-grid-wide {
  align-items: start;
  grid-template-columns: 1fr;
}

.report-card {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-auto-rows: auto;
  align-content: start;
  gap: 14px;
  padding: 14px;
  overflow: visible;
}

.report-card header {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.report-card header.collapsible-header {
  align-items: center;
}

.report-card h3 {
  font-size: 1rem;
  line-height: 1.2;
}

.report-card header span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.collapse-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 950;
  text-align: left;
}

.collapse-button span {
  color: var(--ink);
  font-size: 1rem;
  font-weight: 950;
}

.collapse-button::before {
  content: "-";
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 950;
}

.collapse-button[aria-expanded="false"]::before {
  content: "+";
}

#activity-events[hidden],
.activity-events[hidden] {
  display: none !important;
}

.bar-chart {
  min-height: clamp(130px, 18vh, 220px);
  max-height: clamp(180px, 28vh, 320px);
  overflow: auto;
  padding-right: 4px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(0, 1.4fr) auto;
  gap: 10px;
  align-items: center;
}

.bar-label {
  min-width: 0;
  color: #243348;
  font-size: 0.82rem;
  font-weight: 850;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  min-width: 0;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: #e8eef5;
}

.bar-fill {
  width: var(--bar-width);
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.bar-count {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.empty-state {
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 0.85rem;
}

.table-wrap {
  width: 100%;
  min-height: clamp(150px, 22vh, 240px);
  max-height: clamp(220px, 34vh, 380px);
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 460px;
}

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid #e7edf4;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #006d92;
  background: var(--surface);
  font-size: 0.72rem;
  font-weight: 950;
  text-transform: uppercase;
}

td {
  color: #27364a;
  font-size: 0.82rem;
  line-height: 1.25;
}

td strong {
  color: var(--ink);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.timeline-list {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.timeline-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border: 1px solid #dbe6ee;
  border-radius: 8px;
  background: #f8fbfd;
}

.timeline-toolbar strong {
  display: block;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 950;
}

.timeline-toolbar span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.timeline-toolbar label {
  display: grid;
  gap: 5px;
}

.month-toggle-button {
  margin-top: 10px;
}

.month-select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 850;
}

.timeline-month-grid {
  min-height: clamp(220px, 34vh, 360px);
  max-height: clamp(320px, 54vh, 560px);
  overflow: auto;
  padding-right: 4px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
  gap: 12px;
  align-content: start;
}

.timeline-item {
  min-width: 0;
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid #dbe6ee;
  border-radius: 8px;
  background: #fbfdff;
}

.timeline-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 850;
}

.timeline-hour {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  border-radius: 8px;
  padding: 0 9px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 950;
}

.timeline-category {
  color: #006d92;
  font-size: 0.75rem;
  font-weight: 950;
  text-transform: uppercase;
}

.timeline-phrase {
  margin: 0;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 850;
  line-height: 1.25;
}

.timeline-date {
  color: var(--muted);
  font-size: 0.74rem;
}

.category-detail {
  align-content: start;
  min-height: calc(100vh - 82px);
  padding: clamp(18px, 2.2vw, 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.detail-head {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) minmax(260px, 0.8fr);
  gap: 20px;
  align-items: start;
}

.back-button,
.detail-badge,
.free-write-row button {
  min-height: 39px;
  border: 1px solid #074457;
  border-radius: 8px;
  padding: 0 18px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 900;
}

.back-button {
  background: #ffffff;
  color: var(--accent);
}

.detail-badge {
  display: inline-grid;
  place-items: center;
  text-transform: uppercase;
}

.detail-head .eyebrow {
  margin-bottom: 6px;
}

.detail-head h2 {
  margin: 0;
  font-size: clamp(1.6rem, 2.7vw, 2.5rem);
  line-height: 1;
}

.learning-note {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1rem, 1.6vw, 1.28rem);
  line-height: 1.24;
}

.free-write {
  display: grid;
  gap: 8px;
  margin-top: clamp(14px, 2vw, 24px);
}

.free-write label,
.preset-section h3 {
  color: var(--ink);
  font-size: clamp(1rem, 1.45vw, 1.2rem);
  font-weight: 500;
}

.free-write-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.free-write-row input {
  width: 100%;
  min-height: 48px;
  border: 2px solid #0b4357;
  border-radius: 8px;
  padding: 0 16px;
  color: var(--ink);
  background: #edf8fb;
  font: inherit;
  font-size: 1.05rem;
}

.free-write-row input:focus {
  outline: 4px solid rgba(243, 190, 53, 0.5);
  outline-offset: 2px;
}

.preset-section {
  display: grid;
  gap: 12px;
  margin-top: clamp(62px, 12vh, 110px);
}

.preset-section h3 {
  margin: 0;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px 36px;
}

.phrase-button {
  min-height: 66px;
  border: 2px solid #0b4357;
  border-radius: 8px;
  padding: 10px 14px;
  color: #ffffff;
  background: var(--accent);
  font-size: clamp(0.88rem, 1.25vw, 1.03rem);
  font-weight: 850;
  line-height: 1.15;
  text-align: center;
  touch-action: manipulation;
}

.phrase-button[data-used="true"] {
  box-shadow: inset 0 -4px 0 rgba(255, 255, 255, 0.24);
}

.phrase-button:focus-visible,
.free-write-row button:focus-visible,
.back-button:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side-nav {
    display: none;
  }

  .workspace {
    padding: 14px;
  }

  .topbar {
    margin: -14px -14px 0;
    padding: 7px 14px;
  }

  .category-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .report-heading {
    flex-direction: column;
  }

  .report-heading p:last-child {
    text-align: left;
  }

  .report-grid {
    grid-template-columns: 1fr;
  }

  .timeline-month-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-head {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .learning-note {
    grid-column: 1 / -1;
  }

  .preset-section {
    margin-top: 42px;
  }

  .preset-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-switch {
    width: 100%;
  }

  .mode-switch button {
    flex: 1;
  }

  .category-grid {
    grid-template-columns: 1fr;
  }

  .category-card {
    min-height: 104px;
  }

  .bar-row {
    grid-template-columns: 1fr auto;
  }

  .bar-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .detail-head {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .back-button,
  .detail-badge {
    justify-self: start;
  }

  .free-write-row {
    grid-template-columns: 1fr;
  }

  .preset-grid {
    grid-template-columns: 1fr;
  }

  .timeline-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .month-select {
    width: 100%;
  }

  .timeline-month-grid {
    grid-template-columns: 1fr;
  }
}
