/* HomeBox — app styles on top of Framework7 (iOS theme).
 *
 * Colour system (wiki/frontend.md#colori): palette taken from the app icon
 *   yellow #FFD15D · amber #F9B54C · night blue #2B3B4E/#324A5E · coral #FF6472/#C75163
 * Light and dark values follow the OS setting (prefers-color-scheme). Framework7 runs with
 * darkMode: 'auto', which toggles html.dark from the same media query, so the two always agree.
 * Every text/background pair below meets WCAG AA (≥ 4.5:1 text, ≥ 3:1 graphics).
 */

/* ---- Design tokens: light ---------------------------------------------- */
:root {
  --hb-yellow: #ffd15d;
  --hb-amber: #f9b54c;
  --hb-navy: #2b3b4e;
  --hb-navy-2: #324a5e;
  --hb-ink: #1b2633;

  --hb-primary: #2b3b4e;          /* 11.4:1 on white */
  --hb-primary-rgb: 43, 59, 78;
  --hb-primary-shade: #212e3d;
  --hb-primary-tint: #3b5068;
  --hb-on-primary: #ffffff;

  --hb-page-bg: #f6f2ea;          /* warm light background */
  --hb-surface: #ffffff;
  --hb-muted: #6c6c70;            /* 5.2:1 on white */
  --hb-add: #b43f52;              /* coral, 5.6:1 on white */
  --hb-dot-ring: rgba(0, 0, 0, 0.14);

  --hb-shared: #324a5e;
  --hb-on-shared: #ffffff;
  --hb-personal: #b43f52;
  --hb-on-personal: #ffffff;
  --hb-settlement: #f9b54c;
  --hb-on-settlement: #2b3b4e;
  --hb-settlement-text: #8a5a00;  /* amber as text: 5.9:1 on white */

  --hb-up: #b3261e;               /* spending increased */
  --hb-down: #1e7b3c;             /* spending decreased */
  --hb-error: #b3261e;
  --hb-error-rgb: 179, 38, 30;

  --hb-hero-bg: linear-gradient(135deg, #ffd15d, #f9b54c);
  --hb-hero-text: #2b3b4e;        /* 7.9:1 on yellow */
  --hb-settled-bg: linear-gradient(135deg, #324a5e, #2b3b4e);
  --hb-settled-text: #ffd15d;     /* 7.9:1 on navy */

  --hb-chart-grid: rgba(43, 59, 78, 0.12);
  --hb-chart-text: #6c6c70;

  color-scheme: light dark;
}

/* ---- Design tokens: dark ----------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --hb-primary: #ffd15d;          /* 11.8:1 on #1c1c1e */
    --hb-primary-rgb: 255, 209, 93;
    --hb-primary-shade: #f2be3a;
    --hb-primary-tint: #ffdc85;
    --hb-on-primary: #1b2633;       /* 10.6:1 on yellow */

    --hb-page-bg: #000000;
    --hb-surface: #1c1c1e;
    --hb-muted: #a1a1a6;            /* 6.6:1 on #1c1c1e */
    --hb-add: #ff6472;              /* 5.9:1 on #1c1c1e */
    --hb-dot-ring: rgba(255, 255, 255, 0.22);

    --hb-shared: #a9bdd1;           /* night blue lightened for dark */
    --hb-on-shared: #1b2633;
    --hb-personal: #ff8a94;
    --hb-on-personal: #1b2633;
    --hb-settlement: #f9b54c;
    --hb-on-settlement: #1b2633;
    --hb-settlement-text: #f9b54c;

    --hb-up: #ff8a94;
    --hb-down: #6edc8c;
    --hb-error: #ff8a94;
    --hb-error-rgb: 255, 138, 148;

    --hb-settled-bg: linear-gradient(135deg, #324a5e, #2b3b4e);

    --hb-chart-grid: rgba(255, 255, 255, 0.14);
    --hb-chart-text: #a1a1a6;
  }
}

/* ---- Framework7 integration ---------------------------------------------
   html:root.ios (0,2,1) wins over Framework7's .ios / .ios.dark rules and over the
   :root style block it injects at start-up. */
html:root.ios {
  --f7-ios-primary: var(--hb-primary);
  --f7-ios-primary-rgb: var(--hb-primary-rgb);
  --f7-ios-primary-shade: var(--hb-primary-shade);
  --f7-ios-primary-tint: var(--hb-primary-tint);
  --f7-theme-color: var(--hb-primary);
  --f7-theme-color-rgb: var(--hb-primary-rgb);
  --f7-theme-color-shade: var(--hb-primary-shade);
  --f7-theme-color-tint: var(--hb-primary-tint);
  --f7-button-fill-text-color: var(--hb-on-primary);
  --f7-calendar-selected-text-color: var(--hb-on-primary);
  --f7-page-bg-color: var(--hb-page-bg);
  /* Inactive tabs in muted grey so the active one (primary colour) stands out in both modes. */
  --f7-tabbar-link-inactive-color: var(--hb-muted);
  /* Opaque calendar: the default glass background lets the form behind show through the days. */
  --f7-calendar-sheet-bg-color: var(--hb-surface);
  --f7-calendar-modal-bg-color: var(--hb-surface);
}

.tabbar .tab-link-active .tabbar-label {
  font-weight: 600;
}

/* Framework7's stock red (#ff3b30) is below 4.5:1 as text on white: use the accessible tokens. */
html:root.ios .color-red {
  --f7-theme-color: var(--hb-error);
  --f7-theme-color-rgb: var(--hb-error-rgb);
  --f7-theme-color-shade: var(--hb-error);
  --f7-theme-color-tint: var(--hb-error);
}

/* Swipeout actions: coloured background with guaranteed contrast in both modes. */
.swipeout-actions-right .hb-swipe-edit {
  background-color: var(--hb-navy-2);
  color: #ffffff;
}

.swipeout-actions-right .hb-swipe-delete {
  background-color: #b3261e;
  color: #ffffff;
}

.hb-badge-primary {
  background: var(--hb-primary);
  color: var(--hb-on-primary);
}

.hb-badge-muted {
  background: var(--hb-muted);
  color: var(--hb-surface);
}

html,
body {
  overscroll-behavior: none;
}

/* iOS zooms into inputs with font-size < 16px: keep all form controls at 16px+. */
input,
select,
textarea,
.item-input-wrap input,
.item-input-wrap select,
.item-input-wrap textarea {
  font-size: 17px !important;
}

/* ---- Boot screen ------------------------------------------------------- */
.app-boot {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--hb-page-bg);
  color: var(--hb-primary);
  padding: env(safe-area-inset-top) 24px env(safe-area-inset-bottom);
  text-align: center;
}

