/* Camarata Billing Portal
   Accent colors are lifted from the main site theme (#009ed6 / #ffa808) so the
   portal reads as part of the practice rather than a bolted-on tool. */

:root {
  --blue-700: #0b6c92;
  --blue-600: #0a86b4;
  --blue-500: #009ed6;
  --blue-100: #e2f4fb;
  --blue-50:  #f2fafd;

  --amber-600: #b87400;
  --amber-500: #ffa808;
  --amber-100: #fff2d9;

  --green-700: #14683f;
  --green-100: #e2f5eb;
  --red-700:   #9b2226;
  --red-600:   #c2413f;
  --red-100:   #fdeaea;

  --ink:      #1b2430;
  --ink-soft: #55606e;
  --ink-mute: #7d8896;
  --line:     #e2e6ec;
  --line-soft:#eef1f5;
  --bg:       #f5f7fa;
  --card:     #ffffff;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(19, 32, 48, .06), 0 4px 14px rgba(19, 32, 48, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* No image may exceed its container, whatever width/height attributes it
   carries. Cheap insurance against a stale stylesheet blowing out a layout. */
img { max-width: 100%; height: auto; }

body {
  margin: 0;
  font: 15px/1.55 var(--font);
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: .95rem; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0 1.25rem; min-height: 58px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: .55rem; color: var(--ink); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; display: block; object-fit: contain; flex: none; }
.brand-text { font-size: .95rem; white-space: nowrap; }

.nav { display: flex; gap: .25rem; margin-right: auto; flex-wrap: wrap; }
.nav a {
  padding: .4rem .7rem; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-size: .9rem; font-weight: 500;
}
.nav a:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.nav a.is-active { background: var(--blue-100); color: var(--blue-700); }

.topbar-right { display: flex; align-items: center; gap: .6rem; }

.menu { position: relative; }
.menu > summary {
  list-style: none; cursor: pointer; padding: .4rem .7rem;
  border-radius: var(--radius-sm); font-size: .9rem; color: var(--ink-soft);
  border: 1px solid var(--line); background: var(--card);
  max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { background: var(--line-soft); }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + .4rem); min-width: 12rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .3rem; display: grid; gap: .1rem;
}
.menu-panel a, .menu-panel button {
  display: block; width: 100%; text-align: left; padding: .5rem .6rem;
  border-radius: var(--radius-sm); font-size: .9rem; color: var(--ink-soft);
  background: none; border: 0; cursor: pointer; font-family: inherit;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }

/* Phones: the bar becomes two rows -- brand plus actions on top, then the nav
   as a single horizontally scrollable strip. Wrapping the nav inside a
   fixed-height bar is what made the links spill over the banner. */
@media (max-width: 860px) {
  .topbar {
    flex-wrap: wrap;
    gap: .5rem;
    padding: .55rem .9rem;
  }
  .brand { order: 1; }
  .topbar-right { order: 2; margin-left: auto; }
  .nav {
    order: 3;
    width: 100%;
    margin-right: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; }
  .menu > summary { max-width: 8rem; }
}

@media (max-width: 420px) {
  /* The mark alone still identifies the app once space is tight. */
  .brand-text { display: none; }
}

