/* iOS-style design for the invoice app. Written from scratch: system font,
   inset grouped lists, blurred bars, automatic dark mode. Under 900px wide it is
   one column (phone style); wider it becomes list-left / detail-right (iPad style). */

:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-hover: #f5f5f7;
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);
  --label-3: rgba(60, 60, 67, 0.3);
  --sep: rgba(60, 60, 67, 0.29);
  --fill: rgba(118, 118, 128, 0.12);
  --tint: #007aff;
  --tint-pressed: #0062cc;
  --danger: #ff3b30;
  --success: #34c759;
  --bar: rgba(249, 249, 249, 0.82);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
  --alert-bg: rgba(255, 255, 255, 0.94);
  --seg-on: #ffffff;
  --sidebar-w: 360px;
  --tab-h: 49px;
  --nav-h: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}

/* Dark colours. They appear twice on purpose: once for "Automatic" (follow the Mac, unless the app has been
   set to Light) and once for "Dark" chosen in Settings. A test checks the two copies stay identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1c1c1e;
    --card-hover: #2c2c2e;
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --sep: rgba(84, 84, 88, 0.65);
    --fill: rgba(118, 118, 128, 0.24);
    --tint: #0a84ff;
    --tint-pressed: #409cff;
    --danger: #ff453a;
    --success: #30d158;
    --bar: rgba(29, 29, 31, 0.82);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    --alert-bg: rgba(44, 44, 46, 0.92);
    --seg-on: #636366;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --card: #1c1c1e;
  --card-hover: #2c2c2e;
  --label: #ffffff;
  --label-2: rgba(235, 235, 245, 0.6);
  --label-3: rgba(235, 235, 245, 0.3);
  --sep: rgba(84, 84, 88, 0.65);
  --fill: rgba(118, 118, 128, 0.24);
  --tint: #0a84ff;
  --tint-pressed: #409cff;
  --danger: #ff453a;
  --success: #30d158;
  --bar: rgba(29, 29, 31, 0.82);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  --alert-bg: rgba(44, 44, 46, 0.92);
  --seg-on: #636366;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--label);
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
a { color: var(--tint); text-decoration: none; }

:focus-visible { outline: 2px solid var(--tint); outline-offset: 2px; border-radius: 6px; }
input:focus-visible, textarea:focus-visible { outline: none; }

/* ---------- layout ---------- */

.app { display: flex; height: 100dvh; }

.pane { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  border-right: 0.5px solid var(--sep);
}

.detail { flex: 1; min-width: 0; }

.scroll { padding-bottom: 40px; }

/* Settings/Invoices have a tab bar underneath them */
.has-tabs { padding-bottom: calc(var(--tab-h) + var(--safe-b) + 24px); }

@media (max-width: 899px) {
  .sidebar, .detail { width: 100%; border-right: 0; }
  body[data-route="list"] .detail { display: none; }
  body:not([data-route="list"]) .sidebar { display: none; }
  /* the tab bar only shows on the two "root" screens, like iOS */
  body[data-route="edit"] .tabbar { display: none; }
}

/* ---------- navigation bars ---------- */

.nav {
  position: sticky; top: 0; z-index: 5;
  height: calc(var(--nav-h) + var(--safe-t));
  padding: var(--safe-t) 8px 0;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--sep);
}
.nav-title { font-weight: 600; text-align: center; white-space: nowrap; }
.nav-btn { color: var(--tint); padding: 10px 8px; min-width: 44px; }
.nav-btn.left { justify-self: start; }
.nav-btn.right { justify-self: end; }
.nav-btn.strong { font-weight: 600; }
.nav-btn:hover { color: var(--tint-pressed); }
.nav-btn[disabled] { opacity: 0.4; cursor: default; }

.large-title {
  font-size: 34px; font-weight: 700; letter-spacing: -0.02em;
  padding: 10px 20px 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.icon-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--fill); color: var(--tint);
  display: grid; place-items: center; font-size: 22px; line-height: 1; padding-bottom: 2px;
}
.icon-btn:hover { background: var(--label-3); }

/* ---------- search ---------- */

