:root {
  color-scheme: dark;
  --bg: #080a12;
  --surface: #111522;
  --surface-2: #171b2b;
  --surface-3: #20263a;
  --text: #f3f6ff;
  --muted: #9aa5bd;
  --faint: #68728a;
  --line: rgba(154, 165, 189, 0.18);
  --line-strong: rgba(154, 165, 189, 0.34);
  --primary: #8b5cf6;
  --primary-2: #6d5dfc;
  --blue: #3b82f6;
  --green: #21c48d;
  --yellow: #f4b942;
  --red: #ef4e66;
  --purple-soft: rgba(139, 92, 246, 0.16);
  --blue-soft: rgba(59, 130, 246, 0.16);
  --green-soft: rgba(33, 196, 141, 0.14);
  --yellow-soft: rgba(244, 185, 66, 0.16);
  --red-soft: rgba(239, 78, 102, 0.16);
  --radius-lg: 22px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --nav-height: 76px;
  --hour-height: 70px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  background: linear-gradient(180deg, #0b1020 0%, var(--bg) 34%);
  color: var(--text);
  font: 15px/1.45 Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: white;
  padding: 0 14px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

button:active {
  transform: scale(0.98);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.54;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #0d111d;
  color: var(--text);
  padding: 12px;
}

textarea {
  resize: vertical;
}

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

h1 {
  font-size: 28px;
  font-weight: 750;
}

h2 {
  font-size: 20px;
  font-weight: 720;
}

h3 {
  font-size: 16px;
  font-weight: 700;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 20;
  transform: translateY(-160%);
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: white;
  padding: 10px 12px;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  width: min(980px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(var(--nav-height) + 28px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.ghost-button,
.secondary-button,
.icon-button,
.date-step,
.date-pill,
.nav-item,
.more-tile,
.segmented-control button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.ghost-button {
  min-height: 40px;
}

.icon-button,
.date-step {
  width: 44px;
  padding: 0;
  font-size: 24px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.day-switcher {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 8px;
  margin-bottom: 10px;
}

.date-pill {
  justify-content: center;
  width: 100%;
  font-weight: 720;
}

.scale-control,
.segmented-control {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 10px;
}

.scale-control button,
.segmented-control button {
  flex: 0 0 auto;
  min-height: 38px;
  border-radius: 999px;
  color: var(--muted);
}

.scale-control button.active,
.segmented-control button.active {
  border-color: transparent;
  background: var(--purple-soft);
  color: #d8ccff;
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 2px 0 12px;
}

.summary-pill {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  padding: 10px;
}

.summary-pill strong {
  display: block;
  font-size: 18px;
}

.summary-pill span {
  color: var(--muted);
  font-size: 12px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0;
}

.section-head p {
  color: var(--muted);
  margin-top: 2px;
}

.section-head.compact {
  margin-top: 18px;
}

.card-list {
  display: grid;
  gap: 10px;
}

.entity-card,
.debug-card,
.quick-note,
.timeline {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(17, 21, 34, 0.88);
}

.entity-card {
  padding: 14px;
  text-align: left;
}

.entity-card[role="button"] {
  cursor: pointer;
}

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

.entity-card h3 {
  margin-top: 6px;
}

.entity-card p {
  color: var(--muted);
  margin-top: 6px;
  white-space: pre-wrap;
}

.entity-top,
.entity-footer,
.quick-note-actions,
.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.entity-top,
.entity-footer {
  justify-content: space-between;
}

.entity-kind,
.entity-meta,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.entity-kind,
.badge.info {
  background: var(--purple-soft);
  color: #d7ccff;
}

.entity-meta {
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

.badge.ok {
  background: var(--green-soft);
  color: var(--green);
}

.badge.warn {
  background: var(--yellow-soft);
  color: var(--yellow);
}

.badge.bad {
  background: var(--red-soft);
  color: var(--red);
}

.entity-footer {
  margin-top: 12px;
  justify-content: flex-start;
}

.timeline {
  position: relative;
  min-height: calc(18 * var(--hour-height) + 20px);
  overflow: hidden;
  padding: 10px 8px 18px 58px;
}

.timeline.empty {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 18px;
}

.hour-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(154, 165, 189, 0.12);
}

.hour-label {
  position: absolute;
  left: 12px;
  transform: translateY(-50%);
  color: var(--faint);
  font-size: 12px;
}

.time-block {
  position: absolute;
  left: 58px;
  right: 8px;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.28), rgba(109, 93, 252, 0.12));
  color: var(--text);
  padding: 9px 11px;
  text-align: left;
  overflow: hidden;
}

.time-block.deadline {
  border-left-color: var(--red);
  background: linear-gradient(135deg, rgba(239, 78, 102, 0.26), rgba(239, 78, 102, 0.1));
}

.time-block.rest {
  border-left-color: var(--green);
  background: linear-gradient(135deg, rgba(33, 196, 141, 0.22), rgba(33, 196, 141, 0.08));
}

.time-block.event {
  border-left-color: var(--blue);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.24), rgba(59, 130, 246, 0.08));
}

.time-block span {
  display: block;
  color: rgba(243, 246, 255, 0.76);
  font-size: 12px;
  font-weight: 700;
}

.time-block strong {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.now-line {
  position: absolute;
  left: 48px;
  right: 8px;
  z-index: 3;
  height: 2px;
  background: var(--red);
}

.now-line::before {
  content: "";
  position: absolute;
  left: -5px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 99px;
  background: var(--red);
}

.quick-note {
  padding: 12px;
  margin-bottom: 12px;
}

.quick-note textarea {
  min-height: 92px;
  border-color: transparent;
  background: rgba(255, 255, 255, 0.05);
}

.quick-note-actions {
  justify-content: space-between;
  margin-top: 10px;
}

.more-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.more-tile {
  display: grid;
  align-content: start;
  min-height: 86px;
  text-align: left;
  padding: 12px;
}

.more-tile strong,
.more-tile span {
  display: block;
}

.more-tile span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.more-tile.active {
  border-color: transparent;
  background: var(--purple-soft);
}

.more-pane {
  display: none;
}

.more-pane.active {
  display: block;
}

.chat-log {
  display: grid;
  gap: 10px;
  min-height: 260px;
  margin-bottom: 12px;
}

.message {
  max-width: 88%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 12px;
  white-space: pre-wrap;
}

.message.user {
  justify-self: end;
  border-color: transparent;
  background: var(--primary);
}

.chat-form,
.sheet-form {
  display: grid;
  gap: 10px;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  color: var(--text);
  font-weight: 500;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.check-row input {
  width: auto;
  min-height: auto;
}

.debug-card {
  display: grid;
  gap: 6px;
  padding: 14px;
  margin-bottom: 10px;
}

.debug-card span {
  color: var(--muted);
}

.debug-card strong {
  overflow-wrap: anywhere;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  min-height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(8, 10, 18, 0.94);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  backdrop-filter: blur(18px);
}

.nav-item {
  min-width: 0;
  min-height: 52px;
  border-radius: var(--radius-md);
  padding: 0 4px;
  color: var(--muted);
}

.nav-item.active {
  border-color: transparent;
  background: var(--purple-soft);
  color: var(--text);
}

.nav-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  font-weight: 750;
}

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--nav-height) + 18px + env(safe-area-inset-bottom));
  z-index: 11;
  width: 58px;
  height: 58px;
  min-height: 58px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 16px 40px rgba(109, 93, 252, 0.35);
  font-size: 30px;
  line-height: 1;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.58);
}

