/* Quy ra giờ làm — gọn như máy tính, nhưng ấm và hơi nghịch */

:root {
  color-scheme: light dark;
  --bg: #FBF4EA;
  --surface: #FFFCF7;
  --soft: #F4EADD;
  --ink: #2A1F17;
  --muted: #86766A;
  --hairline: #EFE4D6;
  --accent: #E0571F;
  --accent-ink: #FFFFFF;
  --accent-soft: #FFE4D3;
  --accent-line: #F2B394;
  --ins: #CDB8A2;
  --tax: #8C5A3C;
  --warn: #B4620E;
  --edge: 1px solid var(--hairline); /* thiết kế phẳng: viền mảnh thay cho đổ bóng */
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1511;
    --surface: #241D17;
    --soft: #2F271F;
    --ink: #F6EBDD;
    --muted: #AE9D8C;
    --hairline: #342B23;
    --accent: #FF8A57;
    --accent-ink: #1A1511;
    --accent-soft: #3A2419;
    --accent-line: #8A4B2C;
    --ins: #6E5E50;
    --tax: #D49A6E;
    --warn: #F0B45A;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; }

.wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

/* --- Đầu trang & tab --- */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 2px 16px;
}

.clock { width: 44px; height: 44px; flex: none; }
.clock .face { fill: var(--accent-soft); stroke: var(--accent); }
.clock .hand-long { stroke: var(--accent); }
.clock .hand-short { stroke: var(--ink); }
.clock .pin { fill: var(--ink); }
.clock .hand-long {
  transform-box: view-box;
  transform-origin: 50% 50%;
  animation: tick 12s steps(12) infinite;
}
@keyframes tick { to { transform: rotate(360deg); } }