.search { margin: 0 16px 8px; position: relative; }
.search input {
  width: 100%; height: 36px; border: 0; border-radius: 10px;
  background: var(--fill); padding: 0 10px 0 32px; font-size: 17px;
}
.search input::placeholder { color: var(--label-2); }
.search svg { position: absolute; left: 9px; top: 9px; width: 18px; height: 18px; color: var(--label-2); }
.search input:focus { outline: none; }

/* ---------- grouped lists ---------- */

.group-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: -0.003em;
  color: var(--label-2); margin: 26px 32px 7px;
}
.group-footer { font-size: 13px; color: var(--label-2); margin: 7px 32px 0; line-height: 1.35; }

.group { background: var(--card); border-radius: 10px; margin: 0 16px; overflow: hidden; }

.row {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 0 16px; width: 100%;
}
.row + .row::before, .item + .item::before, .row + .item::before, .item + .row::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 0.5px; background: var(--sep);
}
.item { position: relative; }

.row-label { flex: none; width: 112px; white-space: nowrap; }
.row-input {
  flex: 1; min-width: 0; height: 44px; border: 0; background: none; font-size: 17px; text-align: left;
}
.row-input::placeholder, .row-block textarea::placeholder, .item input::placeholder { color: var(--label-3); }
.row-input:focus, .row-block textarea:focus, .item input:focus { outline: none; }
.row-value { margin-left: auto; color: var(--label-2); }

.row-block { padding: 8px 16px; align-items: stretch; }
.row-block textarea {
  width: 100%; min-height: 76px; border: 0; background: none; resize: none; font-size: 17px; line-height: 1.3; padding: 4px 0;
}

.row-button { color: var(--tint); }
.row-button:hover, a.row:hover { background: var(--card-hover); }
.row-button.danger { color: var(--danger); }
.row-button .plus {
  width: 22px; height: 22px; border-radius: 50%; background: var(--success); color: #fff;
  display: grid; place-items: center; font-size: 17px; line-height: 1; padding-bottom: 1px;
}

.total-row { font-weight: 600; justify-content: space-between; }
.total-row .amount { font-size: 20px; font-variant-numeric: tabular-nums; }

/* invoice rows in the list */
a.list-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; color: inherit; position: relative;
}
a.list-row + a.list-row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 0.5px; background: var(--sep); }
a.list-row.selected { background: var(--tint); color: #fff; }
a.list-row.selected .sub, a.list-row.selected .right-sub { color: rgba(255, 255, 255, 0.8); }
.list-main { min-width: 0; flex: 1; }
.list-title { font-weight: 600; }
.sub { color: var(--label-2); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-right { text-align: right; flex: none; }
.right-sub { color: var(--label-2); font-size: 15px; }
.amount-text { font-variant-numeric: tabular-nums; }

/* line items in the editor */
.item { display: flex; align-items: center; gap: 10px; padding: 8px 16px 8px 12px; }
.minus {
  flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--danger); color: #fff;
  display: grid; place-items: center; font-size: 18px; line-height: 1; padding-bottom: 2px;
}
.item-fields { flex: 1; min-width: 0; }
.item-desc { width: 100%; height: 30px; border: 0; background: none; font-size: 17px; }
.item-nums { display: flex; align-items: center; gap: 6px; color: var(--label-2); font-size: 15px; }
.item-nums input {
  width: 64px; height: 28px; border: 0; border-radius: 7px; background: var(--fill);
  text-align: right; padding: 0 8px; font-size: 15px; font-variant-numeric: tabular-nums; color: var(--label);
}
.item-nums input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
.item-nums input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.item-nums .price { width: 84px; }
.item-amt { margin-left: auto; color: var(--label); font-variant-numeric: tabular-nums; }

/* first-run banner */
.banner {
  margin: 12px 16px 0; padding: 14px 16px; border-radius: 12px; background: var(--tint); color: #fff; line-height: 1.35;
}
.banner strong { display: block; margin-bottom: 2px; }

/* ---------- empty states ---------- */

.empty { text-align: center; color: var(--label-2); padding: 56px 32px; }
.empty .big { font-size: 22px; font-weight: 600; color: var(--label); margin-bottom: 6px; }
.detail-empty {
  display: none; height: 100%; align-items: center; justify-content: center; text-align: center;
  color: var(--label-2); padding: 32px;
}
.detail-empty .big { font-size: 22px; font-weight: 600; color: var(--label); margin-bottom: 6px; }
/* On a wide window the right-hand pane shows this when nothing is open */
@media (min-width: 900px) {
  .detail-empty { display: flex; }
  /* keep forms a comfortable reading width instead of stretching across a big window */
  .detail .scroll { max-width: 700px; margin: 0 auto; }
}

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed; left: 0; bottom: 0; right: 0; z-index: 6;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; justify-content: space-around;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
}
@media (min-width: 900px) {
  .tabbar { right: auto; width: var(--sidebar-w); border-right: 0.5px solid var(--sep); }
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--label-2); font-size: 10px; letter-spacing: 0.01em;
}
.tab svg { width: 26px; height: 26px; }
.tab.active { color: var(--tint); }
.tab:hover { color: var(--tint); }