.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 31;
  max-height: min(88vh, 760px);
  border: 1px solid var(--line-strong);
  border-bottom: 0;
  border-radius: 28px 28px 0 0;
  background: #101423;
  padding: 8px 14px calc(16px + env(safe-area-inset-bottom));
  overflow: auto;
}

.sheet-handle {
  width: 42px;
  height: 5px;
  border-radius: 999px;
  background: rgba(243, 246, 255, 0.24);
  margin: 2px auto 12px;
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sheet-body {
  display: grid;
  gap: 10px;
}

.sheet-actions,
.create-menu {
  display: grid;
  gap: 10px;
}

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

.create-option {
  display: grid;
  gap: 3px;
  align-content: center;
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 10px 14px;
  text-align: left;
}

.create-option strong,
.create-option span {
  overflow-wrap: anywhere;
}

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

.danger {
  background: var(--red);
  color: white;
}

.empty,
.error {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.error {
  color: var(--red);
}

@media (min-width: 820px) {
  .app-shell {
    padding-left: 22px;
    padding-right: 22px;
  }

  .screen.active {
    max-width: 760px;
  }

  #calendar.screen.active,
  #today.screen.active {
    max-width: 920px;
  }

  .bottom-sheet {
    left: 50%;
    right: auto;
    width: min(680px, calc(100% - 28px));
    transform: translateX(-50%);
    border-radius: 28px;
    bottom: 18px;
    border-bottom: 1px solid var(--line-strong);
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  h1 {
    font-size: 24px;
  }

  .summary-row,
  .more-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
