/* ============================================================
   PPA Design Studio — โซลาร์ยีลด์+การเงินรายชั่วโมง
   Palette: navy #0f294a · teal #0d9488 · green #16a34a · amber #d97706
   ============================================================ */
:root {
  --navy: #0f294a;
  --navy-700: #1b3a5e;
  --teal: #0d9488;
  --teal-600: #0f766e;
  --green: #16a34a;
  --amber: #d97706;
  --bg: #eef2f7;
  --card: #ffffff;
  --ink: #1a2330;
  --ink-soft: #5a6573;
  --line: #e3e9f0;
  --radius: 18px;
  --shadow: 0 4px 24px rgba(15, 41, 74, .07);
  --shadow-lg: 0 12px 40px rgba(15, 41, 74, .13);
  --font: 'Sarabun', 'Prompt', system-ui, sans-serif;
  --font-head: 'Prompt', 'Sarabun', sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font); background: var(--bg); color: var(--ink);
  line-height: 1.6; font-size: 16px; -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50; background: rgba(255,255,255,.86);
  backdrop-filter: blur(14px); border-bottom: 1px solid var(--line);
}
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 12px 18px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--amber), #fbbf24);
  display: grid; place-items: center; color: #fff; font-size: 22px;
  box-shadow: 0 4px 14px rgba(217,119,6,.35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-family: var(--font-head); font-size: 18px; color: var(--navy); font-weight: 700; }
.brand-text small { font-size: 11.5px; color: var(--ink-soft); }

/* ---------- Layout ---------- */
.page { min-height: 60vh; }
.container { max-width: 1240px; margin: 0 auto; padding: 24px 18px 40px; }
.page-title { font-family: var(--font-head); font-size: 24px; color: var(--navy); font-weight: 700; margin-bottom: 4px; }
.page-sub { color: var(--ink-soft); font-size: 14.5px; margin-bottom: 22px; }
.work-grid { display: grid; grid-template-columns: 1fr 1.15fr; gap: 22px; align-items: start; }

