@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root{
  --blue-brand: #0294f9;
  --blue-deep: #0b6fb8;
  --blue-band: #7fb6da;
  --blue-band-soft: #eaf3fa;
  --bg-app: #f2f7fb;
  --surface: #ffffff;
  --ink: #1d2b36;
  --ink-soft: #5b6b76;
  --ink-faint: #93a3ad;
  --border: #dfe9f0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20,50,70,.04), 0 6px 20px rgba(20,50,70,.06);
}

*{ box-sizing: border-box; }

html,body{
  margin:0; padding:0;
  background: var(--bg-app);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

h1,h2,h3,.brand-font{
  font-family: 'Poppins', 'Inter', sans-serif;
}

.app-shell{
  max-width: 1400px;
  margin: 0 auto;
  padding: 22px 22px 60px;
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar .brand{
  display:flex; align-items:center; gap:10px;
}
.topbar .brand img{ height: 38px; width:38px; }
.topbar h1{
  font-size: 19px;
  margin:0;
  color: var(--blue-deep);
  font-weight:700;
}
.topbar .sub{
  font-size: 12.5px;
  color: var(--ink-faint);
  margin-top: 2px;
}

.history-toggle{
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--blue-deep);
  font-weight:600;
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 999px;
  cursor:pointer;
  transition: .15s;
}
.history-toggle:hover{ background: var(--blue-band-soft); }

.layout{
  display:grid;
  grid-template-columns: minmax(360px, 480px) 1fr;
  gap: 22px;
  align-items:start;
}
.layout > div{ min-width: 0; }
@media screen and (max-width: 980px){
  .layout{ grid-template-columns: 1fr; }
}

@media screen and (max-width: 640px){
  .app-shell{ padding: 14px 12px 40px; }
  .topbar{ margin-bottom: 14px; }
  .topbar .brand img{ height: 30px; width: 30px; }
  .topbar h1{ font-size: 16px; }
  .topbar .sub{ font-size: 11px; }
  .tab-btn{ padding: 7px 12px; font-size: 12.5px; }
  .history-toggle{ padding: 7px 11px; font-size: 12.5px; }

  .card{ padding: 14px 14px 16px; }
  .row-2, .row-3{ grid-template-columns: 1fr; }
  .line-grid{ grid-template-columns: 1fr; }

  .preview-wrap{ position: static; }

  .history-panel{ width: 88vw; right: -100vw; }
  .history-panel.open{ right: 0; }

  .settings-row{ flex-wrap: wrap; }
  .settings-row input[type=text]{ min-width: 100%; }
  .settings-row-property .sp-label{ min-width: 100%; }
  #settingsNewClient{ min-width: 0; }
}

/* The invoice preview itself is never given a separate "mobile layout" —
   instead app.js scales it down as one piece (via the zoom property) to
   fit whatever width is available, so what she sees on a phone is a true
   miniature of the exact same layout that gets printed/exported, just
   smaller — never a differently-arranged version. See fitInvoicePreview()
   in app.js. */
#invoicePreview{ transform-origin: top left; }

.card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 20px 22px;
}

.card + .card{ margin-top: 18px; }

.card h2{
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--blue-deep);
  margin: 0 0 14px;
  font-weight:700;
}

label{
  display:block;
  font-size: 12.5px;
  font-weight:600;
  color: var(--ink-soft);
  margin: 12px 0 5px;
}
label:first-child{ margin-top:0; }
label .opt{
  font-weight:400;
  color: var(--ink-faint);
  text-transform: none;
  letter-spacing:0;
}

input[type=text], input[type=number], input[type=date], select, textarea{
  width:100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 16px; /* keep at 16px+ — anything smaller triggers automatic zoom-in on tap in mobile Safari/Chrome */
  color: var(--ink);
  background: #fbfdfe;
  transition: border-color .15s, box-shadow .15s;
}
textarea{ resize: vertical; min-height: 56px; }
input:focus, select:focus, textarea:focus{
  outline: none;
  border-color: var(--blue-brand);
  box-shadow: 0 0 0 3px rgba(2,148,249,.12);
  background: #fff;
}