h1 {
  margin: 0;
  font-size: 23px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.tagline { margin: 2px 0 0; font-size: 14px; color: var(--muted); }

.tabs {
  display: grid;
  grid-template-columns: repeat(5, auto);
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px;
  border-radius: 999px;
  background: var(--soft);
}

.tabs [role="tab"] {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 9px 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}
.tabs::-webkit-scrollbar { display: none; }
@media (max-width: 400px) {
  .tabs { gap: 0; padding: 3px; }
  .tabs [role="tab"] { padding: 9px 5px; font-size: 12.5px; }
}
.tabs [role="tab"][aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

/* --- Khung kết quả --- */
.hero {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  margin: 16px 0 6px;
  padding: 22px 18px 20px;
  border-radius: 28px;
  border: 1px solid color-mix(in srgb, var(--accent) 14%, transparent);
  background: var(--accent-soft);
  text-align: center;
}
.hero::before {
  content: "";
  position: absolute;
  z-index: -1;
  right: -60px;
  top: -70px;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
}
.hero::after {
  content: "";
  position: absolute;
  z-index: -1;
  left: -40px;
  bottom: -60px;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.sticker {
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 30px;
  line-height: 1;
  transform: rotate(12deg);
  animation: wobble 3.2s ease-in-out infinite;
}
@keyframes wobble {
  0%, 100% { transform: rotate(12deg); }
  50% { transform: rotate(-6deg) translateY(-2px); }
}

.hero-label {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.hero-value {
  margin: 2px 0 0;
  font-size: clamp(42px, 13vw, 60px);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.035em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.hero-value.empty { color: var(--accent-line); }
.hero-value .unit {
  font-size: 0.42em;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--ink);
  margin: 0 0.35em 0 0.12em;
}
.hero-value .unit:last-child { margin-right: 0; }

.hero-detail {
  margin: 2px 0 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}

.hero-sub {
  margin: 10px auto 0;
  max-width: 34ch;
  font-size: 15px;
  color: var(--muted);
}
.hero-sub.result-text { color: var(--ink); }

.hero-quip {
  display: inline-block;
  margin: 12px auto 0;
  padding: 7px 12px;
  border-radius: 14px;
  background: var(--surface);
  font-size: 14px;
  line-height: 1.4;
  transform: rotate(-1deg);
}

.pop { animation: pop 0.32s cubic-bezier(0.3, 1.5, 0.6, 1); }
.sticker.pop { animation: pop 0.32s cubic-bezier(0.3, 1.5, 0.6, 1), wobble 3.2s ease-in-out 0.32s infinite; }
@keyframes pop {
  from { transform: scale(0.85); opacity: 0.5; }
  to { transform: scale(1); opacity: 1; }
}

.bar {
  display: flex;
  height: 10px;
  max-width: 280px;
  margin: 14px auto 0;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface);
}
.bar span { height: 100%; transition: width 0.4s cubic-bezier(0.3, 1.3, 0.6, 1); }
.b-net, .dot-net { background: var(--accent); }
.b-ins, .dot-ins { background: var(--ins); }
.b-tax, .dot-tax { background: var(--tax); }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: 1px;
}

.share-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding: 9px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
}
.share-btn svg { width: 16px; height: 16px; }

/* --- Nhóm dòng --- */
.group { margin: 0 0 8px; }

.group-title {
  margin: 20px 6px 8px;
  font-size: 15.5px;
  font-weight: 700;
}

.list {
  margin: 0;
  background: var(--surface);
  border-radius: 22px;
  border: var(--edge);
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding: 10px 16px;
  margin: 0;
  position: relative;
  cursor: text;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 16px;
  border-top: 1px dashed var(--hairline);
}
div.row { cursor: default; }

.row-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.row-label { font-size: 15.5px; font-weight: 600; }
.row-sub {
  font-size: 12.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.row-sub:empty { display: none; }
.row-sub.preview { color: var(--accent); font-weight: 600; }
.row-sub.warn { color: var(--warn); font-weight: 500; }

/* Ô nhập: chỗ trống để điền, không phải ô bảng tính */
.row-input { position: relative; flex: none; width: 44%; max-width: 180px; }
.row-input.short { width: 64px; }
.row-input input {
  width: 100%;
  height: 42px;
  padding: 0 2px;
  border: 0;
  border-bottom: 2px dashed var(--accent-line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 20px; /* >= 16px để iOS không tự phóng to */
  font-weight: 750;
  letter-spacing: -0.01em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s, background 0.15s;
}
.row-input.money input { padding-right: 20px; }
.row-input.money::after {
  content: "đ";
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 16px;
  font-weight: 600;
  pointer-events: none;
}
.row-input input.long { font-size: 17px; }
.row-input input.longer { font-size: 15px; }
.row-input input::placeholder { color: var(--muted); opacity: 0.45; font-weight: 600; }
.row-input input:focus {
  outline: none;
  border-bottom-style: solid;
  border-bottom-color: var(--accent);
  background: linear-gradient(to top, var(--accent-soft), transparent 70%);
}
.row-input input[aria-invalid="true"] { border-bottom-color: var(--warn); border-bottom-style: solid; }
.row-input input::-webkit-calendar-picker-indicator { display: none !important; }

.row-value {
  font-size: 18px;
  font-weight: 750;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Dòng chi tiết (chỉ đọc) */
dl.list > .row { min-height: 50px; }
dl.list dt { color: var(--muted); font-size: 15px; }
dl.list dd { margin: 0; font-size: 15.5px; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
dl.list > .row.plus dd { color: var(--accent); }
dl.list > .row.total { background: var(--accent-soft); }
dl.list > .row.total::before { display: none; }
dl.list > .row.total dt { color: var(--ink); font-weight: 750; }
dl.list > .row.total dd { font-size: 18px; font-weight: 800; color: var(--accent); }
dl.list dt small { display: block; font-size: 12.5px; }

/* Người phụ thuộc & vùng */
.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}
.stepper button {
  appearance: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.1s;
}
.stepper button:active { transform: scale(0.88); }
.stepper button:disabled { opacity: 0.35; cursor: default; }
.stepper output {
  min-width: 26px;
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.seg {
  display: flex;
  gap: 4px;
}
.seg button {
  appearance: none;
  min-width: 34px;
  height: 34px;
  padding: 0 6px;
  border: 1.5px solid var(--hairline);
  border-radius: 999px;
  background: transparent;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.seg button[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

/* --- Nút gợi ý: một hàng, vuốt ngang --- */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 -16px 10px;
  padding: 2px 16px 6px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  appearance: none;
  background: var(--surface);
  border: var(--edge);
  font-size: 14px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s, background 0.12s;
}
.chip:nth-child(odd) { transform: rotate(-1.5deg); }
.chip:nth-child(even) { transform: rotate(1.5deg); }
.chip:active { transform: scale(0.92); background: var(--accent-soft); }

.group-foot {
  margin: 10px 6px 0;
  font-size: 13.5px;
  color: var(--muted);
}

.link-btn {
  appearance: none;
  border: 0;
  background: none;
  padding: 2px 0;
  color: var(--accent);
  font-weight: 650;
  text-decoration: underline;
  text-decoration-style: wavy;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  cursor: pointer;
}

.primary-btn {
  appearance: none;
  display: block;
  width: 100%;
  min-height: 52px;
  margin: 16px 0 0;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 750;
  cursor: pointer;
}
.primary-btn:active, .share-btn:active { transform: scale(0.97); }

.fine {
  margin: 12px 6px 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.tabs [role="tab"]:focus-visible, .link-btn:focus-visible, .primary-btn:focus-visible,
.share-btn:focus-visible, .stepper button:focus-visible, .seg button:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Thông báo nổi --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- Giỏ hàng --- */
.item-row { gap: 10px; }
.item-row .row-main { flex: 1; }
.item-name {
  width: 100%;
  height: 34px;
  padding: 0;
  border: 0;
  border-bottom: 2px dashed transparent;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* >= 16px để iOS không tự phóng to */
  font-weight: 600;
}
.item-name::placeholder { color: var(--muted); opacity: 0.7; font-weight: 500; }
.item-name:focus { outline: none; border-bottom-color: var(--accent-line); }
.item-name::-webkit-calendar-picker-indicator { display: none !important; }
.item-row .row-input { width: 48%; max-width: 200px; }
.item-remove {
  appearance: none;
  flex: none;
  width: 28px;
  height: 28px;
  margin-right: -6px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}
.item-remove:hover, .item-remove:focus-visible { background: var(--accent-soft); color: var(--accent); outline: none; }
.list-gap { margin-top: 12px; }
button.add-row {
  appearance: none;
  width: 100%;
  min-height: 48px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 15px;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}
button.add-row:hover, button.add-row:focus-visible { background: var(--accent-soft); outline: none; }

/* Quy ra đồ đời thường */
.hero-equiv {
  margin: 10px auto 0;
  max-width: 36ch;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink);
}

/* --- Công tắc chế độ ở tab Lương --- */
.mode-seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  margin: 16px 0 0;
  padding: 3px;
  border-radius: 14px;
  background: var(--soft);
}
.mode-seg button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 8px 4px;
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 650;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.mode-seg button[aria-checked="true"] {
  background: var(--surface);
  color: var(--accent);
}

/* So sánh 2 offer: bảng 3 cột nhãn | A | B */
.offer-grid { padding: 4px 16px 8px; }
.offer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 1.1fr);
  gap: 10px;
  align-items: center;
  min-height: 54px;
  border-top: 1px dashed var(--hairline);
}
.offer-row.offer-head { min-height: 38px; border-top: 0; font-size: 13px; font-weight: 700; color: var(--accent); text-align: right; }
.offer-row .row-label { font-size: 14.5px; }
.offer-row input {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 2px;
  border: 0;
  border-bottom: 2px dashed var(--accent-line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  font-weight: 750;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.offer-row input:focus { outline: none; border-bottom-style: solid; border-bottom-color: var(--accent); }
.offer-row input[aria-invalid="true"] { border-bottom-color: var(--warn); border-bottom-style: solid; }
.offer-row input::placeholder { color: var(--muted); opacity: 0.45; }

.offer-result { margin: 14px 0 0; text-align: left; }
.offer-result > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-top: 6px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}
.offer-result > div.win { background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent); }
.offer-result dt { font-weight: 700; }
.offer-result dt small { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.offer-result dd { margin: 0; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Cách mua, mẫu ảnh */
.seg-text button { padding: 0 9px; font-size: 13px; white-space: nowrap; }
/* Dòng có nhiều lựa chọn chữ: đưa nút xuống hàng riêng, chia đều bề ngang */
.row.stack { flex-wrap: wrap; row-gap: 8px; }
.row.stack .row-main { flex-basis: 100%; }
.row.stack .seg { width: 100%; }
.row.stack .seg button { flex: 1; }
.share-box { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 14px; }
.share-box .share-btn { margin-top: 0; }
.seg-mini { height: 30px; }
.seg-mini button { height: 30px; min-width: 0; padding: 0 12px; font-size: 12.5px; background: var(--surface); }

/* Thói quen */
.habit-row { align-items: flex-start; padding-top: 12px; padding-bottom: 12px; }
.habit-row .row-input { margin-top: 2px; }
.habit-row .item-remove { margin-top: 6px; }
.freq { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.freq-times {
  width: 44px;
  height: 30px;
  padding: 0 4px;
  border: 0;
  border-bottom: 2px dashed var(--accent-line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}
.freq-times:focus { outline: none; border-bottom-style: solid; border-bottom-color: var(--accent); }
.freq-times[aria-invalid="true"] { border-bottom-color: var(--warn); border-bottom-style: solid; }
.freq-per {
  height: 30px;
  padding: 0 6px;
  border: 0;
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
dl.list > .row.top dd { color: var(--accent); }

/* Đồng hồ */
.row-input.time { width: auto; }
.row-input.time input { width: 118px; text-align: right; font-size: 18px; }
.row-input.time input::-webkit-calendar-picker-indicator { opacity: 0.5; cursor: pointer; }
.toilet-btn {
  appearance: none;
  margin-top: 16px;
  padding: 11px 20px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 15.5px;
  font-weight: 700;
  border: var(--edge);
  cursor: pointer;
}
.toilet-btn.active { background: var(--accent); color: var(--accent-ink); }
.toilet-btn:active { transform: scale(0.97); }
.toilet-live {
  margin: 10px 0 0;
  font-size: 18px;
  font-weight: 750;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.salary-ctx { line-height: 1.5; }

/* Tab Dữ liệu */
.hero-value.hero-text { font-size: clamp(28px, 8vw, 36px); letter-spacing: -0.02em; }
dl.list dd.none { color: var(--muted); font-weight: 500; }
.danger-btn {
  appearance: none;
  margin-top: 16px;
  padding: 10px 20px;
  border: 1.5px solid var(--warn);
  border-radius: 999px;
  background: var(--surface);
  color: var(--warn);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.danger-btn:hover:not(:disabled) { background: var(--warn); color: var(--surface); }
.danger-btn:disabled { opacity: 0.4; cursor: default; }
.danger-btn:focus-visible { outline: 2px solid var(--warn); outline-offset: 2px; }

/* --- Bố cục: điện thoại một cột (kết quả lên đầu), màn rộng hai cột nhập | kết quả --- */
.panel { display: flex; flex-direction: column; }
.side { display: contents; }
.o-1 { order: 1; }
.o-2 { order: 2; }
.o-3 { order: 3; }
.o-4 { order: 4; }
.o-5 { order: 5; }
.desk-only { display: none; }

@media (min-width: 860px) {
  .wrap { max-width: 1040px; padding: 32px 28px 32px; }

  .top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
  }
  .brand { margin: 0; }
  .tabs { width: 400px; flex: none; }

  .panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 32px;
    align-items: start;
    margin-top: 28px;
  }
  .side { display: flex; flex-direction: column; gap: 14px; }
  /* Công tắc chế độ nằm giữa, trên cả hai cột, để hai cột bắt đầu cùng một hàng */
  .panel > .mode-seg { grid-column: 1 / -1; justify-self: center; width: min(460px, 100%); margin: 0 0 -6px; }
  .side-result { position: sticky; top: 20px; }
  .desk-only { display: block; }

  .panel .hero, .panel .group, .panel .primary-btn { margin: 0; }
  .side > .group-title, .panel .group-title { margin: 0 6px 10px; }
  .side > .group-title { margin-bottom: -4px; }
  .side-input .col + .col { margin-top: 24px; }
  .panel .fine { margin-top: 0; }

  .chips { flex-wrap: wrap; overflow: visible; margin: 0 0 12px; padding: 0 2px; }
  dl.list > .row { min-height: 44px; padding-top: 7px; padding-bottom: 7px; }
  .hero { padding: 24px 22px 22px; }
}

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