/* ==========================================================================
   Simple Invoice — interface styles
   Mobile first. Big targets, few words, no dashboards.
   ========================================================================== */

:root {
  --brand:        #1f6feb;
  --brand-dark:   #1a5fd0;
  --brand-tint:   #eaf2ff;
  --ink:          #14161a;
  --ink-2:        #414751;
  --ink-3:        #6b7280;
  --line:         #e3e6ea;
  --line-strong:  #cfd4da;
  --bg:           #f6f7f9;
  --surface:      #ffffff;
  --ok:           #147d4a;
  --ok-tint:      #e6f5ed;
  --warn:         #9a5b00;
  --warn-tint:    #fdf1de;
  --bad:          #c0322b;
  --bad-tint:     #fdecea;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 1px 2px rgba(16, 20, 26, .06), 0 4px 14px rgba(16, 20, 26, .05);
  --shadow-lg:    0 8px 32px rgba(16, 20, 26, .14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  /* 16px minimum: anything smaller makes iOS Safari zoom on focus. */
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--brand); 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.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 .75rem; }

/* --- app shell ----------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .9rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar__brand { display: flex; align-items: center; gap: .5rem; font-weight: 680; color: var(--ink); }
.topbar__brand:hover { text-decoration: none; }
.topbar__logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: .95rem; font-weight: 700;
}
.topbar__spacer { flex: 1; }

/* Default size for every inline icon. Component rules below override it. */
.icon { width: 20px; height: 20px; flex-shrink: 0; }

.business-switch {
  display: flex; align-items: center; gap: .4rem;
  padding: .35rem .7rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink-2);
  font-size: .85rem; font-weight: 550; cursor: pointer;
  /* Roomy enough to actually read the business name on a phone. */
  max-width: 62vw;
}
.business-switch .icon { width: 15px; height: 15px; opacity: .65; }
.business-switch:hover { border-color: var(--line-strong); text-decoration: none; }
.business-switch span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 1rem .9rem 6rem; }
.wrap--wide { max-width: 1240px; }

/* --- bottom navigation (phone) ------------------------------------------- */

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 45;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .5rem 0 .45rem;
  font-size: .68rem; font-weight: 550; color: var(--ink-3);
}
.tabbar a:hover { text-decoration: none; }
.tabbar a.is-active { color: var(--brand); }
/* While editing a document the save bar takes the bottom slot. */
body:has(.savebar) .tabbar { display: none; }
.tabbar svg { width: 22px; height: 22px; }