/* ---- Tab bar ----------------------------------------------------------- */
.tabbar .tab-add .icon {
  font-size: 40px;
  width: 40px;
  height: 40px;
  color: var(--hb-add);
}

.tabbar .tab-add {
  min-width: 56px;
}

/* ---- Payments ---------------------------------------------------------- */
.payer-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px var(--hb-dot-ring);
}

.payer-dot-large {
  width: 28px;
  height: 28px;
  margin-right: 0;
}

.payments-list .item-media {
  align-self: center;
}

.payments-list .item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.payments-list .item-text {
  -webkit-line-clamp: 1;
  white-space: pre-line;
}

.amount {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--f7-text-color, inherit);
}

.amount-settlement {
  color: var(--hb-settlement-text);
}

.kind-badge {
  display: inline-block;
  padding: 0 6px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 17px;
  font-weight: 700;
  margin-right: 4px;
}

.kind-badge.kind-shared { background: var(--hb-shared); color: var(--hb-on-shared); }
.kind-badge.kind-personal { background: var(--hb-personal); color: var(--hb-on-personal); }
.kind-badge.kind-settlement { background: var(--hb-settlement); color: var(--hb-on-settlement); }

.kind-icon.kind-shared { color: var(--hb-shared); }
.kind-icon.kind-personal { color: var(--hb-personal); }
.kind-icon.kind-settlement { color: var(--hb-settlement-text); }

