/* ===========================================================================
   Electricity Calculator — fresh light + energy theme
   Mobile-first, responsive, no framework.
   =========================================================================== */

:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;

  --primary: #0f766e;
  --primary-600: #0d9488;
  --primary-50: #f0fdfa;
  --accent: #f59e0b;
  --accent-soft: #fef3c7;
  --grad: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);
  --danger: #dc2626;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  --fs: 16px;
}

* {
  box-sizing: border-box;
}
/* `hidden` must win over layout rules like `display:grid` (class specificity
   would otherwise override the UA [hidden] rule and keep the panel visible). */
[hidden] {
  display: none !important;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Bengali",
    "Hind Siliguri", Arial, sans-serif;
  font-size: var(--fs);
  color: var(--ink);
  line-height: 1.5;
  background: var(--bg)
    radial-gradient(1200px 480px at 80% -10%, rgba(16, 185, 129, 0.12), transparent 60%),
    radial-gradient(900px 420px at -10% 0%, rgba(6, 182, 212, 0.1), transparent 55%);
  background-attachment: fixed;
  min-height: 100vh;
}

.wrap {
  width: 100%;
  max-width: 1400px;
  margin-inline: auto;
  padding-inline: 16px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 8px 0;
  z-index: 100;
}
.skip-link:focus {
  left: 0;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-block: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--grad);
  color: #fff;
  font-size: 22px;
  box-shadow: var(--shadow-sm);
  flex: none;
}
.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.brand-name {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.brand-tag {
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lang-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  flex: none;
}
.lang-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.lang-btn.is-on {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  padding-block: 20px 28px;
}
@media (min-width: 920px) {
  .layout {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
    align-items: start;
  }
  .col-result {
    position: sticky;
    top: 76px;
  }
}
.col {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

/* ---------- panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.panel-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
}
.panel-hint {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
/* mobile: stack heading above actions, give actions full width for even wrapping */
@media (max-width: 520px) {
  .panel-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .panel-head-left {
    width: 100%;
  }
  .period-panel .panel-head {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
  }
  .period-panel .panel-head-left {
    flex: 1 1 0%;
    min-width: 0;
  }
  .period-panel #resetBtn {
    flex-shrink: 0;
  }
  .panel-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .panel-actions .btn,
  .panel-actions select {
    flex: 1 1 auto;
    min-width: 0;
  }
  .scenario-select {
    max-width: none;
  }
}
.panel-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.device-count-badge {
  background: var(--primary-50);
  color: var(--primary);
  border: 1px solid #99f6e4;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  min-width: 22px;
  text-align: center;
}
/* scenario dropdown styled as a ghost button */
.scenario-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 26px;
  cursor: pointer;
  max-width: 170px;
}

/* ---------- fields ---------- */
.field {
  display: block;
  min-width: 0;
}
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.text-input {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.text-input:focus {
  outline: none;
  border-color: var(--primary-600);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18);
}
input[type="number"] {
  -moz-appearance: textfield;
}
/* date inputs are intrinsically wide on iOS/desktop — keep them in their box */
input[type="date"] {
  min-width: 0;
  max-width: 100%;
}

/* segmented control */
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 14px;
}
.seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 7px 18px;
  border-radius: 999px;
  cursor: pointer;
}
.seg-btn.is-on {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.period-body.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
/* date pickers are wide — stack start/end vertically on phones so each
   gets a full, comfortable line instead of two cramped inputs */
@media (max-width: 520px) {
  .period-body.two-col {
    grid-template-columns: 1fr;
  }
}
.days-computed {
  grid-column: 1 / -1;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-50);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

/* "Add device" button below the device list */
.add-item-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  text-align: center;
  border-style: dashed;
}

/* ---------- add device form ---------- */
.add-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.add-form .add-device {
  width: 100%;
}
.add-form .watt-edit .cb-input {
  padding-right: 38px;
}
.add-form .add-btn {
  align-self: flex-start;
}
@media (min-width: 560px) {
  .add-form .add-device {
    max-width: 50%;
  }
  .add-form .add-btn {
    margin-top: 4px;
  }
}

/* ---------- combobox ---------- */
.cb {
  position: relative;
}
.cb-input {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 11px 38px 11px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.cb-input:focus {
  outline: none;
  border-color: var(--primary-600);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.18);
}
.cb-caret {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
}
.cb-panel {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  margin: 0;
  padding: 6px;
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  -webkit-overflow-scrolling: touch;
}
.cb-group {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 8px 10px 4px;
}
.cb-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
}
.cb-opt:hover,
.cb-opt.is-active {
  background: var(--primary-50);
}
.cb-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cb-sub {
  font-size: 12px;
  color: var(--muted);
  flex: none;
}
.cb-add {
  color: var(--primary);
  font-weight: 600;
}
.cb-add .cb-label {
  white-space: normal;
}
.cb-empty {
  padding: 12px 10px;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  padding: 11px 18px;
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:active {
  transform: translateY(1px);
}
.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
  box-shadow: var(--shadow);
}
.btn-primary:disabled {
  opacity: 0.6;
  cursor: progress;
}
.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--primary-600);
}
.btn-secondary:hover {
  background: var(--primary-50);
}
.btn-secondary.ok {
  background: var(--primary);
  color: #fff;
}
.btn-ghost {
  background: var(--surface-2);
  color: var(--ink-soft);
  border-color: var(--line);
}
.btn-ghost:hover {
  background: #eef2f7;
}
.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
}
.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover {
  background: var(--line);
  color: var(--ink-soft);
}
.it-remove:hover {
  background: #fee2e2;
  color: var(--danger);
}
.it-dup:hover {
  background: var(--primary-50);
  color: var(--primary);
}

