:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #d7dee8;
  --accent: #4f9d09;
  --accent-strong: #3f7f07;
  --warn: #b45309;
  --danger: #b91c1c;
  --blue: #2563eb;
  --shadow: 0 18px 50px rgba(31, 41, 51, 0.07);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  padding: 28px 20px;
  background: #eef2f6;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 30px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
}

#sleepTitleDate span {
  font-weight: 400;
}

.brand p,
.form-head p,
.panel-head p,
.list-panel p,
.settings-panel p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 1px 0 rgba(31, 41, 51, 0.04);
}

.workspace {
  padding: 28px;
  max-width: 1240px;
  width: 100%;
}

.topbar,
.panel-head,
.settings-actions,
.topbar-actions,
.period-toolbar,
.period-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

h2 {
  font-size: 30px;
}

.primary-button,
.ghost-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 42px;
}

.primary-button {
  padding: 0 16px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  padding: 0 14px;
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  background: var(--panel);
  border-color: var(--line);
}

.full {
  width: 100%;
}

.voice-panel,
.settings-panel,
.entry-form,
.list-panel,
.metric-card,
.health-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.voice-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
  padding: 18px;
}

.voice-panel[hidden],
.settings-panel[hidden],
.health-page[hidden],
.content-grid[hidden] {
  display: none;
}

.voice-panel p {
  color: var(--muted);
  margin-top: 4px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 22px;
}

.metric-card {
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  font-size: 28px;
  margin-top: 8px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.health-page {
  margin-top: 18px;
}

.period-toolbar {
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 210px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

.segment {
  min-height: 42px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segment.active {
  background: var(--ink);
  color: white;
}

.period-nav {
  justify-content: flex-end;
}

.period-nav strong {
  min-width: 190px;
  text-align: center;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.time-choice {
  appearance: none;
  background-image: none;
  cursor: pointer;
  padding-left: 8px;
  padding-right: 8px;
  text-align: left;
  font-weight: 700;
}

.month-choice {
  width: 104px;
}

.year-choice {
  width: 58px;
}

.sleep-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.readonly-field {
  background: #f0fdfa;
  color: var(--accent-strong);
  font-weight: 700;
}

.sleep-period-controls {
  display: flex;
  align-items: end;
  gap: 10px;
}

.sleep-period-controls label {
  width: auto;
}

.sleep-month-table {
  display: grid;
  margin-top: 2px;
}

.sleep-table-head,
.sleep-table-row {
  display: grid;
  grid-template-columns: 0.8fr repeat(4, minmax(0, 1fr));
  gap: 0;
}

.sleep-table-head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  padding: 0 0 5px;
}

.sleep-table-row {
  min-height: 24px;
  border: 0;
  border-top: 1px solid #e5e7eb;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  padding: 0;
  text-align: left;
}

.sleep-table-row.selected {
  background: var(--accent);
  color: white;
}

.sleep-table-row.weekend .sleep-cell {
  background: #fff1f2;
}

.sleep-table-row.selected .sleep-cell {
  background: var(--accent);
  color: white;
}

.sleep-cell {
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 4px 6px;
  text-align: left;
  border-left: 1px solid #e5e7eb;
}

.sleep-cell:first-child {
  border-left: 0;
}

.sleep-duration {
  font-weight: 700;
}

.entry-form,
.settings-panel,
.health-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.three-cols {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 157, 9, 0.14);
}

.list-panel {
  min-height: 520px;
  padding: 18px;
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.entry-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.health-list {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.health-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfdff;
}

.health-item strong,
.health-item span {
  display: block;
}

.health-item strong {
  font-size: 13px;
}

.health-item span,
.health-empty {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.health-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
}

.entry-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: white;
}

.entry-title {
  font-weight: 700;
}

.entry-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.tag {
  border-radius: 999px;
  padding: 3px 8px;
  background: #eef2ff;
  color: #3730a3;
}

.entry-row[data-type="expense"] .tag {
  background: #fff7ed;
  color: var(--warn);
}

.entry-row[data-type="health"] .tag {
  background: #ecfeff;
  color: #0e7490;
}

.entry-row[data-type="food"] .tag {
  background: #f0fdf4;
  color: #15803d;
}

.delete-button,
.health-delete-button {
  border: 0;
  border-radius: 8px;
  min-width: 36px;
  min-height: 36px;
  background: #fee2e2;
  color: var(--danger);
}

.health-delete-button {
  min-width: 32px;
  min-height: 32px;
}

.settings-panel {
  margin-top: 18px;
}

dialog {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(31, 41, 51, 0.38);
}

.dialog-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 16px;
  }

  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .workspace {
    padding: 18px 14px 28px;
  }

  .metrics-grid,
  .content-grid,
  .health-grid {
    grid-template-columns: 1fr;
  }

  .three-cols,
  .sleep-fields {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 520px) {
  .brand p {
    display: none;
  }

  .topbar,
  .panel-head,
  .voice-panel,
  .period-toolbar,
  .period-nav {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions,
  .panel-actions,
  .settings-actions,
  .period-nav,
  .segmented-control {
    width: 100%;
  }

  .topbar-actions .primary-button,
  .panel-actions .ghost-button,
  .settings-actions button,
  .period-nav button {
    flex: 1;
  }

  .period-nav {
    flex-direction: row;
    align-items: center;
  }

  .period-nav strong {
    min-width: 0;
    flex: 1;
  }

  .two-cols {
    grid-template-columns: 1fr;
  }

  h2 {
    font-size: 25px;
  }
}