.item-disabled-soft {
  opacity: 0.6;
}

.filters-active {
  position: relative;
}

.filters-active .badge {
  position: absolute;
  top: 2px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  font-size: 10px;
  background: var(--hb-add);
  color: #fff;
}

.empty-state,
.list-end {
  color: var(--hb-muted);
}

/* ---- Offline & pending sync ---------------------------------------------- */
.offline-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px calc(16px + env(safe-area-inset-right)) 4px calc(16px + env(safe-area-inset-left));
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--hb-surface);
  color: inherit;
  border: 1px solid var(--hb-dot-ring);
}

.offline-banner.is-offline {
  background: var(--hb-navy-2);
  color: #ffffff;
  border-color: transparent;
}

.offline-banner.has-errors {
  border-color: var(--hb-error);
}

.offline-banner-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.offline-banner:not(.is-offline) .offline-banner-icon {
  color: var(--hb-primary);
}

.offline-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 14px;
  line-height: 1.35;
  flex: 1;
}

.offline-banner-text strong {
  font-size: 15px;
}

.offline-banner-action {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 10px;
  background: var(--hb-primary);
  color: var(--hb-on-primary);
  font-weight: 600;
  font-size: 15px;
  min-height: 20px;
}

.offline-banner.is-offline .offline-banner-action {
  background: var(--hb-yellow);
  color: var(--hb-ink);
}

.pending-icon {
  font-size: 22px;
  color: var(--hb-muted);
}

.pending-icon.is-invalid {
  color: var(--hb-error);
}

.pending-badge {
  display: inline-block;
  padding: 0 6px;
  margin-right: 4px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 17px;
  font-weight: 700;
  background: var(--hb-muted);
  color: var(--hb-surface);
}

.pending-badge.is-invalid {
  background: #b3261e;
  color: #ffffff;
}

.pending-tab-badge {
  background: var(--hb-add);
  color: #ffffff;
}

.pending-tab-badge.is-invalid {
  background: #b3261e;
}

.form-notice {
  margin: 12px 16px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--hb-surface);
  color: inherit;
  text-align: center;
}

.form-notice.is-invalid {
  color: var(--hb-error);
  font-weight: 600;
}

/* ---- Dashboard --------------------------------------------------------- */
.balance-card {
  background: var(--hb-hero-bg);
  color: var(--hb-hero-text);
}

.balance-card.balance-settled {
  background: var(--hb-settled-bg);
  color: var(--hb-settled-text);
}

.balance-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 600;
}

.balance-label .payer-dot {
  box-shadow: 0 0 0 2px var(--hb-hero-text);
}

.balance-arrow {
  font-size: 16px;
  margin: 0 4px;
}

.balance-amount {
  font-size: 34px;
  font-weight: 700;
  margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
}

.balance-hint {
  font-size: 13px;
  font-weight: 500;
}

.stat-grid {
  padding: 0 calc(var(--f7-block-inset-side-margin, 16px) + env(safe-area-inset-left)) 0 calc(var(--f7-block-inset-side-margin, 16px) + env(safe-area-inset-right));
  --f7-grid-gap: 10px;
}

.stat-tile {
  background: var(--hb-surface);
  border-radius: 12px;
  padding: 12px;
  min-height: 84px;
}

.stat-label {
  font-size: 13px;
  color: var(--hb-muted);
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: 12px;
  color: var(--hb-muted);
  margin-top: 2px;
}

.stat-sub.trend-up,
.trend-up { color: var(--hb-up); }
.stat-sub.trend-down,
.trend-down { color: var(--hb-down); }