/* ---------- items ---------- */
.items {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  background: var(--surface-2);
  animation: slideIn 0.18s ease;
}
.item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.item-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  min-width: 18px;
  flex: none;
  user-select: none;
}
.item-name {
  font-weight: 700;
  font-size: 15.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.item-tools {
  display: flex;
  gap: 2px;
  flex: none;
}
.item-fields {
  display: grid;
  gap: 12px;
  align-items: end;
}
.item-fields.three {
  grid-template-columns: repeat(3, 1fr);
}
.item-fields.one {
  grid-template-columns: 130px;
}
/* phones: stack watt / hours / days each on its own full-width row so the
   hours input + unit selector always sit comfortably on one line */
@media (max-width: 520px) {
  .item-fields.three {
    grid-template-columns: 1fr;
  }
}
/* native select styled like our inputs */
select.text-input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}
.field-hint {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.45;
}
.occupied-field {
  margin-top: 14px;
  border-top: 1px dashed var(--line);
  padding-top: 14px;
}
.days-resolved {
  margin-top: 10px;
  font-size: 13px;
  color: var(--primary);
  background: var(--primary-50);
  border-radius: 8px;
  padding: 7px 11px;
}
.it-customdays {
  margin-top: 10px;
}
/* hours input + unit selector side by side */
.hours-wrap {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.hours-wrap .it-hours {
  flex: 1;
  min-width: 0;
}
.it-hoursunit {
  flex: none;
  width: auto;
  min-width: 92px;
  font-size: 13px;
  padding: 11px 28px 11px 10px;
}
/* hours input + unit selector stay on one line at every width:
   below 520px the parent .item-fields.three is already 1-column, giving
   .hours-wrap the full card width — no need to ever stack vertically. */
.chk-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--ink-soft);
}
.chk-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
  flex: none;
}
/* label + required star inline row */
.label-row {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 6px;
}
.label-row .field-label {
  margin-bottom: 0;
}
/* required field asterisk */
.req-star {
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

/* input error state */
.text-input.input-error {
  border-color: var(--danger);
  outline: none;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.12);
}
.occupied-error {
  display: block;
  font-size: 12px;
  color: var(--danger);
  margin-top: 5px;
}

/* note per device */
.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.btn-link:hover {
  color: var(--primary-600);
}
.it-note-row {
  margin-top: 8px;
}
.add-form .it-note-row {
  margin-top: 0;
}
.it-note-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.it-note {
  font-size: 13px;
  resize: vertical;
  min-height: 48px;
}

/* disabled controls read as non-interactive */
.text-input:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}
.icon-btn:disabled,
.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.icon-btn:disabled:hover {
  background: transparent;
  color: var(--muted);
}
.watt-edit {
  position: relative;
}
.add-form .watt-edit .cb-input {
  padding-right: 38px;
}
.split-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--ink-soft);
}
.add-form .split-toggle {
  margin-top: 0;
}
.split-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* segments */
.segments {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.seg-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
}
.seg-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
}
.seg-field .text-input {
  padding: 9px 10px;
  font-size: 14px;
}
.seg-remove {
  height: 38px;
}
.seg-note {
  font-size: 12px;
  color: var(--primary);
  background: var(--primary-50);
  padding: 6px 10px;
  border-radius: 8px;
}

/* empty state */
.empty {
  text-align: center;
  padding: 26px 16px;
  color: var(--muted);
}
.empty-icon {
  font-size: 34px;
  margin-bottom: 6px;
}
.empty-title {
  font-weight: 700;
  color: var(--ink-soft);
}
.empty-hint {
  font-size: 13.5px;
  margin-top: 2px;
}

/* ---------- results ---------- */
.result-panel {
  border-top: 4px solid transparent;
  border-image: var(--grad) 1;
}
.total-card {
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.total-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.total-value {
  font-size: 46px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 2px 0;
}
.total-unit {
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 600;
}
.result-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}
.result-actions .btn {
  flex: 1; /* PDF expands to full width when Save is hidden */
}
.sub-title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
}
.muted {
  color: var(--muted);
  font-size: 14px;
}

