:root {
  color-scheme: light;
  --bg: #edf4f1;
  --surface: #ffffff;
  --surface-alt: #f7fbf9;
  --text: #12201d;
  --text-muted: #61736e;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #dff3ee;
  --line: #d8e5e1;
  --warning: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --shadow: 0 18px 45px rgba(15, 94, 89, 0.12);
  --radius-sm: 6px;
  --radius-md: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(15, 118, 110, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: 34px 34px;
  color: var(--text);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #142420;
  color: #f6fbf9;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: #12a394;
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
}

.brand-subtitle {
  color: #a5c7bf;
  font-size: 12px;
  margin-top: 2px;
}

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

.nav-tab {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: #d9ebe7;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  text-align: left;
}

.nav-tab:hover,
.nav-tab.active {
  background: #203a35;
  border-color: #2f5e55;
  color: #ffffff;
}

.icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
}

svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-status {
  margin-top: auto;
  border: 1px solid #2f5e55;
  border-radius: var(--radius-md);
  padding: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.status-label {
  color: #a5c7bf;
  font-size: 12px;
  margin-bottom: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: #33433f;
  color: #ffffff;
  font-size: 12px;
}

.status-pill.on {
  background: #0f766e;
}

.content {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 22px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

.topbar-actions,
.button-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.icon-button {
  border-radius: var(--radius-sm);
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
}

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

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

.ghost-button:hover,
.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.icon-button {
  width: 40px;
  display: grid;
  place-items: center;
  padding: 0;
}

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

.grid {
  display: grid;
  gap: 16px;
}

.kpi-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.kpi,
.panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(216, 229, 225, 0.95);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.kpi {
  padding: 18px;
}

.kpi-label,
.kpi-meta {
  color: var(--text-muted);
  font-size: 13px;
}

.kpi-value {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 8px 0 12px;
  font-size: 31px;
  font-weight: 800;
  line-height: 1;
}

.kpi-value small {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

.progress {
  height: 9px;
  background: #e7efec;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #0f766e, #22c55e);
  border-radius: inherit;
  transition: width 0.25s ease;
}

.kpi.alert .progress span {
  background: linear-gradient(90deg, #f97316, #dc2626);
}

.dashboard-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  margin-bottom: 16px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

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

.panel-header p {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 5px;
}

.chip {
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 26px;
  padding: 3px 10px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 800;
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfefd;
}

label {
  display: grid;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfefd;
  color: var(--text);
  min-height: 38px;
  padding: 8px 10px;
  outline: none;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 16px,
    calc(100% - 12px) 16px;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

textarea {
  resize: vertical;
  min-height: 86px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

input[readonly] {
  background: #edf7f4;
  color: var(--accent-strong);
  font-weight: 800;
}

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

.quick-form .primary-button {
  grid-column: 1 / -1;
}

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

.detail-form .wide {
  grid-column: span 2;
}

.detail-form .full {
  grid-column: 1 / -1;
}

.detail-form .primary-button {
  grid-column: 1 / -1;
  justify-self: start;
}

.quick-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.meal-builder {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 12px;
}

.meal-builder-head,
.photo-estimator-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.meal-builder h3,
.photo-estimator h3 {
  margin: 0;
  font-size: 15px;
}

.meal-builder p,
.photo-estimator p,
.form-note {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 3px;
}

.photo-estimator {
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #f7fbf9, #edf7f4);
  padding: 12px;
}

.photo-estimator-grid {
  display: grid;
  grid-template-columns: 1.1fr repeat(3, minmax(120px, 0.55fr));
  gap: 10px;
  align-items: end;
}

.photo-upload input {
  padding: 9px;
}

.photo-preview {
  margin-top: 10px;
}

.photo-preview img {
  display: block;
  width: min(360px, 100%);
  max-height: 220px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.estimate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.estimate-result-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.estimate-result-panel[hidden] {
  display: none;
}

.estimate-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  padding: 10px;
}

.estimate-summary strong,
.estimate-summary span {
  display: block;
}

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

.estimate-dish-list {
  display: grid;
  gap: 8px;
}

.estimate-dish-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) repeat(6, minmax(72px, 0.5fr));
  gap: 8px;
  align-items: center;
}

.estimate-dish-row input {
  min-height: 36px;
  font-size: 12px;
}

.meal-builder-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) repeat(4, minmax(88px, 0.6fr)) auto;
  gap: 8px;
  align-items: center;
}

.custom-food-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.custom-food-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  padding: 9px 10px;
}

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

.custom-food-item span {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 3px;
}

.empty-state.compact {
  min-height: 40px;
  padding: 9px 10px;
}

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

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

.reminder-form .button-row {
  grid-column: 1 / -1;
}

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

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

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

.status-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 14px;
}