/* ---- Payment form ------------------------------------------------------ */
.payment-popup .page-content {
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.amount-block {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  margin: 24px 16px 8px;
}

.amount-currency {
  font-size: 32px;
  font-weight: 600;
  color: var(--hb-muted);
}

.amount-block .amount-input {
  font-size: 44px !important;
  font-weight: 700;
  width: 5.5ch;
  field-sizing: content;
  min-width: 3ch;
  max-width: 75%;
  text-align: left;
  border: none;
  background: transparent;
  color: inherit;
  caret-color: var(--hb-primary);
  font-variant-numeric: tabular-nums;
  outline: none;
}

.amount-invalid .amount-input {
  color: var(--hb-error);
}

.form-error {
  color: var(--hb-error);
  text-align: center;
}

.form-hint {
  color: var(--hb-settlement-text);
  font-weight: 500;
}

.payer-block {
  margin-top: 8px;
  margin-bottom: 8px;
}

.payer-segmented .button {
  height: 40px;
  font-size: 15px;
}

.delete-button {
  margin-top: 16px;
}

.color-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.color-choice {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 0 0 1px var(--hb-dot-ring);
}

.color-choice.selected {
  border-color: var(--hb-primary);
  box-shadow: inset 0 0 0 3px var(--hb-surface);
}

/* ---- Receipt scan ------------------------------------------------------ */
.scan-block {
  margin-top: 16px;
  margin-bottom: 0;
}

.scan-button {
  position: relative;
  gap: 8px;
  height: 44px;
  font-size: 16px;
}

.scan-button .icon {
  font-size: 22px;
}

/* Visually hidden but still reachable: iOS does not open the camera for display:none inputs. */
.scan-button .scan-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.scan-hint {
  margin-top: 6px;
  font-size: 13px;
  color: var(--hb-muted);
  text-align: center;
}

/* Values read from the receipt: visible until the user confirms them by editing. */
.amount-block.is-autofilled,
.form-list .item-input.is-autofilled {
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px var(--hb-amber);
  background-color: rgba(249, 181, 76, 0.14);
}

.amount-block.is-autofilled {
  padding: 4px 12px;
}

/* ---- Statistics -------------------------------------------------------- */
.chart-box {
  position: relative;
  height: 260px;
}

.chart-box-small {
  height: 200px;
}

.subnavbar .segmented .button {
  font-size: 13px;
}

/* ---- Login / error / offline pages (no Framework7 JS) -------------------
   Self-contained: they use the same tokens, driven by the media query only. */
.login-body {
  margin: 0;
  min-height: 100dvh;
  background: var(--hb-page-bg);
  color: var(--f7-text-color, #1c1c1e);
  font-family: -apple-system, system-ui, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  --login-field-bg: #f6f2ea;
  --login-border: #d6cfc2;
  --login-text: #1c1c1e;
}

@media (prefers-color-scheme: dark) {
  .login-body {
    --login-field-bg: #2c2c2e;
    --login-border: #3a3a3c;
    --login-text: #f2f2f7;
  }
}

.login-body {
  color: var(--login-text);
}

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  box-sizing: border-box;
}

.login-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo {
  border-radius: 16px;
}

.login-title {
  font-size: 28px;
  margin: 12px 0 20px;
}

.login-message {
  margin: 0 0 16px;
  padding: 12px;
  border-radius: 12px;
  background: var(--hb-surface);
}

.login-error {
  color: var(--hb-error);
}

.login-notice {
  color: var(--hb-primary);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  border-radius: 16px;
  background: var(--hb-surface);
  text-align: left;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--hb-muted);
}

.login-form .login-input {
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--login-border);
  border-radius: 12px;
  background: var(--login-field-bg);
  color: var(--login-text);
  caret-color: var(--hb-primary);
  font: inherit;
  font-size: 17px !important;
  -webkit-appearance: none;
  appearance: none;
}

.login-form .login-input::placeholder {
  color: var(--hb-muted);
  opacity: 1;
}

.login-form .login-input:focus {
  outline: none;
  border-color: var(--hb-primary);
  box-shadow: 0 0 0 3px rgba(var(--hb-primary-rgb), 0.3);
}

.login-body .login-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 100%;
  min-height: 50px;
  margin-top: 6px;
  border: 0;
  border-radius: 12px;
  background: var(--hb-primary);
  color: var(--hb-on-primary);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.login-body .login-submit:active {
  opacity: 0.8;
}