.breakdown {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bd-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.bd-main {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14.5px;
}
.bd-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.bd-watts {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}
.bd-kwh {
  font-weight: 700;
  color: var(--primary);
  flex: none;
}
.bd-bar {
  height: 8px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.bd-bar span {
  display: block;
  height: 100%;
  background: var(--grad);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.bd-details {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.4;
}
.bd-meta {
  font-size: 12px;
  color: var(--muted);
}
.bd-hours {
  font-size: 12px;
  color: var(--ink-soft);
}

.formula {
  margin-top: 16px;
  border-top: 1px dashed var(--line-strong);
  padding-top: 12px;
}
.formula summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-soft);
}
.formula-body {
  margin-top: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fline {
  background: var(--surface-2);
  padding: 7px 10px;
  border-radius: 8px;
  overflow-x: auto;
  white-space: nowrap;
}
.ftotal {
  background: var(--accent-soft);
}
.fline.fsub {
  color: var(--muted);
  padding-left: 16px;
}

/* ---------- summary table (PDF preview) ---------- */
.summary {
  margin-top: 18px;
  border-top: 1px dashed var(--line-strong);
  padding-top: 14px;
}
.summary-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.summary-head .sub-title {
  margin: 0;
}
.summary-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.summary-hint {
  font-size: 12.5px;
}
.summary-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 10px;
  padding: 7px 11px;
  background: var(--primary-50);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary-600);
}
.summary-meta-item {
  white-space: nowrap;
}
.summary-note-row td {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  padding: 2px 12px 8px !important;
  border-bottom: 1px solid var(--line) !important;
}
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 340px;
}
.summary-table th,
.summary-table td {
  padding: 9px 12px;
  text-align: right;
  white-space: nowrap;
}
.summary-table th:first-child,
.summary-table td:first-child {
  text-align: left;
  white-space: normal;
}
.summary-table thead th {
  background: var(--primary-50);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 2px solid #99f6e4;
}
.summary-table tbody td {
  border-bottom: 1px solid var(--line);
}
.summary-table tbody tr:last-child td {
  border-bottom: 0;
}
.summary-table tfoot td {
  background: var(--surface-2);
  font-weight: 700;
  border-top: 2px solid var(--line-strong);
}

/* ---------- history ---------- */
.history {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--surface-2);
}
.hist-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.hist-title {
  font-weight: 600;
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hist-when {
  font-size: 12px;
  color: var(--muted);
}
.hist-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

/* ---------- FAQ ---------- */
.faq-section {
  padding-block: 8px 36px;
}
.faq-heading {
  font-size: 20px;
  font-weight: 800;
  margin: 0 0 16px;
}
.faq {
  display: grid;
  gap: 10px;
}
@media (min-width: 760px) {
  .faq {
    grid-template-columns: 1fr 1fr;
  }
}
.faq-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.faq-item summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
}
.faq-item[open] summary {
  color: var(--primary);
  margin-bottom: 8px;
}
.faq-a {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.6;
}
.faq-a b {
  color: var(--ink);
}

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding-block: 18px;
  margin-bottom: env(safe-area-inset-bottom);
}
.site-footer .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}
.site-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

/* ---------- mobile sticky total ---------- */
.mobile-total {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 35;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--primary);
  color: #fff;
  padding: 13px 20px;
  border-radius: 16px;
  box-shadow: 0 8px 28px rgba(15, 118, 110, 0.4);
  font-size: 15px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s, box-shadow 0.15s;
}
.mobile-total:active {
  transform: scale(0.97);
  box-shadow: 0 4px 14px rgba(15, 118, 110, 0.35);
}
.mobile-total b {
  font-size: 20px;
}
.mt-label {
  opacity: 0.85;
  font-size: 13px;
}
.mt-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mt-arrow {
  font-size: 16px;
  opacity: 0.7;
  animation: mt-bounce 1.6s ease-in-out infinite;
}
@keyframes mt-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}
@media (max-width: 919px) {
  .mobile-total.show {
    display: flex;
  }
}

/* ---------- scroll to top ---------- */
.to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 45;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(15, 118, 110, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}
.to-top:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(15, 118, 110, 0.42);
}
.to-top:active {
  transform: scale(0.94);
}
.to-top.show {
  display: flex;
}
@media (max-width: 919px) {
  /* clear the mobile sticky-total bar */
  .to-top {
    bottom: 88px;
  }
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  z-index: 60;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  padding: 8px 18px;
  border-radius: 20px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- custom confirm dialog ---------- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.confirm-card {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
  padding: 28px 28px 22px;
  max-width: 380px;
  width: 100%;
  animation: cardUp 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes cardUp {
  from { transform: scale(0.9) translateY(10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.confirm-msg {
  margin: 0 0 22px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
}
.confirm-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
}
.btn-danger:hover {
  background: #b91c1c;
}

/* ---------- animations ---------- */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.shake .cb-input,
.shake.text-input {
  animation: shake 0.3s;
  border-color: var(--danger) !important;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