/* --- cards and lists ----------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.card__head {
  display: flex; align-items: center; gap: .6rem;
  padding: .85rem 1rem; border-bottom: 1px solid var(--line);
}
.card__head h2, .card__head h3 { margin: 0; }
.card__body { padding: 1rem; }
.card__body--flush { padding: 0; }
.card__foot { padding: .8rem 1rem; border-top: 1px solid var(--line); background: #fbfcfd; border-radius: 0 0 var(--radius) var(--radius); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list a.row, .row {
  display: flex; align-items: center; gap: .8rem;
  padding: .8rem 1rem; color: inherit;
}
.list a.row:hover { background: #fafbfc; text-decoration: none; }
.row__main { flex: 1; min-width: 0; }
.row__title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__sub { font-size: .82rem; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__end { text-align: right; flex-shrink: 0; }
.row__amount { font-weight: 650; font-variant-numeric: tabular-nums; }

/* --- buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .6rem 1rem;
  min-height: 44px;                    /* comfortable thumb target */
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: .93rem; font-weight: 600;
  cursor: pointer; text-align: center;
}
.btn:hover { background: #f7f8fa; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-dark); }
.btn--danger { color: var(--bad); border-color: #f0c4c1; background: var(--bad-tint); }
.btn--danger:hover { background: #fbdcd9; }
.btn--ghost { border-color: transparent; background: transparent; color: var(--brand); }
.btn--ghost:hover { background: var(--brand-tint); }
.btn--sm { min-height: 36px; padding: .35rem .7rem; font-size: .85rem; }
.btn--block { width: 100%; }
.btn svg { width: 18px; height: 18px; }

.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }

/* The two things the app is for, given the space they deserve. */
.actions-big { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1.1rem; }
.action-tile {
  display: flex; flex-direction: column; gap: .3rem;
  padding: 1.05rem 1rem;
  border-radius: var(--radius);
  background: var(--brand); color: #fff;
  box-shadow: var(--shadow);
  font-weight: 650;
}
.action-tile:hover { background: var(--brand-dark); text-decoration: none; }
.action-tile--soft { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.action-tile--soft:hover { background: #f7f8fa; }
.action-tile small { font-weight: 450; font-size: .78rem; opacity: .82; }
.action-tile svg { width: 24px; height: 24px; margin-bottom: .15rem; }

/* --- forms ---------------------------------------------------------------- */

.field { margin-bottom: .9rem; }
.field > label, .label {
  display: block; margin-bottom: .3rem;
  font-size: .84rem; font-weight: 600; color: var(--ink-2);
}
.field .hint { display: block; margin-top: .3rem; font-size: .78rem; color: var(--ink-3); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], input[type=tel], select, textarea {
  width: 100%;
  /* Grid and flex children default to min-width:auto and refuse to shrink
     below their content's intrinsic width. iOS Safari gives date inputs a
     much wider intrinsic size than Chrome, which pushed them outside the
     card. These two lines are what keep every field inside its column. */
  min-width: 0;
  max-width: 100%;
  padding: .6rem .7rem;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 1rem;
}

/* iOS applies its own sizing and centring to date and time controls. */
input[type=date], input[type=time], input[type=datetime-local] {
  -webkit-appearance: none;
  appearance: none;
  /* Safari ignores the shared min-height without this. */
  height: 44px;
}
input[type=date]::-webkit-date-and-time-value {
  text-align: left;
  margin: 0;
}
/* Keep the picker button from stealing width on small screens. */
input[type=date]::-webkit-calendar-picker-indicator { margin-left: 0; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}
input[readonly] { background: #f4f5f7; color: var(--ink-2); }
.is-invalid { border-color: var(--bad) !important; }
.error-text { display: block; margin-top: .3rem; font-size: .8rem; color: var(--bad); font-weight: 550; }

.grid { display: grid; gap: 0 .9rem; }
/* Without this a single wide field drags the whole column out of the card. */
.grid > *, .field, .line__grid > * { min-width: 0; }
.grid--2 { grid-template-columns: 1fr; }
.grid--3 { grid-template-columns: 1fr; }

.check { display: flex; align-items: flex-start; gap: .55rem; margin-bottom: .7rem; }
.check input[type=checkbox] { width: 20px; height: 20px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--brand); }
.check label { font-size: .9rem; font-weight: 500; color: var(--ink-2); margin: 0; }

fieldset { border: 0; margin: 0 0 1rem; padding: 0; }
legend { padding: 0; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: .5rem; }

/* --- tables --------------------------------------------------------------- */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: .6rem .7rem; text-align: left; border-bottom: 1px solid var(--line); }
table.data th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 650; white-space: nowrap; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: 0; }

/* --- pills and flags ------------------------------------------------------ */

.pill {
  display: inline-block; padding: .18rem .5rem;
  border-radius: 999px; font-size: .74rem; font-weight: 650;
  background: #eef0f3; color: var(--ink-2); white-space: nowrap;
}
.pill--draft  { background: #eef0f3; color: var(--ink-2); }
.pill--sent   { background: var(--brand-tint); color: var(--brand-dark); }
.pill--pending, .pill--partially_paid { background: var(--warn-tint); color: var(--warn); }
.pill--paid   { background: var(--ok-tint); color: var(--ok); }
.pill--cancelled { background: var(--bad-tint); color: var(--bad); text-decoration: line-through; }

.flash { display: flex; gap: .6rem; padding: .75rem .9rem; border-radius: var(--radius-sm); margin-bottom: .9rem; font-size: .92rem; font-weight: 500; }
.flash--success { background: var(--ok-tint);  color: var(--ok);   border: 1px solid #bfe4d0; }
.flash--error   { background: var(--bad-tint); color: var(--bad);  border: 1px solid #f3c9c5; }
.flash--info    { background: var(--brand-tint); color: var(--brand-dark); border: 1px solid #c9dcfb; }

.empty { padding: 2.4rem 1rem; text-align: center; color: var(--ink-3); }
.empty svg { width: 40px; height: 40px; opacity: .35; margin-bottom: .6rem; }
.empty p { margin-bottom: .9rem; }

.page-head { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; flex: 1; min-width: 0; }

/* Document type picker. Full width on a phone so it wraps under the title
   rather than squeezing it — it used to be hidden on small screens, which
   left five of the seven document types unreachable on mobile. */
.type-switch { width: 100%; }
@media (min-width: 700px) {
  .type-switch { width: auto; min-width: 180px; }
}

.muted { color: var(--ink-3); }
.small { font-size: .84rem; }
.num   { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: .75rem; }

/* --- type-ahead ----------------------------------------------------------- */

.suggest { position: relative; }
.suggest__menu {
  position: absolute; z-index: 60; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 300px; overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  display: none;
}
.suggest__menu.is-open { display: block; }
.suggest__item {
  display: block; width: 100%; text-align: left;
  padding: .6rem .75rem; border: 0; border-bottom: 1px solid var(--line);
  background: none; font: inherit; cursor: pointer;
}
.suggest__item:last-child { border-bottom: 0; }
.suggest__item:hover, .suggest__item.is-active { background: var(--brand-tint); }
.suggest__name { display: block; font-weight: 600; font-size: .93rem; }
.suggest__hint { display: block; font-size: .78rem; color: var(--ink-3); margin-top: 1px; }
.suggest__new { color: var(--brand); font-weight: 600; }

/* --- invoice editor ------------------------------------------------------- */

.lines { display: block; }
.line {
  position: relative;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.line:last-of-type { border-bottom: 0; }
.line__top { display: flex; gap: .5rem; align-items: flex-start; margin-bottom: .55rem; }
.line__name { flex: 1; }
.line__remove {
  flex-shrink: 0; width: 38px; height: 38px; padding: 0;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-3); cursor: pointer;
}
.line__remove:hover { background: var(--bad-tint); color: var(--bad); border-color: #f0c4c1; }
.line__grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
.line__grid label { font-size: .72rem; }
.line__grid input, .line__grid select { min-height: 40px; padding: .4rem .5rem; font-size: .95rem; }
.line__total {
  grid-column: 1 / -1;
  display: flex; justify-content: space-between; align-items: baseline;
  padding-top: .45rem; border-top: 1px dashed var(--line);
  font-weight: 650;
}
.line__total .muted { font-weight: 500; font-size: .82rem; }

.chips { display: flex; gap: .4rem; flex-wrap: wrap; padding: .75rem 1rem; }
.chip {
  padding: .35rem .7rem; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface); font-size: .84rem; font-weight: 550; cursor: pointer; color: var(--ink-2);
}
.chip:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-tint); }

.totals { list-style: none; margin: 0; padding: 0; }
.totals li { display: flex; justify-content: space-between; gap: 1rem; padding: .32rem 0; font-size: .92rem; }
/* Setting display on li beats the browser's [hidden] rule, so restate it —
   without this every zero row (discount, IGST, round off) stays on screen. */
.totals li[hidden] { display: none; }
.totals li span:last-child { font-variant-numeric: tabular-nums; }
.totals li.totals__grand {
  margin-top: .45rem; padding-top: .6rem; border-top: 2px solid var(--ink);
  font-size: 1.18rem; font-weight: 700;
}
.totals li.totals__muted { color: var(--ink-3); }

/* Save bar pinned above the tab bar while editing. */
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; gap: .5rem; align-items: center;
  padding: .7rem .9rem calc(.7rem + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 20px rgba(16, 20, 26, .07);
}
.savebar__total { flex: 1; min-width: 0; }
.savebar__total small { display: block; font-size: .72rem; color: var(--ink-3); }
.savebar__total strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

/* --- document view -------------------------------------------------------- */

.doc-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.doc-head__amount { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: .3rem .9rem; font-size: .9rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-weight: 550; }

/* --- wider screens -------------------------------------------------------- */

@media (min-width: 700px) {
  .business-switch { max-width: 280px; }
  h1 { font-size: 1.75rem; }
  .wrap { padding: 1.4rem 1.2rem 2.5rem; }
  .grid--2 { grid-template-columns: 1fr 1fr; }
  .grid--3 { grid-template-columns: repeat(3, 1fr); }
  .actions-big { grid-template-columns: repeat(4, 1fr); }
  .line__grid { grid-template-columns: repeat(6, 1fr); }
  .line__total { grid-column: auto; border-top: 0; padding-top: 0; align-items: center; }
  .tabbar { display: none; }
  .savebar { position: sticky; border-radius: var(--radius); border: 1px solid var(--line); margin-top: 1rem; bottom: 1rem; }
  .topbar__nav { display: flex; gap: .2rem; }
  .topbar__nav a {
    padding: .45rem .7rem; border-radius: var(--radius-sm);
    color: var(--ink-2); font-size: .9rem; font-weight: 550;
  }
  .topbar__nav a:hover { background: #f2f4f6; text-decoration: none; }
  .topbar__nav a.is-active { background: var(--brand-tint); color: var(--brand-dark); }
}

@media (max-width: 699px) {
  .topbar__nav { display: none; }
  .hide-sm { display: none !important; }
}

@media print {
  .topbar, .tabbar, .savebar, .no-print { display: none !important; }
  body { background: #fff; }
}
