*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        rgb(200, 218, 240);
  --text:      rgb(30, 40, 55);
  --muted:     rgb(85, 105, 130);
  --heading:   rgb(30, 65, 110);
  --primary:   rgb(120, 60, 60);
  --primary-h: rgb(90, 45, 45);
  --danger:    rgb(160, 40, 40);
  --danger-h:  rgb(120, 25, 25);
  --border:    rgb(185, 210, 235);
  --card-bg:   rgb(248, 252, 255);
  --radius:    8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 60px;
}

/* ── PAGE HEADER ── */
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.back-link {
  color: var(--primary);
  text-decoration: none;
  font-family: inherit;
  font-size: 1rem;
  padding: 8px 18px;
  border: 2px solid var(--primary);
  border-radius: 8px;
  white-space: nowrap;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.back-link:hover { background: var(--primary); color: #fff; text-decoration: none; }

.page-header h1 {
  flex: 1;
  font-size: 1.9rem;
  font-weight: normal;
  color: var(--heading);
  text-align: center;
}

.btn-add-header {
  background: var(--primary);
  color: #fff;
  border: none;
  font-family: inherit;
  font-size: 1rem;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.btn-add-header:hover { background: var(--primary-h); }

.btn-add-section {
  background: #eaf2ea;
  color: #3a6a3a;
  border: 1px solid #b2d4b2;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: normal;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 36px;
  width: 10rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.btn-add-section:hover { background: #3a6a3a; color: #fff; }
.btn-add-header:hover { background: var(--primary-h); }

/* ── MAIN ── */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px 32px;
}

.freq-section {
  margin-bottom: 28px;
}

.section-heading-group {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.section-heading-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 8px 0 6px;
  border-bottom: 2px solid var(--border);
}

.list-section-heading {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--heading);
}

.section-subtotal {
  font-size: 0.95rem;
  color: var(--muted);
  font-style: italic;
}

.bill-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-msg {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  padding: 32px 0;
  font-size: 1.05rem;
}

/* ── BILL CARD ── */
.Bill_Card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px 10px 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: box-shadow 0.15s;
  overflow: hidden;
}
.Bill_Card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.10); }
.Bill_Card:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.Bill_Card.sortable-ghost { opacity: 0.35; }

.Drag_Handle {
  flex-shrink: 0;
  align-self: stretch;
  width: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8aaac8;
  font-size: 1.3rem;
  cursor: grab;
  touch-action: none;
  user-select: none;
  background: #ddeaf7;
  border-right: 1px solid var(--border);
  margin-right: 4px;
  margin-top: -10px;
  margin-bottom: -10px;
}
.Drag_Handle:active { cursor: grabbing; }

.Bill_Info {
  flex: 1;
  min-width: 0;
}

.Bill_Service {
  display: block;
  font-size: 1.15rem;
  font-weight: bold;
  color: var(--text);
  line-height: 1.3;
}

.Bill_Primary {
  display: block;
  font-size: 1.15rem;
  font-weight: bold;
  color: var(--text);
  line-height: 1.3;
}

.Bill_Primary a {
  color: var(--text);
  text-decoration: none;
}
.Bill_Primary a:hover { color: var(--primary); text-decoration: underline; }

.Bill_Secondary {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 2px;
}

.Bill_Details {
  display: block;
  font-size: 0.95rem;
  color: var(--muted);
  margin-top: 3px;
}

.Bill_Details a {
  color: var(--primary);
  text-decoration: none;
}
.Bill_Details a:hover { text-decoration: underline; }

.Bill_Amount {
  flex-shrink: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  padding-right: 4px;
  margin-left: 8px;
}

/* ── FIXED / VARIABLE BADGE ── */
.fixed-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  font-family: inherit;
  min-height: 36px;
  transition: background 0.15s, color 0.15s;
}
.fixed-badge--fixed    { background: #e0f0e8; color: #2a6a42; border-color: #b0d8be; }
.fixed-badge--fixed:hover    { background: #2a6a42; color: #fff; }
.fixed-badge--variable { background: #fdf0d8; color: #7a5a1a; border-color: #e0c880; }
.fixed-badge--variable:hover { background: #7a5a1a; color: #fff; }

.bill-actions {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
}

.btn-edit,
.btn-delete {
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
}
.btn-edit   { background: #fdf8e1; color: #7a6a1a; border: 1px solid #e0d080; }
.btn-edit:hover   { background: #7a6a1a; color: #fff; }
.btn-delete { background: #f5e8e8; color: var(--danger); border: 1px solid #e0bfbf; padding: 10px 12px; }
.btn-delete:hover { background: var(--danger); color: #fff; }

/* ── MONTHLY TOTAL BANNER ── */
.monthly-total-banner {
  background: rgb(30, 75, 130);
  color: #fff;
  border-radius: var(--radius);
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  font-size: 1.05rem;
}
.monthly-total-banner strong {
  font-size: 1.3rem;
}

/* ── MODAL OVERLAY ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.50);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 16px 40px;
  overflow-y: auto;
}
.modal-overlay[hidden] { display: none; }

/* ── EDIT MODAL ── */
.modal-box {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.20);
  margin: auto;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.4rem;
  font-weight: normal;
  color: var(--heading);
}

.modal-updated {
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 2px;
}

.btn-modal-close {
  background: none;
  border: none;
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
}
.btn-modal-close:hover { color: var(--text); background: #dae6f5; }

.modal-body {
  padding: 20px 24px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

/* ── FORM ── */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 1rem;
  margin-bottom: 6px;
  color: var(--text);
}

.req { color: var(--danger); margin-left: 2px; }

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="number"],
.form-group select {
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 44px;
}
.form-group input:focus,
.form-group select:focus {
  outline: 3px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

.input-prefix-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.input-prefix-wrap input {
  flex: 1;
  border: none !important;
  border-radius: 0 !important;
  outline: none !important;
  min-width: 0;
}
.input-prefix-wrap:focus-within {
  outline: 3px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}
.input-prefix {
  padding: 0 12px;
  font-size: 0.95rem;
  color: var(--text-muted, #888);
  white-space: nowrap;
  pointer-events: none;
  border-right: 1px solid var(--border);
  height: 44px;
  display: flex;
  align-items: center;
  background: var(--bg-soft, #ddeaf7);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 400px) {
  .form-row { grid-template-columns: 1fr; }
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
}

.btn-cancel {
  background: #dce8f5;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
}
.btn-cancel:hover { background: #bdd4ee; }

.btn-save {
  background: var(--primary);
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 28px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
}
.btn-save:hover { background: var(--primary-h); }

/* ── CONFIRM DIALOG ── */
.confirm-box {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 380px;
  padding: 32px 28px 28px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.20);
  margin: auto;
  text-align: center;
}

.confirm-box p {
  font-size: 1.15rem;
  line-height: 1.5;
  margin-bottom: 10px;
  color: var(--text);
}

.confirm-item-name { font-weight: bold; color: var(--heading); }

.confirm-sub {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 28px !important;
}

.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-danger {
  background: var(--danger);
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
}
.btn-danger:hover { background: var(--danger-h); }

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #2c2c2c;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.95rem;
  transition: transform 0.25s ease;
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* ── PRINT ── */
@media print {
  .page-header .back-link,
  .page-header .btn-add-header,
  .bill-actions,
  .Drag_Handle,
  #toast,
  .modal-overlay { display: none !important; }

  body { background: #fff; padding-bottom: 0; }
  .page-header { position: static; border-bottom: 2px solid #000; }
  .Bill_Card { box-shadow: none; cursor: default; break-inside: avoid; }
  .monthly-total-banner { background: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
