/* =============================================================
   เฉิดฉาย — Cost & Profit Calculator
   Brand CI:
     Brick Brown   #8A4633  (primary)
     Bright Orange #F15A29  (accent / energy)
     Golden Brown  #A2885C  (secondary accent)
     Craft Grey    #9C9C9A
     Paper / Cream #F4EFE6  (background)
     White         #FFFFFF
   Fonts:
     Headline EN  — Cormorant Garamond  (substitute for TT Ramillas)
     Headline TH  — Bai Jamjuree        (substitute for Sao Chingcha)
     Body         — Prompt               (official brand body font)
   ============================================================= */

:root {
  --brick:        #8A4633;
  --brick-dark:   #6E3526;
  --brick-soft:   #B26852;
  --orange:       #F15A29;
  --orange-soft:  #FBE4D8;
  --gold:         #A2885C;
  --gold-soft:    #E6DBC5;
  --grey:         #9C9C9A;
  --ink:          #2B201B;
  --ink-soft:     #5C4A42;
  --paper:        #F4EFE6;
  --paper-2:      #FBF7EE;
  --line:         #E4DACC;
  --white:        #FFFFFF;
  --success:      #2F7A4F;
  --danger:       #C0392B;

  --radius:        14px;
  --radius-sm:     10px;
  --shadow-sm:     0 1px 2px rgba(80, 50, 30, 0.06);
  --shadow-md:     0 8px 24px rgba(80, 40, 20, 0.08);
  --shadow-card:   0 2px 10px rgba(80, 40, 20, 0.06);
  --transition:    180ms ease;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Prompt', 'Helvetica Neue', Arial, sans-serif;
  font-weight: 400;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* subtle paper texture overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(241,90,41,0.06), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(138,70,51,0.07), transparent 60%);
  z-index: 0;
}

/* ===== Header ===== */
.site-header {
  position: relative;
  z-index: 1;
  background: linear-gradient(135deg, var(--brick) 0%, var(--brick-dark) 100%);
  color: var(--white);
  padding: 28px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: var(--shadow-md);
}
.site-header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -6px;
  height: 6px;
  background: linear-gradient(90deg, var(--orange) 0%, var(--gold) 100%);
}

.brand { display: flex; align-items: center; gap: 16px; }
.brand__logo {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--white);
  padding: 6px;
  object-fit: contain;
  box-shadow: var(--shadow-sm);
}
.brand__text { display: flex; flex-direction: column; line-height: 1.1; }
.brand__th {
  font-family: 'Bai Jamjuree', 'Prompt', sans-serif;
  font-weight: 700;
  font-size: 28px;
  letter-spacing: 0.5px;
}
.brand__sub {
  font-family: 'Prompt', sans-serif;
  font-weight: 300;
  font-size: 14px;
  opacity: 0.85;
  letter-spacing: 1.5px;
}
.header__tag { text-align: right; }
.eyebrow {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 3px;
  color: var(--gold-soft);
  text-transform: uppercase;
}
.header__title {
  margin: 4px 0 0;
  font-family: 'Bai Jamjuree', 'Prompt', sans-serif;
  font-weight: 600;
  font-size: clamp(20px, 3vw, 28px);
  letter-spacing: 0.3px;
}

/* ===== Layout ===== */
.container {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 60px;
  display: grid;
  gap: 24px;
}

/* ===== Card ===== */
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 24px;
}
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px dashed var(--line);
}
.card__title {
  margin: 0;
  font-family: 'Bai Jamjuree', 'Prompt', sans-serif;
  font-weight: 600;
  font-size: 20px;
  color: var(--brick);
}
.card__title .muted { color: var(--grey); font-weight: 400; font-size: 14px; }

