:root {
  --bg: #f7f5ef;
  --panel: #fffdf8;
  --panel-strong: #ffffff;
  --text: #202124;
  --muted: #6d6a63;
  --line: #ded8cc;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #d9f0eb;
  --warning: #b45309;
  --danger: #b42318;
  --done: #16803f;
  --cancelled: #7b7b7b;
  --shadow: 0 16px 36px rgba(45, 38, 28, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), transparent 280px),
    var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

body.is-loading {
  cursor: progress;
}

body.is-loading button,
body.is-loading input,
body.is-loading select,
body.is-loading textarea,
body.is-loading label {
  pointer-events: none;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.topbar,
.toolbar,
.section-title,
.dialog-header,
.dialog-actions,
.date-nav,
.toggle-row {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
  max-width: 1280px;
  margin: 0 auto 20px;
}

.topbar h1,
.toolbar h2,
.dialog-header h2,
.section-title h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(24px, 4vw, 38px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-actions,
.quick-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.top-actions form {
  margin: 0;
}

.api-status {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 253, 248, 0.82);
  color: var(--muted);
  font-size: 13px;
  font-weight: 820;
}

.api-status[data-status="ready"] {
  border-color: rgba(22, 128, 63, 0.24);
  background: #f3fbf6;
  color: var(--done);
}

.api-status[data-status="error"] {
  border-color: rgba(180, 35, 24, 0.26);
  background: #fff1ef;
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1280px;
  margin: 0 auto;
}

.side-panel,
.main-panel {
  min-width: 0;
}

.side-panel {
  display: grid;
  gap: 14px;
  align-content: start;
}

.date-card,
.summary-card,
.main-panel {
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.date-card,
.summary-card {
  padding: 14px;
}

.main-panel {
  padding: 18px;
}

.date-nav {
  gap: 8px;
  margin-bottom: 10px;
}

.date-nav input,
.section-title input,
.field-label input,
.field-label select,
.field-label textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 9px 10px;
}

.field-label textarea {
  resize: vertical;
}

.section-title {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-title h2 {
  font-size: 16px;
}

.icon-button,
.primary-button,
.secondary-button,
.danger-button,
.quick-add button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
  background: var(--panel-strong);
  color: var(--text);
  font-weight: 750;
}

.icon-button {
  min-width: 42px;
}

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

.secondary-button {
  background: #f1eee7;
}

.danger-button {
  border-color: rgba(180, 35, 24, 0.24);
  background: #fff1ef;
  color: var(--danger);
}

.full-width {
  width: 100%;
}

.import-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.import-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.global-loading {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(32, 33, 36, 0.2);
  backdrop-filter: blur(2px);
}

.global-loading[hidden] {
  display: none;
}

.loading-panel {
  display: grid;
  justify-items: center;
  gap: 12px;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 22px 26px;
  color: var(--text);
}

.loading-spinner {
  width: 34px;
  height: 34px;
  border: 4px solid #d7efe9;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.progress-line {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 750;
}

.progress-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #ebe6dc;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.status-badge,
.type-pill,
.money-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge {
  background: #efeae0;
  color: var(--muted);
}

.status-badge.done {
  background: var(--accent-soft);
  color: var(--done);
}

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

.money-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
}

.money-grid dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.money-grid dd {
  margin: 0;
  font-size: 17px;
  font-weight: 850;
}

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

.field-label.compact {
  margin-top: 8px;
}

.notice {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--warning);
  font-size: 13px;
  font-weight: 760;
}

.type-breakdown {
  display: grid;
  gap: 8px;
}

.type-row {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.type-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #ebe6dc;
}

.type-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.toolbar {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.quick-add {
  margin-bottom: 16px;
}

.quick-add button {
  min-height: 34px;
  padding-inline: 12px;
}

.timeline {
  display: grid;
  gap: 10px;
}

.empty-state {
  padding: 46px 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 18px;
}

.item-card {
  display: grid;
  grid-template-columns: 78px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--item-color, var(--accent));
  border-radius: 8px;
  background: var(--panel-strong);
}

.item-card.done {
  background: #f3fbf6;
  border-color: rgba(22, 128, 63, 0.22);
  border-left-color: var(--done);
}

.item-card.cancelled {
  background: #f0f0ef;
  color: var(--cancelled);
}

.item-time {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.item-title-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.item-title-row h3 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.item-description {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
  white-space: pre-wrap;
}

.item-actions {
  display: flex;
  gap: 6px;
}

.complete-button {
  min-width: 42px;
  min-height: 38px;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 900;
}

.edit-button {
  min-width: 42px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f4ec;
  color: var(--text);
  font-weight: 850;
}

.type-pill {
  background: color-mix(in srgb, var(--item-color, var(--accent)) 18%, white);
  color: var(--item-color, var(--accent));
}

.money-pill {
  background: #f2ede2;
  color: #4d4232;
}

.item-dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: min(880px, calc(100vh - 24px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.item-dialog::backdrop {
  background: rgba(32, 33, 36, 0.32);
}

.item-dialog form {
  padding: 18px;
}

.dialog-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

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

.wide {
  grid-column: 1 / -1;
}

.money-fieldset {
  margin: 16px 0 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toggle-row {
  gap: 8px;
  margin-bottom: 12px;
  color: var(--text);
  font-weight: 850;
}

.toggle-row input {
  width: 18px;
  height: 18px;
}

.money-fields[hidden] {
  display: none;
}

.dialog-actions {
  gap: 8px;
  margin-top: 16px;
}

.action-spacer {
  flex: 1;
}

@media (max-width: 860px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .workspace {
    display: grid;
    grid-template-columns: 1fr;
  }

  .workspace {
    gap: 14px;
  }

  .side-panel {
    order: 2;
  }

  .main-panel {
    order: 1;
    padding: 14px;
  }

  .toolbar {
    align-items: start;
  }

  .item-card {
    grid-template-columns: 1fr;
  }

  .item-actions {
    width: 100%;
  }

  .item-actions button {
    flex: 1;
  }

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

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

@media (max-width: 520px) {
  .top-actions,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .top-actions .icon-button,
  .toolbar .primary-button {
    width: 100%;
  }

  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .action-spacer {
    display: none;
  }
}

.login-page {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.12), transparent 360px),
    var(--bg);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.login-copy {
  margin: 10px 0 22px;
  color: var(--muted);
  line-height: 1.6;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-error {
  margin: 0;
  color: var(--danger);
  font-weight: 800;
}
