:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #eef4f3;
  --border: #dce6e4;
  --text: #0f172a;
  --text-sub: #475569;
  --text-muted: #64748b;
  --primary: #0f766e;
  --primary-hover: #0d625b;
  --primary-soft: #ccfbf1;
  --primary-soft-text: #115e59;
  --good: #059669;
  --good-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --alert: #dc2626;
  --alert-bg: #fee2e2;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b1313;
    --surface: #131f1f;
    --surface-soft: #1a2a29;
    --border: #253a38;
    --text: #f1f5f9;
    --text-sub: #cbd5e1;
    --text-muted: #94a3b8;
    --primary: #14b8a6;
    --primary-hover: #2dd4bf;
    --primary-soft: #134e4a;
    --primary-soft-text: #99f6e4;
    --good: #34d399;
    --good-bg: #064e3b;
    --warn: #fbbf24;
    --warn-bg: #451a03;
    --alert: #f87171;
    --alert-bg: #450a0a;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme='dark'] {
  --bg: #0b1313;
  --surface: #131f1f;
  --surface-soft: #1a2a29;
  --border: #253a38;
  --text: #f1f5f9;
  --text-sub: #cbd5e1;
  --text-muted: #94a3b8;
  --primary: #14b8a6;
  --primary-hover: #2dd4bf;
  --primary-soft: #134e4a;
  --primary-soft-text: #99f6e4;
  --good: #34d399;
  --good-bg: #064e3b;
  --warn: #fbbf24;
  --warn-bg: #451a03;
  --alert: #f87171;
  --alert-bg: #450a0a;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

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

.app-shell {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
}

.top-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

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

.brand-icon {
  border-radius: 7px;
}

.brand-name {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-sync-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-good {
  background: var(--good-bg);
  color: var(--good);
}
.badge-info {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
}
.badge-warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.badge-alert {
  background: var(--alert-bg);
  color: var(--alert);
}
.badge-neutral {
  background: var(--surface-soft);
  color: var(--text-sub);
}

.app-main {
  padding: 14px 14px 20px;
  flex: 1;
}

.tab-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.hint-text {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 4px;
}

/* Hero Card */
.hero-card {
  border-width: 1.5px;
}
.hero-card.hero-due {
  border-color: var(--primary);
}
.hero-card.hero-alert {
  border-color: var(--warn);
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.hero-kicker {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.hero-date {
  font-size: 1.32rem;
  font-weight: 800;
  margin-top: 2px;
}

.dday-pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-weight: 800;
  font-size: 0.95rem;
  white-space: nowrap;
}
.hero-alert .dday-pill {
  background: var(--warn-bg);
  color: var(--warn);
}

.hero-status {
  margin: 6px 0 12px;
  font-size: 0.9rem;
  color: var(--text-sub);
}

.site-flow {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.site-flow-box {
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.88rem;
}

.site-flow-box.is-rec {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
}

.site-flow-label {
  font-size: 0.72rem;
  opacity: 0.85;
}

.site-flow-arrow {
  color: var(--text-muted);
  font-weight: 700;
}

/* Pen alert banner */
.pen-alert-banner {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--warn);
  background: var(--warn-bg);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-size: 0.86rem;
}
.pen-alert-text {
  flex: 1;
}
.pen-alert-arrow {
  font-weight: 700;
  color: var(--warn);
}

/* Stats */
.stat-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-box {
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 2px;
}

.stat-label {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.stat-val {
  font-size: 1.08rem;
  font-weight: 800;
}

.stat-sub {
  font-size: 0.7rem;
  color: var(--text-sub);
}

.target-sub {
  margin-top: 10px;
  font-size: 0.83rem;
  color: var(--text-sub);
  text-align: center;
}

.text-good {
  color: var(--good);
}
.text-warn {
  color: var(--warn);
}

/* Mini list */
.mini-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface-soft);
  font-size: 0.86rem;
}

.mini-row-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-row-date {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.94rem;
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease;
}

.btn:active {
  transform: scale(0.985);
}

.btn-sm {
  min-height: 44px;
  padding: 0 12px;
  font-size: 0.84rem;
  white-space: nowrap;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-soft {
  background: var(--surface-soft);
  color: var(--text);
  border-color: var(--border);
}

.btn-danger-soft {
  background: var(--alert-bg);
  color: var(--alert);
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-row > .btn {
  flex: 1;
}

.field-group {
  margin-bottom: 14px;
}

.field-label {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 6px;
}

.input-ctrl {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 0.94rem;
}

.datetime-row {
  display: flex;
  gap: 8px;
}

/* Dose & Site selectors */
.chip-grid-5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.chip-btn {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0 4px;
}

.chip-btn.is-active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.site-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.site-btn {
  min-height: 48px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  cursor: pointer;
  text-align: left;
}

.site-btn.is-active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-soft-text);
  font-weight: 700;
}

.site-btn-label {
  font-size: 0.88rem;
}

.site-btn-badges {
  display: flex;
  gap: 4px;
}

.mini-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
}

.badge-rec {
  background: var(--primary);
  color: #ffffff;
}
.badge-muted {
  background: var(--border);
  color: var(--text-sub);
}

.subtle-details {
  margin-bottom: 14px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 8px 12px;
}

.subtle-details summary {
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-sub);
  padding: 4px 0;
}

.details-body {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-btn {
  min-height: 36px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 0.8rem;
  cursor: pointer;
}

.tag-btn.is-active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-soft-text);
  font-weight: 700;
}