/* ===== Buttons ===== */
.btn {
  appearance: none;
  border: 1px solid transparent;
  background: var(--brick);
  color: var(--white);
  font-family: inherit;
  font-weight: 500;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: var(--transition);
}
.btn:hover { background: var(--brick-dark); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn--ghost {
  background: transparent;
  border-color: var(--brick);
  color: var(--brick);
}
.btn--ghost:hover { background: var(--brick); color: var(--white); }

/* ===== Form ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}
.fieldset {
  border: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 14px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 18px 16px 16px;
}
.fieldset__legend {
  padding: 4px 10px;
  margin-left: 4px;
  background: var(--brick);
  color: var(--white);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.4px;
  border-radius: 999px;
}

.field { display: grid; gap: 6px; }
.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
}
.field label .muted { color: var(--grey); font-weight: 400; }

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--white);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.input-wrap:focus-within {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(241, 90, 41, 0.15);
}
.input-wrap input {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: textfield;
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
  min-width: 0;
}
.input-wrap input::-webkit-outer-spin-button,
.input-wrap input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input-wrap .suffix {
  padding: 0 12px 0 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--grey);
  border-left: 1px solid var(--line);
  margin-left: 6px;
  padding-left: 12px;
  line-height: 36px;
}

/* ===== Summary Cards ===== */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.stat {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}
.stat::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--gold);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat__label {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.4px;
  color: var(--ink-soft);
  text-transform: uppercase;
}
.stat__value {
  font-family: 'Cormorant Garamond', 'Bai Jamjuree', serif;
  font-weight: 600;
  font-size: 30px;
  color: var(--brick);
  line-height: 1.05;
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.stat__value small {
  font-family: 'Prompt', sans-serif;
  font-size: 13px;
  font-weight: 400;
  color: var(--grey);
}
.stat__hint { font-size: 12px; color: var(--grey); }

.stat--accent::before { background: var(--orange); }
.stat--accent .stat__value { color: var(--orange); }

.stat--profit::before { background: var(--success); }
.stat--profit .stat__value { color: var(--success); }
.stat--profit.is-loss::before { background: var(--danger); }
.stat--profit.is-loss .stat__value { color: var(--danger); }

.stat--total {
  background: linear-gradient(135deg, var(--brick) 0%, var(--brick-dark) 100%);
  color: var(--white);
}
.stat--total::before { background: var(--orange); }
.stat--total .stat__label { color: rgba(255,255,255,0.75); }
.stat--total .stat__value { color: var(--white); }
.stat--total .stat__value small { color: rgba(255,255,255,0.7); }
.stat--total .stat__hint { color: rgba(255,255,255,0.7); }

/* ===== Warning ===== */
.warning {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--orange-soft);
  border: 1px solid var(--orange);
  color: var(--brick-dark);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow-card);
}
.warning svg { flex-shrink: 0; color: var(--orange); margin-top: 2px; }
.warning__text { display: flex; flex-direction: column; gap: 2px; }
.warning__text strong { font-weight: 600; color: var(--brick); }
.warning__text span { font-size: 14px; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
.breakdown {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.breakdown thead th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.5px;
  color: var(--grey);
  text-transform: uppercase;
  padding: 10px 12px;
  border-bottom: 2px solid var(--line);
  background: var(--paper-2);
}
.breakdown tbody th {
  text-align: left;
  font-weight: 400;
  color: var(--ink);
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.breakdown tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  white-space: nowrap;
}
.breakdown .num { text-align: right; font-variant-numeric: tabular-nums; }
.breakdown thead th.num { text-align: right; }
.breakdown td.spacer { padding: 0; border: none; height: 8px; background: transparent; }
.breakdown tr.row-deduct td,
.breakdown tr.row-deduct th { color: var(--danger); }
.breakdown tr.row-total th,
.breakdown tr.row-total td {
  font-weight: 600;
  background: var(--gold-soft);
  color: var(--brick-dark);
  border-bottom: 2px solid var(--gold);
}
.breakdown tr.row-profit th,
.breakdown tr.row-profit td {
  font-weight: 700;
  background: var(--brick);
  color: var(--white);
  font-size: 15px;
}
.breakdown tr.row-profit.is-loss th,
.breakdown tr.row-profit.is-loss td {
  background: var(--danger);
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  color: var(--grey);
  padding-top: 12px;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .site-header { padding: 20px 18px; flex-direction: column; align-items: flex-start; gap: 14px; }
  .header__tag { text-align: left; }
  .container { padding: 18px 14px 40px; gap: 18px; }
  .card { padding: 18px 16px; }
  .form-grid { grid-template-columns: 1fr; gap: 16px; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat__value { font-size: 24px; }
  .brand__logo { width: 54px; height: 54px; }
  .brand__th { font-size: 24px; }
}
@media (max-width: 380px) {
  .summary { grid-template-columns: 1fr; }
}