/* ---------- alerts, sheets, toast ---------- */

.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fade-in 0.15s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: scale(1.08); } to { opacity: 1; transform: scale(1); } }

.alert {
  width: 270px; border-radius: 14px; text-align: center; overflow: hidden;
  background: var(--alert-bg); -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px);
  animation: pop-in 0.18s ease-out;
}
.alert-body { padding: 18px 16px 16px; }
.alert-title { font-weight: 600; font-size: 17px; margin-bottom: 4px; }
.alert-message { font-size: 13px; line-height: 1.35; }
.alert-actions { display: flex; flex-direction: column; border-top: 0.5px solid var(--sep); }
.alert-actions button {
  height: 44px; width: 100%; text-align: center; color: var(--tint); font-size: 17px;
  border-top: 0.5px solid var(--sep);
}
.alert-actions button:first-child { border-top: 0; }
.alert-actions button.strong { font-weight: 600; }
.alert-actions button.danger { color: var(--danger); }
.alert-actions button:hover { background: var(--fill); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 18px); transform: translateX(-50%);
  z-index: 60; width: max-content; padding: 10px 18px; border-radius: 22px; font-size: 15px; font-weight: 500;
  background: rgba(60, 60, 67, 0.92); color: #fff; box-shadow: var(--shadow);
  animation: fade-in 0.15s ease-out; max-width: calc(100vw - 32px); text-align: center;
}
.toast.error { background: var(--danger); }

.hidden-file { display: none; }

/* ---------- PDF preview sheet ---------- */

.sheet-backdrop { align-items: flex-end; padding: 0; }
.sheet {
  width: 100%; height: 100dvh; background: var(--bg);
  display: flex; flex-direction: column; overflow: hidden;
  animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 900px) {
  .sheet-backdrop { align-items: center; padding: 24px; }
  .sheet { width: min(780px, 100%); height: min(94dvh, 980px); border-radius: 14px; box-shadow: var(--shadow); }
}
.sheet-body { position: relative; flex: 1; min-height: 0; background: var(--fill); }
.pdf-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.sheet-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 32px; color: var(--label-2); background: var(--bg);
}
.sheet-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px calc(10px + var(--safe-b)); background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
}
.sheet-dest { font-size: 13px; color: var(--label-2); min-width: 0; }
.btn {
  height: 36px; padding: 0 16px; border-radius: 10px; background: var(--fill); color: var(--tint); font-weight: 600; flex: none;
}
.btn:hover { background: var(--label-3); }

/* ---------- segmented control (iOS style), used for Appearance in Settings ---------- */

.segmented { display: flex; flex: 1; background: var(--fill); border-radius: 9px; padding: 2px; margin: 8px 0; }
.seg { flex: 1; height: 32px; text-align: center; border-radius: 7px; font-size: 14px; font-weight: 500; color: var(--label); }
.seg[aria-checked="true"] { background: var(--seg-on); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
.seg:not([aria-checked="true"]):hover { background: var(--label-3); }
