* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.45 -apple-system, "Segoe UI", Calibri, Arial, sans-serif; color: #1d2433; background: #f4f6fa; }
nav { display: flex; gap: 2px; align-items: center; background: #1f3a68; padding: 0 12px; flex-wrap: wrap; position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 6px rgba(0,0,0,.18); }
html { scroll-padding-top: calc(var(--nav-h, 44px) + 8px); }
nav a, nav button.link { color: #dfe7f5; text-decoration: none; padding: 12px 6px; font-size: 13px; white-space: nowrap; }
nav a.on { color: #fff; box-shadow: inset 0 -3px 0 #8eaadb; }
nav a:hover, nav button.link:hover { color: #fff; }
nav a.brand { padding: 5px 0; margin-right: 6px; display: flex; align-items: center; }
nav a.brand img { height: 30px; display: block; background: #fff; border-radius: 6px; padding: 3px 8px; }
nav .spacer { flex: 1; }
main { padding: 20px 24px 60px; max-width: 1500px; margin: 0 auto; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 17px; margin: 28px 0 10px; }
a { color: #2f5597; }
table { border-collapse: collapse; width: 100%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
th, td { padding: 7px 9px; border-bottom: 1px solid #e6e9ef; text-align: left; vertical-align: top; }
th { background: #eef2f8; font-weight: 600; font-size: 13px; position: sticky; top: var(--nav-h, 44px); z-index: 5; }
td.num, th.num { text-align: right; white-space: nowrap; }
.muted td, tr.muted td { color: #8a93a3; }
.card { background: #fff; padding: 14px 16px; border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.06); margin-bottom: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { background: #fff; padding: 10px 14px; border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.06); min-width: 140px; }
.stat b { display: block; font-size: 20px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: #e6e9ef; white-space: nowrap; }
.badge.test { background: #ffcf33; color: #000; }
.s-READY { background: #d9f2df; color: #1d6b32; }
.s-INVOICED { background: #dbe7fb; color: #1f3a68; }
.s-NEEDS_AMOUNT, .s-NO_USAGE_REPORT, .s-MISSING_ADDRESS { background: #ffe1e1; color: #a12020; }
.s-ZERO_USAGE, .s-EXCLUDED { background: #eceff3; color: #6b7280; }
.st-OUTSTANDING { background: #ffff00; color: #000; }
.st-PAID { background: transparent; border: 1px solid #ccd; }
.st-PARTIAL { background: #ffe58a; color: #000; }
.st-CANCELLED { background: #eee; color: #888; }
.warn { color: #a15c00; font-size: 12px; display: block; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; white-space: pre-line; }
.flash.ok { background: #d9f2df; } .flash.err { background: #ffe1e1; } .flash.info { background: #e3ecfb; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=month], input[type=search], select, textarea {
  padding: 6px 8px; border: 1px solid #c4cad6; border-radius: 4px; font: inherit; background: #fff; }
input[type=number] { width: 120px; text-align: right; }
textarea { width: 100%; min-height: 70px; }
button, .btn { padding: 7px 14px; border: 0; border-radius: 4px; background: #2f5597; color: #fff; font: inherit; cursor: pointer; text-decoration: none; display: inline-block; }
button.secondary, .btn.secondary { background: #e6e9ef; color: #1d2433; }
button.danger { background: #b42318; }
button.small { padding: 3px 9px; font-size: 13px; }
button.link { background: none; padding: 0; color: #2f5597; }
button:disabled { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; margin: 0; }
/* sign-in page */
body.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #1f3a68 0%, #2f5597 55%, #3f8fb7 100%); padding: 20px; }
.login-box { background: #fff; width: 100%; max-width: 400px; padding: 36px 32px 28px; margin: 0; border-radius: 14px;
  box-shadow: 0 18px 50px rgba(10, 25, 60, .35); text-align: center; }
.login-logo { width: 240px; max-width: 80%; height: auto; margin: 0 auto 14px; display: block; }
.login-title { font-size: 15px; font-weight: 700; letter-spacing: .18em; color: #1f3a68; margin-bottom: 24px; }
.login-form { text-align: left; }
.login-form label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: #3a4558; }
.login-form input { width: 100%; margin-top: 5px; padding: 11px 12px; font-size: 16px; border-radius: 8px; }
.login-form button { width: 100%; padding: 12px; font-size: 16px; border-radius: 8px; margin-top: 6px; }
.login-box .flash { text-align: left; }
.login-test { margin-top: 18px; display: inline-block; background: #ffd23f; color: #3a2d00; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 10px; }
label.f { display: block; margin: 0 0 10px; font-weight: 600; font-size: 13px; }
label.f input[type=text], label.f input[type=month], label.f textarea, label.f select { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.small { font-size: 12px; color: #6b7280; }
button.small:not(.secondary):not(.link) { color: #fff; }
.nowrap { white-space: nowrap; }
details > summary { cursor: pointer; color: #2f5597; }

/* Row saved in place (no page reload) */
.just-saved td { background: #d9f2df; transition: background .3s; }

/* "Record payment": horizontal panel under the invoice row */
tr.pay-row > td { background: #f4f7fc; border-bottom: 2px solid #2f5597; padding: 10px 12px 12px; }
.pay-title { margin-bottom: 8px; }
.pay-fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 18px; margin-bottom: 6px; }
.pay-fields > label { font-size: 13px; font-weight: 600; display: flex; flex-direction: column; gap: 4px; }
.pay-fields > label input { font-weight: 400; }
.pay-fields .pay-note input { width: 260px; }
.pay-fields .pay-check { flex-direction: row; align-items: center; font-weight: 400; }
.pay-kind { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.pay-buttons { display: flex; gap: 6px; }
button[aria-expanded="true"] { background: #1d3b70; color: #fff; }
.pay-preview { font-weight: 600; color: #1d3b70; margin: 2px 0 4px; min-height: 1em; }
td.num .small { display: block; }
/* prepaid (user-based) customers on the monthly page */
tr.pp-row > td { background: #f7f9fd; border-bottom: 2px solid #c9d6ee; }
.pp-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 16px; margin: 6px 0 10px; }
.pp-form label { display: flex; flex-direction: column; font-size: 13px; font-weight: 600; gap: 3px; }
.pp-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.pp-box { background: #fff; border: 1px solid #dde4f0; border-radius: 6px; padding: 8px 12px; font-size: 13px; min-width: 240px; }
.pp-box > b:first-child { display: block; margin-bottom: 4px; }
.pp-sum { font-size: 17px; font-weight: 700; color: #1d3b70; margin-top: 4px; }
.pay-preview.bad { color: #b42318; }
.pay-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
/* payment column: compact buttons; details open in the full-width row below */
.pay-cell { display: flex; flex-wrap: wrap; gap: 4px; min-width: 120px; }
.pay-cell button { white-space: nowrap; }
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.edit-grid > form { background: #fff; border: 1px solid #dde4f0; border-radius: 6px; padding: 10px 12px; }
@media (max-width: 820px) { .edit-grid { grid-template-columns: 1fr; } }
table.mini { width: auto; min-width: 60%; box-shadow: none; font-size: 13px; }
table.mini th, table.mini td { padding: 4px 10px; background: #fff; }
table.mini th { position: static; background: #eef2f8; }
table.mini td.num .small { display: block; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 240px; }
.pay-actions form.inline { display: inline; }
/* new customer / billing line form */
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
fieldset.f { border: 1px solid #dde4f0; border-radius: 6px; padding: 8px 12px 10px; margin: 0 0 12px; }
fieldset.f legend { font-weight: 600; font-size: 13px; padding: 0 4px; }
fieldset.months label.month { display: inline-block; min-width: 92px; font-weight: 400; font-size: 13px; margin: 2px 6px 2px 0; }
fieldset.f > label { display: block; font-weight: 400; margin: 3px 0; }
.prepaid-fields { margin-top: 8px; }
.prepaid-fields .rate { display: flex; gap: 6px; margin-bottom: 6px; }
.prepaid-fields .rate input:first-child { width: 55%; }
.prepaid-fields .rate input:last-child { width: 45%; }
/* user types: checkbox + yearly rate */
.ut-list { display: flex; flex-wrap: wrap; gap: 6px 10px; margin: 6px 0 4px; }
.ut-list label.ut { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #dde4f0; border-radius: 6px; padding: 4px 8px; background: #fff; font-weight: 400; font-size: 13px; }
.ut-list label.ut input[type=text] { width: 90px; padding: 3px 6px; }
.ut-list label.ut-new { border-style: dashed; }
.ut-list label.ut-new input[name=new_type] { width: 130px; }

/* guide page */
.guide h2 { border-bottom: 2px solid #c9d6ee; padding-bottom: 4px; }
.guide h3 { font-size: 15px; margin: 18px 0 6px; }
.guide p, .guide li { line-height: 1.55; max-width: 980px; }
.guide .toc { columns: 2; max-width: 900px; }
.guide pre.mail { background: #f7f9fd; border: 1px solid #dde4f0; border-radius: 6px; padding: 12px 14px; white-space: pre-wrap; font: 13px/1.5 Calibri, Arial, sans-serif; max-width: 900px; }
.guide div.mail { background: #f7f9fd; border: 1px solid #dde4f0; border-radius: 6px; padding: 12px 14px; font: 14px/1.4 Calibri, Arial, sans-serif; color: #000; max-width: 900px; }
.guide div.mail .mail-footer { margin: 18px 0 0; font-size: 12px; color: #555; border-top: 1px solid #ddd; padding-top: 10px; }
.guide .subject { font-weight: 700; margin: 4px 0; }
.guide table { max-width: 1000px; }

/* phones and small tablets */
@media (max-width: 820px) {
  nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0 8px; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav a, nav button.link { padding: 14px 8px; }
  nav .spacer { flex: 0 0 8px; }
  main { padding: 14px 10px 50px; }
  h1 { font-size: 19px; }
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th { position: static; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .stat { min-width: calc(50% - 6px); flex: 1 1 calc(50% - 6px); }
  .row { flex-wrap: wrap; }
  .pay-fields > label, .pp-form label { flex: 1 1 100%; }
  .pay-fields .pay-note input, .pay-fields input, .pp-form input, .pp-form select { width: 100%; }
  .pp-box { min-width: 0; flex: 1 1 100%; }
  input, select, textarea { font-size: 16px; } /* no auto-zoom on iPhone */
  .guide .toc { columns: 1; }
}

/* short notice after a background save (e.g. file upload); fixed, so the page does not move */
.notice { position: fixed; right: 16px; bottom: 16px; max-width: 460px; z-index: 50; padding: 10px 14px; border-radius: 6px;
  background: #d9f2df; box-shadow: 0 2px 10px rgba(0,0,0,.2); white-space: pre-line; font-size: 13px; cursor: pointer; }
.notice.warn { background: #fff3cd; border: 1px solid #e0b100; }

/* a row jumped to (#item-12 after a save): shown below the fixed menu and the sticky table header, never hidden under them */
tbody[id], tr[id] { scroll-margin-top: calc(var(--nav-h, 56px) + 52px); }