/* ---------- Cards / fields ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; border: 1px solid var(--line); }
.card + .card { margin-top: 16px; }
.card-title {
  font-family: var(--font-head); font-weight: 600; font-size: 16.5px; color: var(--navy);
  display: flex; align-items: center; gap: 8px; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--line);
}
.card-title i { color: var(--teal); font-size: 20px; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 13.5px; font-weight: 500; color: var(--ink); margin-bottom: 6px; }
.field-label em { color: var(--ink-soft); font-style: normal; font-weight: 400; font-size: 12px; }
.field input[type=text], .field input[type=number], .field select {
  width: 100%; padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 11px;
  font-size: 15px; font-family: var(--font); color: var(--ink); background: #fff; transition: .16s;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13,148,136,.12);
}
.field-hint { display: block; font-size: 12px; color: var(--ink-soft); margin-top: 5px; }
.field-hint-warn { color: #92400e; display: flex; align-items: flex-start; gap: 5px; margin-bottom: 10px; }
.field-hint-warn i { flex-shrink: 0; margin-top: 1px; }
.req-check { color: #b45309; font-weight: 600; font-size: 12px; }
.link-btn {
  background: none; border: none; padding: 0; margin-left: 10px; cursor: pointer;
  color: var(--teal-600); font-size: 12.5px; text-decoration: underline; font-family: inherit;
}

.map-wrap { margin-top: 12px; }
#location-map {
  height: 260px; border-radius: 13px; border: 1.5px solid var(--line);
  z-index: 1;
}
.map-hint {
  display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-soft);
  margin-top: 6px;
}
#btn-gps.locating { opacity: .7; pointer-events: none; }

.field-check {
  display: flex; align-items: center; gap: 9px; font-size: 14px; color: var(--ink);
  cursor: pointer; padding: 4px 0;
}
.field-check input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--teal); cursor: pointer; }

details.more-options { margin: 6px 0 12px; }
details.more-options summary {
  cursor: pointer; font-size: 13.5px; color: var(--teal-600); font-weight: 500;
  list-style: none; display: inline-flex; align-items: center; gap: 5px; padding: 4px 0;
}
details.more-options summary::-webkit-details-marker { display: none; }
details.more-options[open] summary { margin-bottom: 10px; }

/* ---------- Buttons ---------- */
.btn-primary {
  width: 100%; padding: 14px; border: none; border-radius: 13px; cursor: pointer;
  background: linear-gradient(135deg, var(--teal), var(--teal-600)); color: #fff;
  font-family: var(--font-head); font-weight: 600; font-size: 16px;
  display: flex; align-items: center; justify-content: center; gap: 9px; transition: .18s;
  box-shadow: 0 6px 18px rgba(13,148,136,.32);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(13,148,136,.42); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-secondary {
  width: 100%; padding: 12px; border: 1.5px solid var(--teal); border-radius: 12px; cursor: pointer;
  background: #fff; color: var(--teal-600); font-family: var(--font-head); font-weight: 600; font-size: 14.5px;
  display: flex; align-items: center; justify-content: center; gap: 8px; transition: .16s; margin-top: 10px;
}
.btn-secondary:hover { background: #f0fdfa; }
.btn-secondary:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Result: empty / loading ---------- */
.result-empty { text-align: center; padding: 60px 28px; }
.empty-art {
  width: 88px; height: 88px; margin: 0 auto 16px; border-radius: 26px;
  background: linear-gradient(135deg, #fef3c7, #fde68a); display: grid; place-items: center;
}
.empty-art i { font-size: 44px; color: var(--amber); }
.result-empty h3 { font-family: var(--font-head); color: var(--navy); font-size: 18px; margin-bottom: 8px; }
.result-empty p { color: var(--ink-soft); font-size: 14px; }
.result-loading { text-align: center; padding: 70px 28px; display: none; }
.result-loading.show { display: block; }
.spinner {
  width: 50px; height: 50px; margin: 0 auto 18px; border-radius: 50%;
  border: 5px solid #e3e9f0; border-top-color: var(--teal); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Result content ---------- */
#result-content { display: none; }
#result-content.show { display: block; animation: rise .35s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.headline-kwp {
  padding: 20px 22px; border-radius: 16px; margin-bottom: 16px;
  background: linear-gradient(120deg, var(--teal), var(--teal-600)); color: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  box-shadow: 0 10px 28px rgba(13,148,136,.3);
}
.hk-label { font-size: 13px; opacity: .9; }
.hk-value { display: block; font-family: var(--font-head); line-height: 1; margin: 4px 0; font-size: 34px; font-weight: 700; }
.hk-sub { font-size: 12.5px; opacity: .9; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { border-radius: 14px; padding: 14px 10px; text-align: center; }
.stat-green { background: #f0fdf4; } .stat-teal { background: #f0fdfa; }
.stat-navy { background: #f1f5fb; } .stat-amber { background: #fffbeb; }
.stat-label { display: block; font-size: 11.5px; color: var(--ink-soft); font-weight: 500; }
.stat-value { display: block; font-family: var(--font-head); font-size: 22px; font-weight: 700; line-height: 1.25; }
.stat-green .stat-value { color: var(--green); } .stat-teal .stat-value { color: var(--teal-600); }
.stat-navy .stat-value { color: var(--navy); } .stat-amber .stat-value { color: var(--amber); }
.stat-unit { font-size: 11px; color: var(--ink-soft); }

.chart-wrap { position: relative; height: 260px; margin-bottom: 6px; }

.card-title-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--line);
}
.seg-toggle { display: flex; background: #f1f5f9; border-radius: 10px; padding: 3px; flex-shrink: 0; }
.seg-btn {
  border: none; background: transparent; padding: 6px 14px; border-radius: 8px;
  font-family: var(--font); font-size: 13px; font-weight: 500; color: var(--ink-soft); cursor: pointer;
  transition: .15s;
}
.seg-btn.active { background: #fff; color: var(--teal-600); box-shadow: 0 1px 4px rgba(15,41,74,.12); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data-table th, table.data-table td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--line); }
table.data-table th:first-child, table.data-table td:first-child { text-align: left; }
table.data-table thead th { color: var(--ink-soft); font-weight: 600; background: #f8fafc; }
.table-scroll { overflow-x: auto; }

.loss-row { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.loss-row span { color: var(--ink-soft); }
.loss-row b { color: var(--ink); }
.loss-row .neg { color: #dc2626; }

#dscr-note {
  margin-top: 12px; padding: 10px 14px; border-radius: 10px; font-size: 13px;
  display: flex; align-items: center; gap: 8px; font-weight: 500;
}
#dscr-note.ok { background: #f0fdf4; color: #15803d; }
#dscr-note.warn { background: #fef2f2; color: #b91c1c; }

.disclaimer {
  margin-top: 14px; padding: 12px 15px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 11px;
  font-size: 12.5px; color: #92400e; display: flex; gap: 8px; line-height: 1.5;
}
.disclaimer i { font-size: 16px; flex-shrink: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--navy); color: #fff; padding: 13px 22px; border-radius: 12px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg); opacity: 0; transition: .3s; z-index: 200; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #b91c1c; }

/* ---------- Login / entry page ---------- */
.login-wrap { max-width: 440px; margin: 60px auto; padding: 0 18px; }
.login-card { text-align: center; padding: 40px 30px; }
.login-icon {
  width: 74px; height: 74px; margin: 0 auto 18px; border-radius: 20px;
  background: linear-gradient(135deg, var(--navy), var(--navy-700));
  display: grid; place-items: center;
}
.login-icon i { font-size: 38px; color: #fff; }
.login-card h1 { font-family: var(--font-head); font-size: 19px; color: var(--navy); font-weight: 700; line-height: 1.35; }
.login-sub { color: var(--ink-soft); font-size: 13.5px; margin: 8px 0 22px; }
.login-error {
  display: flex; align-items: center; gap: 7px; justify-content: center;
  background: #fee2e2; color: #b91c1c; border-radius: 10px; padding: 10px 14px;
  font-size: 13.5px; font-weight: 500; margin-bottom: 16px;
}
.login-card form { text-align: left; }
.login-card .btn-primary { margin-top: 6px; }
.topbar-user { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.topbar-inner { display: flex; align-items: center; }
.logout-link {
  display: inline-flex; align-items: center; gap: 5px; font-size: 13.5px; color: var(--ink-soft);
  padding: 7px 12px; border-radius: 9px; border: 1px solid var(--line);
}
.logout-link:hover { border-color: #fca5a5; color: #dc2626; }
.logout-link.active { background: var(--navy); color: #fff; border-color: var(--navy); }

/* ---------- Flash messages ---------- */
.flash-wrap { max-width: 1240px; margin: 14px auto 0; padding: 0 18px; }
.flash { padding: 12px 16px; border-radius: 12px; margin-bottom: 8px; font-size: 14.5px; font-weight: 500; }
.flash-success { background: #dcfce7; color: #15803d; }
.flash-warning { background: #fef3c7; color: #b45309; }
.flash-danger  { background: #fee2e2; color: #b91c1c; }

/* ---------- Settings page ---------- */
.settings-wrap { max-width: 820px; margin: 0 auto; }
.settings-intro { color: var(--ink-soft); font-size: 14.5px; margin-bottom: 20px; }
.settings-actions { display: flex; gap: 12px; margin-top: 10px; }
.settings-actions .btn-primary { width: auto; flex: 1; }
.btn-ghost {
  padding: 14px 22px; border: 1.5px solid var(--line); border-radius: 13px; background: #fff;
  color: var(--ink-soft); font-family: var(--font-head); font-weight: 600; cursor: pointer; font-size: 14.5px;
}
.btn-ghost:hover { border-color: #fca5a5; color: #dc2626; }

/* ---------- Roof layout (draw + auto panel-fill) ---------- */
.roof-tools { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.roof-tools-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.roof-result { margin-top: 4px; }

/* ---------- History page ---------- */
.history-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.history-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.history-search { position: relative; flex: 1; min-width: 220px; }
.history-search i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); font-size: 15px; }
.history-search input { width: 100%; padding: 10px 13px 10px 36px; border: 1.5px solid var(--line); border-radius: 11px; font-size: 14px; font-family: var(--font); color: var(--ink); }
.history-search input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(13,148,136,.12); }
.history-search .search-clear { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); }
.btn-mini {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 15px; border-radius: 10px;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink); font-size: 13.5px; font-weight: 500;
  white-space: nowrap; transition: .15s; cursor: pointer;
}
.btn-mini:hover { border-color: var(--teal); color: var(--teal-600); }
.btn-mini-ghost:hover { border-color: #fca5a5; color: #dc2626; }
.history-empty { text-align: center; padding: 50px 24px; color: var(--ink-soft); }
.history-empty i { font-size: 34px; margin-bottom: 10px; display: block; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 7px; font-size: 11.5px; font-weight: 600; }
.badge-school { background: #f0fdfa; color: var(--teal-600); }
.badge-government { background: #f1f5fb; color: var(--navy); }
.badge-boi { background: #fef3c7; color: #b45309; margin-left: 4px; }
.hist-del-btn { background: none; border: none; color: var(--ink-soft); cursor: pointer; font-size: 16px; padding: 4px 6px; border-radius: 7px; }
.hist-del-btn:hover { color: #dc2626; background: #fee2e2; }
.hist-name { font-weight: 600; color: var(--ink); }
.hist-sub { display: block; font-size: 11.5px; color: var(--ink-soft); font-weight: 400; }

/* ---------- Footer ---------- */
.site-footer { text-align: center; padding: 26px 18px; color: var(--ink-soft); font-size: 12.5px; }
.site-footer .muted { font-size: 11.5px; opacity: .8; margin-top: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .work-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .field-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; row-gap: 8px; }
  .topbar-user { margin-left: 0; width: 100%; flex-wrap: wrap; gap: 8px; }
  .logout-link { font-size: 12.5px; padding: 6px 10px; }
  .history-head { flex-direction: column; align-items: stretch; }
}