.row-2{ display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3{ display:grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.pill-toggle{
  display:inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow:hidden;
}
.pill-toggle button{
  border:none; background:#fbfdfe; color: var(--ink-soft);
  padding: 7px 14px; font-size: 12.5px; font-weight:600; cursor:pointer;
  font-family: 'Inter', sans-serif;
}
.pill-toggle button.active{
  background: var(--blue-brand); color:#fff;
}

.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  border:none; cursor:pointer;
  padding: 11px 18px;
  border-radius: 999px;
  font-family:'Inter', sans-serif;
  font-weight:600;
  font-size: 14px;
  transition: transform .1s, box-shadow .15s, background .15s;
}
.btn:active{ transform: translateY(1px); }
.btn-primary{ background: var(--blue-brand); color:#fff; box-shadow: 0 6px 16px rgba(2,148,249,.28); }
.btn-primary:hover{ background: var(--blue-deep); }
.btn-ghost{ background:#fff; color: var(--blue-deep); border:1px solid var(--border); }
.btn-ghost:hover{ background: var(--blue-band-soft); }
.btn-text{ background:none; color: var(--ink-faint); padding: 4px 6px; font-size:12.5px; }
.btn-text:hover{ color:#c0392b; }
.btn[disabled]{ opacity:.5; cursor:not-allowed; box-shadow:none; }
.btn-block{ width:100%; }

.actions-row{ display:flex; gap:10px; margin-top:16px; flex-wrap:wrap; }

/* Line items */
.lines{ display:flex; flex-direction:column; gap:10px; margin-top: 8px;}
.line-item{
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 12px 8px;
  background: #fbfdfe;
  position:relative;
}
.line-item .line-head{
  display:flex; justify-content:space-between; align-items:center; margin-bottom:4px;
}
.line-item .line-index{
  font-size:11.5px; font-weight:700; color: var(--blue-brand); letter-spacing:.03em;
}
.line-grid{ display:grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.line-grid .full{ grid-column: 1 / -1; }
.line-total-display{
  margin-top:8px; text-align:right; font-size:13px; color: var(--ink-soft);
}
.line-total-display b{ color: var(--ink); font-size:14.5px; }

.add-line-btn{
  border: 1.5px dashed var(--blue-band);
  background: var(--blue-band-soft);
  color: var(--blue-deep);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-weight:600; font-size:13.5px;
  cursor:pointer; width:100%; margin-top:10px;
}
.add-line-btn:hover{ background:#dcedf8; }

.grand-total{
  display:flex; justify-content:space-between; align-items:baseline;
  margin-top:16px; padding-top:14px; border-top:1px dashed var(--border);
}
.grand-total .label{ font-weight:600; color: var(--ink-soft); font-size:13.5px; }
.grand-total .value{ font-size:24px; font-weight:700; color: var(--blue-deep); font-family:'Poppins',sans-serif; }

.hint{ font-size:12px; color: var(--ink-faint); margin-top:4px; }
.error-msg{
  background:#fdeceb; color:#b23b2f; border:1px solid #f3c8c3;
  padding:9px 12px; border-radius: var(--radius-sm); font-size:13px; margin-top:10px;
}
.success-msg{
  background:#eaf8ee; color:#2a7a45; border:1px solid #c3ecce;
  padding:9px 12px; border-radius: var(--radius-sm); font-size:13px; margin-top:10px;
}

/* ---------- INVOICE PREVIEW ---------- */
.preview-wrap{ position: sticky; top: 20px; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.preview-toolbar{
  display:flex; justify-content:flex-end; gap:10px; margin-bottom: 14px;
}

.invoice{
  background:#fff;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 46px 50px 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.invoice-logo-row{ margin-bottom: 18px; }
.invoice-logo-row img{ height: 90px; display:block; }

.invoice-issued-row{
  display:flex; justify-content:space-between; align-items:flex-start; gap:20px; margin-bottom: 26px;
}
.invoice-issued-row .meta{ text-align:right; white-space:nowrap; }
.invoice-issued-row .meta .num{ font-size:14px; font-weight:700; color:#111; }
.invoice-issued-row .meta .num span{ font-weight:400; }
.invoice-issued-row .meta .date{ font-size:14px; color:#111; margin-top:4px; }
.invoice-issued-row .meta .date span{ font-weight:700; }

.invoice-issued .label{ font-weight:700; font-size:13.5px; color:#111; letter-spacing:.02em; }
.invoice-issued .addr{ font-size:13.5px; color:#222; line-height:1.6; margin-top:2px; white-space:pre-line; }

table.invoice-table{ width:100%; border-collapse:collapse; }
table.invoice-table thead th{
  background: var(--blue-band);
  color:#fff;
  text-align:left;
  font-size: 11.5px;
  letter-spacing:.04em;
  text-transform:uppercase;
  padding: 10px 12px;
  font-weight:700;
}
table.invoice-table thead th.num, table.invoice-table td.num{ text-align:right; }
table.invoice-table tbody td{
  padding: 10px 12px;
  font-size:13px;
  color:#222;
  border-bottom: 1px solid #f0f4f7;
  vertical-align: top;
  white-space: pre-line;
}
table.invoice-table tbody tr:last-child td{ border-bottom:none; }

.invoice-total-row{
  display:flex; justify-content:space-between; align-items:center;
  background: var(--blue-band);
  color:#fff; margin-top: 16px;
  padding: 12px 16px; border-radius: 6px;
}
.invoice-total-row .t-label{ font-weight:700; font-size:12px; letter-spacing:.05em; text-transform:uppercase; }
.invoice-total-row .t-value{ font-weight:700; font-size:16px; }

.invoice-foot{
  display:flex; justify-content:space-between; align-items:flex-end;
  margin-top: 60px;
}
.invoice-foot .bank .label{ font-weight:700; font-size:12.5px; margin-bottom:5px; }
.invoice-foot .bank div{ font-size:12.5px; color:#333; line-height:1.55; }
.invoice-foot .thanks{ text-align:right; }
.invoice-foot .thanks .label{ font-weight:700; font-size:12.5px; margin-bottom:6px; }
.invoice-foot .thanks img{ height:56px; }

.tab-nav{
  display:inline-flex; background: var(--surface); border:1px solid var(--border);
  border-radius: 999px; padding:3px;
}
.tab-btn{
  border:none; background:none; padding: 8px 16px; border-radius:999px;
  font-family:'Inter',sans-serif; font-weight:600; font-size:13px; color:var(--ink-soft); cursor:pointer;
}
.tab-btn.active{ background: var(--blue-brand); color:#fff; }

.editing-banner{
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  background:#fdf3e3; border:1px solid #f0d9a8; color:#8a6110;
  padding:9px 12px; border-radius: var(--radius-sm); font-size:12.5px; margin-top:12px;
}

.settings-list{ margin-top:14px; display:flex; flex-direction:column; gap:8px; max-height:480px; overflow-y:auto; }
.settings-row{ display:flex; align-items:center; gap:8px; }
.settings-row input[type=text]{ flex:1; }
.settings-row-property{ flex-direction:column; align-items:stretch; border:1px solid var(--border); border-radius:var(--radius-sm); padding:10px; }
.settings-row-property .sp-top{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.settings-row-property .sp-label{ flex:1; min-width:140px; }
.settings-row-property .sp-rate-summary{ font-size:12.5px; color:var(--ink-soft); white-space:nowrap; }
.settings-row-property .sp-rate-fields{ margin-top:10px; padding-top:10px; border-top:1px dashed var(--border); }
.settings-row-property .sp-rate{ max-width:140px; }

.hi-actions{ display:flex; gap:12px; margin-top:6px; }
.hi-actions .btn-text{ padding:2px 0; }
.hi-actions .hi-delete:hover{ color:#c0392b; }
.hi-actions .hi-edit:hover{ color: var(--blue-deep); }
.combo-wrap{ position:relative; }
.combo-wrap input{ width:100%; }
.combo-list{
  display:none;
  position:absolute;
  top: calc(100% + 4px);
  left:0; right:0;
  background:#fff;
  border:1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px rgba(20,50,70,.14);
  max-height: 320px;
  overflow-y:auto;
  -webkit-overflow-scrolling: touch;
  z-index: 30;
  padding: 4px;
}
.combo-option{
  padding: 9px 10px;
  border-radius: 6px;
  cursor:pointer;
  font-size: 13.5px;
  color: var(--ink);
}
.combo-option .co-sub{
  font-size: 11.5px;
  color: var(--ink-faint);
  margin-top: 1px;
}
.combo-option:hover, .combo-option.highlighted{
  background: var(--blue-band-soft);
}
.combo-option.combo-add-new{
  color: var(--blue-deep);
  font-weight:600;
  border-top: 1px dashed var(--border);
  margin-top: 2px;
  padding-top: 10px;
}
.combo-option.combo-empty{
  color: var(--ink-faint);
  cursor:default;
}
.combo-tag{
  display:inline-block;
  font-size: 10px;
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:.03em;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left:6px;
  background: var(--blue-band-soft);
  color: var(--blue-deep);
}
.combo-tag.hourly{ background:#fdf0e0; color:#a0651a; }

/* History drawer */
.history-panel{
  position: fixed; top:0; right:-420px; width: 400px; height:100vh;
  background:#fff; box-shadow: -8px 0 30px rgba(20,50,70,.15);
  transition: right .25s ease; z-index: 50; padding: 22px; overflow-y:auto;
}
.history-panel.open{ right:0; }
.history-panel h2{ font-size:15px; color:var(--blue-deep); margin-bottom:14px; }
.history-item{
  border:1px solid var(--border); border-radius: var(--radius-sm);
  padding:10px 12px; margin-bottom:8px; cursor:pointer;
}
.history-item:hover{ background: var(--blue-band-soft); }
.history-item .hi-top{ display:flex; justify-content:space-between; font-size:13px; font-weight:600; }
.history-item .hi-sub{ font-size:12px; color:var(--ink-faint); margin-top:2px; }
.scrim{
  position:fixed; inset:0; background: rgba(15,30,45,.3); z-index:40;
  opacity:0; pointer-events:none; transition:opacity .2s;
}
.scrim.open{ opacity:1; pointer-events:auto; }

@media print{
  @page{ size: A4 portrait; margin: 1in; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }
  html, body, .app-shell{ background: #fff !important; }
  .topbar, .history-panel, .scrim, .preview-toolbar{ display:none !important; }
  .app-shell{ padding:0 !important; max-width:none !important; margin:0 !important; }
  .layout{ display:block !important; }
  .layout > div:first-child{ display:none !important; }
  .preview-wrap{ position:static !important; }
  #invoicePreview{
    box-shadow:none !important; border:none !important; margin:0 !important;
    border-radius:0 !important; width:100% !important; max-width:100% !important;
    padding:0 !important;
  }
}