/* Weight Stepper */
.stepper-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
}

.step-btn {
  min-height: 46px;
  min-width: 46px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
}

.weight-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.weight-number-input {
  width: 100%;
  min-height: 46px;
  border-radius: 10px;
  border: 1.5px solid var(--primary);
  background: var(--surface);
  text-align: center;
  font-size: 1.15rem;
  font-weight: 800;
  padding-right: 24px;
}

.weight-unit {
  position: absolute;
  right: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.bmi-preview-bar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface-soft);
  font-size: 0.82rem;
  margin-bottom: 12px;
}

.wt-meta-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 8px;
  margin-bottom: 14px;
}

/* Charts */
.chart-wrap {
  width: 100%;
  overflow: hidden;
}

.weight-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-grid-line {
  stroke: var(--border);
  stroke-width: 1;
}

.chart-axis-text {
  fill: var(--text-muted);
  font-size: 10px;
}

.chart-target-line {
  stroke: var(--warn);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.chart-target-label {
  fill: var(--warn);
  font-size: 10px;
  font-weight: 700;
}

.chart-dose-marker {
  stroke: var(--primary);
  stroke-width: 1;
  stroke-dasharray: 2 3;
  opacity: 0.55;
}

.chart-dose-pill {
  fill: var(--primary-soft);
}

.chart-dose-text {
  fill: var(--primary-soft-text);
  font-size: 9px;
  font-weight: 700;
}

.chart-area {
  fill: var(--primary);
  opacity: 0.12;
}

.chart-line {
  stroke: var(--primary);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot {
  fill: var(--surface);
  stroke: var(--primary);
  stroke-width: 2;
}

.chart-dot-latest {
  fill: var(--primary);
  stroke: var(--surface);
  stroke-width: 2;
}

.chart-value-label {
  fill: var(--text);
  font-size: 10.5px;
  font-weight: 700;
}

.chart-point-group {
  cursor: pointer;
}

.range-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.range-btn,
.chip-toggle {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.range-btn.is-active,
.chip-toggle.is-active {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-soft-text);
}

.chart-tooltip {
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

.chart-empty {
  padding: 24px 12px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-soft);
}

.history-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.history-badges,
.weight-row-main {
  display: flex;
  align-items: center;
  gap: 6px;
}

.weight-row-kg {
  font-size: 1.05rem;
}

.weight-row-diff {
  font-size: 0.82rem;
  font-weight: 700;
}

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.pill-dose {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
}

.pill-site {
  background: var(--surface);
  border: 1px solid var(--border);
}

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

.icon-text-btn {
  background: none;
  border: none;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-sub);
  cursor: pointer;
  padding: 4px 6px;
}

.icon-text-btn.is-danger {
  color: var(--alert);
}

.history-time {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.tag-pill {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.74rem;
}

.item-memo {
  margin: 6px 0 0;
  font-size: 0.84rem;
  color: var(--text-sub);
}

/* More Tab & Accordions */
.section-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 4px 4px 0;
}

.accordion-card {
  padding: 0;
  overflow: hidden;
}

.acc-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 16px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.94rem;
}

.acc-summary::-webkit-details-marker {
  display: none;
}

.acc-badge {
  font-size: 0.76rem;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text-sub);
}

.acc-body {
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.pen-visual {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.pen-dots {
  display: flex;
  gap: 6px;
}

.pen-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--primary);
}
.pen-dot.is-used {
  background: var(--primary);
}
.pen-dot.is-left {
  background: transparent;
}

.pen-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.sub-title {
  margin: 0 0 8px;
  font-size: 0.86rem;
  color: var(--text-sub);
}

.insight-list,
.titration-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.insight-row,
.titration-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface-soft);
  font-size: 0.85rem;
}

.titration-row.is-current {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-weight: 700;
}

.insight-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.site-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.site-stat-box {
  padding: 10px;
  border-radius: 10px;
  background: var(--surface-soft);
}
.site-stat-name {
  font-weight: 700;
  font-size: 0.86rem;
}
.site-stat-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.summary-preview {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 0.8rem;
  line-height: 1.45;
  margin-bottom: 10px;
  resize: vertical;
}

.muted-p {
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--text-sub);
  line-height: 1.5;
}

.hint-note {
  margin: 10px 0 0;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.meta-pills-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.sync-user-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.error-banner {
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--alert-bg);
  color: var(--alert);
  font-size: 0.8rem;
  margin: 0 0 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.settings-grid .field-group:last-child {
  grid-column: 1 / -1;
}

.backup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  z-index: 30;
}

.nav-tab {
  background: none;
  border: none;
  min-height: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 12px;
}

.nav-tab.is-active {
  color: var(--primary);
  font-weight: 700;
}

.nav-ico {
  font-size: 1.15rem;
}

.nav-lbl {
  font-size: 0.72rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

.modal-sheet {
  width: 100%;
  max-width: 460px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.icon-close-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  background: var(--surface-soft);
  cursor: pointer;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  font-size: 0.8rem;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: calc(82px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  pointer-events: none;
}

.toast {
  padding: 11px 14px;
  border-radius: 12px;
  background: #0f172a;
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.toast-good {
  background: var(--primary);
}
.toast.toast-alert {
  background: var(--alert);
}
.toast.is-leaving {
  opacity: 0;
  transform: translateY(6px);
}

.is-hidden {
  display: none !important;
}

.empty-state,
.empty-inline,
.loading-box {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.86rem;
  padding: 16px 8px;
}