/* ---------- Layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.foot { text-align: center; color: var(--ink-mute); font-size: .8rem; padding: 0 0 2rem; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem;
}
.page-head p { margin: .15rem 0 0; color: var(--ink-mute); font-size: .9rem; }
.welcome-line { color: var(--blue-600) !important; font-weight: 550; font-size: .95rem !important; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card + .card { margin-top: 1.25rem; }
.card-head {
  padding: .9rem 1.1rem; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-body { padding: 1.1rem; }
.card-body.tight { padding: .6rem 1.1rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) {
  .grid-2, .grid-3, .split { grid-template-columns: 1fr; }
}

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
@media (max-width: 820px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.stat-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-mute); font-weight: 600; }
.stat-value { font-size: 1.65rem; font-weight: 680; margin-top: .3rem; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-note { font-size: .82rem; color: var(--ink-mute); margin-top: .15rem; }
.stat.is-alert .stat-value { color: var(--red-700); }
.stat.is-good  .stat-value { color: var(--green-700); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
  text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-mute); font-weight: 650; padding: .6rem 1.1rem; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: .7rem 1.1rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--blue-50); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .shrink { width: 1%; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.row-link { color: var(--ink); font-weight: 600; }
.sub { color: var(--ink-mute); font-size: .82rem; }

.empty { padding: 2.5rem 1.1rem; text-align: center; color: var(--ink-mute); }
.empty p { margin: 0 0 .9rem; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: .2rem .5rem; border-radius: 999px;
  font-size: .74rem; font-weight: 650; letter-spacing: .01em; white-space: nowrap;
  background: var(--line-soft); color: var(--ink-soft);
}
.badge-draft          { background: var(--line-soft); color: var(--ink-soft); }
.badge-sent           { background: var(--blue-100);  color: var(--blue-700); }
.badge-partially_paid { background: var(--amber-100); color: var(--amber-600); }
.badge-paid           { background: var(--green-100); color: var(--green-700); }
.badge-overdue        { background: var(--red-100);   color: var(--red-700); }
.badge-canceled,
.badge-refunded       { background: var(--line-soft); color: var(--ink-mute); text-decoration: line-through; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  padding: .5rem .85rem; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-size: .875rem; font-weight: 550;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--line-soft); text-decoration: none; }
.btn-sm { padding: .35rem .65rem; font-size: .82rem; }
.btn-primary { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }
.btn-primary:hover { background: var(--blue-700); border-color: var(--blue-700); }
.btn-danger { color: var(--red-700); border-color: #f0d3d3; background: #fff; }
.btn-danger:hover { background: var(--red-100); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--line-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.field { margin-bottom: 1rem; }
.field > label, .label {
  display: block; font-size: .82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: .3rem;
}
.input, .select, .textarea {
  width: 100%; padding: .5rem .65rem; font: inherit; font-size: .9rem; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px var(--blue-100);
}
.textarea { min-height: 5rem; resize: vertical; }
.input.is-error, .select.is-error { border-color: var(--red-600); }
.hint { font-size: .8rem; color: var(--ink-mute); margin-top: .25rem; }
.error-text { font-size: .82rem; color: var(--red-700); margin-top: .25rem; }
.check { display: flex; align-items: center; gap: .45rem; font-size: .88rem; color: var(--ink-soft); }
.check input { width: 16px; height: 16px; accent-color: var(--blue-600); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 1rem; }
@media (max-width: 700px) { .form-row, .form-row-3 { grid-template-columns: 1fr; } }

.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.filters .field { margin: 0; }
.filters .input, .filters .select { min-width: 9rem; }

/* ---------- Flash + banner ---------- */
.flash {
  padding: .7rem .95rem; border-radius: var(--radius); margin-bottom: 1rem;
  font-size: .9rem; border: 1px solid transparent;
}
.flash-success { background: var(--green-100); border-color: #c6e8d6; color: var(--green-700); }
.flash-error   { background: var(--red-100);   border-color: #f3d2d2; color: var(--red-700); }
.flash-info    { background: var(--blue-100);  border-color: #c9e8f5; color: var(--blue-700); }

.banner {
  background: var(--amber-100); border-bottom: 1px solid #f3dfb5; color: var(--amber-600);
  padding: .6rem 1.25rem; font-size: .86rem; text-align: center;
}
.banner a { color: var(--amber-600); font-weight: 650; text-decoration: underline; }

/* ---------- Invoice builder ---------- */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th {
  text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-mute); font-weight: 650; padding: 0 .5rem .4rem;
}
.items-table td { padding: .25rem .5rem .25rem 0; vertical-align: top; }
.items-table td:last-child { padding-right: 0; }
.items-table .col-qty   { width: 90px; }
.items-table .col-price { width: 130px; }
.items-table .col-amt   { width: 110px; text-align: right; }
.items-table .col-del   { width: 40px; }
.item-row td { border-bottom: 1px solid var(--line-soft); padding-bottom: .6rem; padding-top: .6rem; }
.line-amount { font-variant-numeric: tabular-nums; font-weight: 600; padding-top: .55rem; display: block; text-align: right; }
.row-del {
  border: 0; background: none; color: var(--ink-mute); cursor: pointer;
  font-size: 1.1rem; line-height: 1; padding: .5rem .3rem; border-radius: var(--radius-sm);
}
.row-del:hover { color: var(--red-700); background: var(--red-100); }

.totals { margin-left: auto; width: min(320px, 100%); }
.totals-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .35rem 0; font-size: .9rem; }
.totals-row .input { width: 120px; text-align: right; }
.totals-grand {
  border-top: 2px solid var(--line); margin-top: .4rem; padding-top: .6rem;
  font-size: 1.15rem; font-weight: 680; font-variant-numeric: tabular-nums;
}

/* ---------- Invoice detail ---------- */
.money-big { font-size: 1.9rem; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.meta-list { display: grid; gap: .55rem; font-size: .88rem; }
.meta-list div { display: flex; justify-content: space-between; gap: 1rem; }
.meta-list dt, .meta-list .k { color: var(--ink-mute); }
.meta-list .v { font-weight: 550; text-align: right; }

.timeline { display: grid; gap: .7rem; font-size: .85rem; }
.timeline-item { display: grid; gap: .1rem; padding-left: .9rem; border-left: 2px solid var(--line); }
.timeline-when { color: var(--ink-mute); font-size: .78rem; }

.actions-stack { display: grid; gap: .5rem; }

.pill-note {
  background: var(--blue-50); border: 1px solid var(--blue-100); border-radius: var(--radius-sm);
  padding: .6rem .75rem; font-size: .85rem; color: var(--ink-soft);
}

.code {
  font-family: var(--mono); font-size: 1.05rem; background: var(--line-soft);
  padding: .35rem .55rem; border-radius: var(--radius-sm); user-select: all;
}

/* ---------- Pagination ---------- */
.pager { display: flex; gap: .4rem; align-items: center; justify-content: center; padding: 1rem; }
.pager span { color: var(--ink-mute); font-size: .85rem; }

/* ---------- Login ---------- */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1.5rem 1rem;
  background: linear-gradient(160deg, #eef5f9, #f7f9fb 60%);
}
/* On a tall phone, centring in 100vh strands the card halfway down the screen
   behind a band of empty gradient. Pin it near the top instead. */
@media (max-width: 640px), (max-height: 720px) {
  .auth-page { align-items: flex-start; padding-top: 1.25rem; }
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 10px 40px rgba(19, 32, 48, .09); padding: 1.75rem;
}
.auth-logo {
  display: block; width: 100%; max-width: 260px; height: auto;
  margin: 0 auto 1.5rem;
}
.auth-card h1 { font-size: 1.15rem; margin-bottom: 1.1rem; text-align: center; color: var(--ink-soft); }

/* ---------- Public pay page ---------- */
.pay-page { background: linear-gradient(180deg, #eef5f9, #f5f7fa 220px); }
.pay-wrap { max-width: 560px; margin: 0 auto; padding: 2rem 1rem 3rem; }
.pay-logo { display: block; width: 200px; max-width: 60%; height: auto; margin: 0 auto 1.5rem; }
.pay-foot {
  text-align: center; color: var(--ink-mute); font-size: .82rem; line-height: 1.6;
  margin-top: 1.5rem;
}
.btn-lg { padding: .8rem 1.1rem; font-size: 1rem; }

/* ---------- Print ---------- */
@media print {
  .topbar, .foot, .banner, .no-print { display: none !important; }
  body { background: #fff; }
  .wrap { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; }
}
