:root {
  color-scheme: dark;
  --bg: #0b1220;
  --panel: #111827;
  --panel-2: #162033;
  --line: #27364f;
  --text: #edf4ff;
  --muted: #a9b8d1;
  --ok: #86efac;
  --warn: #fbbf24;
  --bad: #fca5a5;
  --blue: #8ab4f8;
  --accent: #3d69c5;
  --accent-2: #2f64c8;
  --success-bg: #153e33;
  --success-text: #d8fff0;
  --danger-bg: #4a1f28;
  --radius-lg: 12px;
  --radius-md: 10px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: contain;
}

body {
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  max-width: 1600px;
  margin: 0 auto;
  padding: 12px 14px 18px;
}

.pull-sync-indicator {
  position: fixed;
  top: 8px;
  left: 50%;
  z-index: 120;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #1b2437;
  color: var(--text);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.32);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -56px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.pull-sync-indicator.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.pull-sync-indicator.is-ready {
  border-color: #4f78bd;
}

.page-header h1,
.section-title {
  margin: 0;
}

.page-header h1 {
  font-size: 2.05rem;
  line-height: 1.1;
}

.title-row,
.status-row,
.sidebar-actions,
.debug-panel,
.day-row,
.panel-header {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.title-row {
  justify-content: space-between;
  margin-bottom: 14px;
}

.status-row {
  justify-content: flex-end;
}

.control-bar {
  margin-bottom: 10px;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(190px, 0.9fr) minmax(120px, 0.45fr);
  gap: 10px;
}

.week-switcher {
  min-height: 52px;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: stretch;
  background: #1b2437;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.icon-button {
  min-width: 48px;
  background: #222b3f;
  color: var(--text);
  border: 0;
  font-size: 1.8rem;
  line-height: 1;
}

.week-switcher-label {
  min-width: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 6px 10px;
  text-align: center;
}

.week-switcher-label strong,
.week-switcher-label span {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.week-switcher-label span {
  color: var(--muted);
  font-size: 0.88rem;
}

.field {
  display: grid;
  gap: 6px;
}

.field input,
.field select,
.pill,
.debug-chip,
.file-label,
.ghost,
.secondary,
.primary,
.icon-button {
  border-radius: var(--radius-md);
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  color: var(--text);
  background: #1b2437;
  border: 1px solid var(--line);
}

.field input.is-editable-time {
  color: #facc15;
  -webkit-text-fill-color: #facc15;
  caret-color: #facc15;
  font-weight: 800;
}

.field input:disabled {
  opacity: 1;
  color: var(--text);
  -webkit-text-fill-color: var(--text);
}

.field input:focus,
.field select:focus {
  outline: 1px solid #4f78bd;
  border-color: #4f78bd;
}

.time-edit-control {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: center;
}

.time-reset-button {
  min-width: 42px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(138, 180, 248, 0.28);
  border-radius: var(--radius-md);
  background: rgba(138, 180, 248, 0.08);
  color: var(--blue);
  padding: 0;
}

.time-reset-button:focus {
  outline: 1px solid var(--blue);
}

.time-reset-icon {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.primary,
.secondary,
.ghost,
.file-label {
  min-height: 44px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary {
  background: var(--accent);
  color: white;
  border: 1px solid #4f78bd;
}

.secondary,
.file-label {
  background: #1b2437;
  color: var(--text);
  border: 1px solid var(--line);
}

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.save-button {
  width: 100%;
}

.pill,
.debug-chip {
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #1b2437;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
}

.subtle-pill {
  color: var(--text);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
}

.main-column {
  min-width: 0;
}

.panel,
.week-strip,
.summary-strip,
.day-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.panel {
  padding: 16px;
}

.week-strip {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 12px 14px;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.week-strip-title {
  font-size: 1.05rem;
  font-weight: 800;
}

.week-strip-range {
  color: var(--muted);
}

.week-strip-status {
  color: var(--ok);
  font-weight: 800;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  padding: 10px 14px;
  margin-top: 10px;
}

.summary-card {
  min-width: 0;
  padding-right: 10px;
}

.summary-label,
.summary-detail,
.panel-subtitle,
.retention-note,
.section-kicker,
.compact-label {
  color: var(--muted);
}

.summary-label {
  display: block;
  font-size: 0.78rem;
  line-height: 1.15;
}

.summary-value {
  display: block;
  font-size: 1rem;
  font-weight: 800;
  margin-top: 2px;
}

.summary-detail {
  display: block;
  margin-top: 2px;
  font-size: 0.92rem;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 14px 0 10px;
}

.section-title {
  font-size: 2rem;
}

.days-list {
  display: grid;
  gap: 14px;
}

.day-card {
  margin-top: 6px;
  padding: 12px;
  background: rgba(22, 32, 51, 0.68);
  border: 1px solid rgba(39, 54, 79, 0.9);
  border-radius: var(--radius-lg);
}

.day-row {
  display: grid;
  grid-template-columns: 240px minmax(220px, 1.3fr) 220px 220px 180px;
  gap: 14px;
  align-items: center;
}

.day-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1rem;
  font-weight: 600;
}

.day-toggle input {
  width: 18px;
  height: 18px;
  accent-color: #ff5c5c;
}

.day-mode-field,
.day-time-field {
  gap: 4px;
}

.compact-label {
  font-size: 0.9rem;
  font-weight: 700;
}

.day-stats-inline {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  white-space: nowrap;
}

.day-stat-text {
  color: var(--muted);
  font-size: 0.95rem;
}

.day-stat-text strong {
  color: var(--text);
  font-size: 1.05rem;
}

.day-delta.is-positive {
  color: var(--ok);
}

.day-delta.is-negative {
  color: var(--bad);
}

.day-delta.is-neutral,
.summary-value.is-neutral {
  color: var(--blue);
}

.summary-value.is-positive {
  color: var(--ok);
}

.summary-value.is-negative {
  color: var(--bad);
}

.day-fixed-note {
  margin: 6px 0 0 252px;
  color: var(--muted);
  font-size: 0.88rem;
}

.feedback {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 8, 18, 0.72);
}

.cloud-panel {
  width: min(440px, 100%);
  max-height: min(680px, calc(100vh - 36px));
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #101827;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.cloud-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.cloud-header h3,
.cloud-header p,
.cloud-path,
.cloud-feedback {
  margin: 0;
}

.cloud-header p,
.cloud-path,
.cloud-feedback {
  color: var(--muted);
}

.cloud-actions {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.cloud-path {
  margin-top: 12px;
  font-size: 0.88rem;
}

.icon-close-button {
  min-height: 34px;
  min-width: 34px;
  padding: 0;
}

.cloud-feedback {
  min-height: 20px;
  margin-top: 10px;
}

.sync-action {
  gap: 8px;
}

.button-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(237, 244, 255, 0.24);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.sidebar-panel {
  position: sticky;
  top: 12px;
}

.panel-header {
  align-items: flex-start;
}

.panel-header h2 {
  margin: 0;
}

.panel-subtitle,
.retention-note {
  margin: 8px 0 0;
}

.records-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.record-button {
  width: 100%;
  padding: 14px;
  text-align: left;
  background: #1b2437;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text);
}

.record-button.is-active {
  border-color: #4f78bd;
}

.record-title,
.record-meta {
  display: block;
}

.record-title {
  font-weight: 700;
}

.record-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--muted);
}

.debug-panel {
  margin-top: 16px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#import-input {
  display: none;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1280px) {
  .day-row {
    grid-template-columns: 210px minmax(180px, 1fr) 170px 170px 155px;
  }
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar-panel {
    position: static;
  }

  .summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .day-row {
    grid-template-columns: 1fr;
  }

  .day-fixed-note {
    margin-left: 0;
  }

  .day-stats-inline {
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 10px;
  }

  .control-grid {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .title-row {
    align-items: flex-start;
    flex-direction: column;
  }
}