.status-item span {
  color: var(--text-muted);
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
}

.status-item strong {
  font-size: 22px;
}

.todo-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

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

.todo-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 10px;
}

.todo-item input {
  width: 18px;
  height: 18px;
  min-height: auto;
}

.todo-text {
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.todo-meta {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 3px;
}

.todo-item.done .todo-text {
  color: var(--text-muted);
  text-decoration: line-through;
}

.daily-task-preview {
  display: grid;
  gap: 10px;
}

.daily-task-preview h3 {
  font-size: 14px;
  margin: 2px 0 0;
}

.preview-box,
.empty-state {
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text-muted);
  padding: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 940px;
  background: #ffffff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}

th {
  background: #142420;
  color: #ffffff;
  position: sticky;
  top: 0;
}

td {
  color: var(--text);
}

.mini-button {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text);
  min-height: 30px;
  padding: 0 10px;
}

.mini-button:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  min-width: 220px;
  max-width: min(520px, calc(100vw - 32px));
  background: #142420;
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .nav-tabs {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .nav-tab {
    justify-content: center;
    padding: 0 8px;
  }

  .sidebar-status {
    display: none;
  }

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

@media (max-width: 760px) {
  body {
    background: var(--bg);
  }

  .app-shell {
    display: block;
    min-height: 100vh;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 15;
    height: auto;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid #2f5e55;
    box-shadow: 0 -16px 36px rgba(10, 24, 21, 0.18);
  }

  .brand,
  .sidebar-status {
    display: none;
  }

  .content {
    padding: 14px 12px 92px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 24px;
  }

  .nav-tabs {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
  }

  .nav-tab {
    min-height: 58px;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 4px 2px;
    font-size: 11px;
    line-height: 1.1;
  }

  .nav-tab .icon {
    width: 22px;
    height: 22px;
  }

  .topbar {
    margin-bottom: 14px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 44px 1fr 1fr;
  }

  .kpi-grid,
  .dashboard-grid,
  .quick-form,
  .detail-form,
  .quick-add-row,
  .photo-estimator-grid,
  .meal-builder-grid,
  .todo-form,
  .settings-form,
  .reminder-form,
  .status-grid {
    grid-template-columns: 1fr;
  }

  .detail-form .wide,
  .detail-form .full {
    grid-column: auto;
  }

  .panel,
  .kpi {
    padding: 14px;
    box-shadow: 0 12px 28px rgba(15, 94, 89, 0.08);
  }

  input,
  select,
  textarea,
  .primary-button,
  .ghost-button,
  .icon-button {
    min-height: 44px;
  }

  .estimate-summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .estimate-dish-row {
    grid-template-columns: 1fr 1fr;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #ffffff;
    padding: 8px;
  }

  .estimate-dish-row input:first-child {
    grid-column: 1 / -1;
  }

  .toast {
    bottom: calc(84px + env(safe-area-inset-bottom));
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .ghost-button,
  .topbar-actions .file-button {
    flex: 1;
    justify-content: center;
  }
}
