:root {
  --bg: #FAF7F0;
  --surface: #FFFFFF;
  --surface-soft: #F3EDE0;
  --vine: #2D4A33;
  --vine-dark: #1E3523;
  --vine-light: #EAF1EB;
  --gold: #B8863B;
  --gold-bright: #D4A962;
  --gold-light: #F7EFE0;
  --grape: #6B2D3E;
  --grape-light: #F8ECEF;
  --text: #1F2A22;
  --muted: #5C6B60;
  --border: #E5DCCB;
  --danger: #B43232;
  --danger-bg: #FDF0F0;
  --ok: #256B3A;
  --ok-bg: #EAF6EE;
  --radius: 19px;
  --shadow: 0 7px 22px rgba(30, 53, 35, 0.08);
}

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

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', 'Noto Sans Arabic', Tahoma, Arial, sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

/* Native App Header */
.header {
  background: linear-gradient(155deg, var(--vine) 0%, var(--vine-dark) 100%);
  color: #FAF7F0;
  padding: calc(15px + env(safe-area-inset-top)) 14px 16px;
  border-bottom-left-radius: 26px;
  border-bottom-right-radius: 26px;
  box-shadow: 0 8px 24px rgba(30, 53, 35, 0.22);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 13px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1.5px solid rgba(212, 169, 98, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-text {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.03rem;
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.72rem;
  color: #E7D5B3;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-pill-btn {
  background: rgba(255, 255, 255, 0.14);
  color: #FAF7F0;
  border: 1.5px solid rgba(212, 169, 98, 0.55);
  border-radius: 999px;
  padding: 6px 9px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  position: relative;
}

.history-count {
  background: var(--gold-bright);
  color: #1A281D;
  font-size: 0.65rem;
  font-weight: 900;
  min-width: 17px;
  height: 17px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.install-btn {
  background: linear-gradient(135deg, #D4A962, #B8863B);
  color: #1A281D;
  border: none;
  border-radius: 999px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

.icon-pill-btn:active,
.install-btn:active {
  transform: scale(0.94);
}

/* Top App Navigation Switcher */
.app-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: rgba(0, 0, 0, 0.22);
  padding: 4px;
  border-radius: 15px;
  border: 1px solid rgba(212, 169, 98, 0.28);
}

.nav-tab {
  border: none;
  background: transparent;
  color: rgba(250, 247, 240, 0.84);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 800;
  padding: 9px 10px;
  border-radius: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.nav-tab.active {
  background: #FAF7F0;
  color: var(--vine-dark);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.nav-tab:active {
  transform: scale(0.97);
}

/* Main Container & Views */
.main {
  padding: 15px 14px 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.view-panel {
  display: none;
  flex-direction: column;
  gap: 13px;
}

.view-panel.active {
  display: flex;
}

/* =========================================
   TAB 1: AREA CONVERTER (Arisha ⇄ m²)
   ========================================= */
.primary-stage {
  display: flex;
  flex-direction: column;
  position: relative;
}

.conv-box {
  border-radius: var(--radius);
  padding: 15px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.conv-arisha {
  background: linear-gradient(145deg, #2D4A33 0%, #203825 100%);
  color: #FAF7F0;
  border: 2px solid rgba(212, 169, 98, 0.65);
  box-shadow: 0 12px 26px rgba(30, 53, 35, 0.2);
  padding-bottom: 22px;
}

.conv-arisha.is-active {
  border-color: var(--gold-bright);
  box-shadow: 0 12px 28px rgba(30, 53, 35, 0.28), 0 0 0 3px rgba(212, 169, 98, 0.22);
}

.box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.box-title {
  font-size: 0.92rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
}

.conv-arisha .box-title { color: #F5E5C5; }
.conv-sqm .box-title { color: var(--vine-dark); }

.box-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}

.conv-arisha .box-badge {
  background: rgba(255, 255, 255, 0.12);
  color: #E7D5B3;
  border: 1px solid rgba(212, 169, 98, 0.35);
}

.conv-sqm .box-badge {
  background: var(--vine-light);
  color: var(--vine);
  border: 1px solid #C8DBC9;
}

.big-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 15px;
  padding: 4px 10px;
}

.conv-arisha .big-input-row {
  background: rgba(255, 255, 255, 0.1);
  border: 1.5px solid rgba(255, 255, 255, 0.2);
}

.conv-arisha .big-input-row:focus-within {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--gold-bright);
}

.conv-sqm .big-input-row {
  background: #FCFBF8;
  border: 2px solid var(--border);
}

.conv-sqm .big-input-row:focus-within {
  border-color: var(--vine);
  box-shadow: 0 0 0 4px rgba(45, 74, 51, 0.09);
}

.big-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 2.1rem;
  font-weight: 900;
  padding: 7px 4px;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: right;
  letter-spacing: -0.5px;
}

html[dir="ltr"] .big-input { text-align: left; }

.conv-arisha .big-input { color: #FFFFFF; }
.conv-arisha .big-input::placeholder { color: rgba(255, 255, 255, 0.35); }
.conv-sqm .big-input { color: var(--vine-dark); }
.conv-sqm .big-input::placeholder { color: #C2BCB0; }

.unit-suffix {
  font-size: 0.9rem;
  font-weight: 800;
  white-space: nowrap;
  flex-shrink: 0;
}

.conv-arisha .unit-suffix { color: #E7D5B3; }
.conv-sqm .unit-suffix { color: var(--muted); }

.mini-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  flex-shrink: 0;
  transition: transform 0.12s ease;
}

.mini-icon-btn:active { transform: scale(0.9); }
.conv-arisha .mini-icon-btn { background: rgba(255, 255, 255, 0.14); color: #FAF7F0; }
.conv-sqm .mini-icon-btn { background: var(--surface-soft); color: var(--vine-dark); }

.presets {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.presets::-webkit-scrollbar { display: none; }

.preset-chip {
  flex: 1;
  min-width: 44px;
  background: rgba(255, 255, 255, 0.11);
  color: #F6E6C6;
  border: 1px solid rgba(212, 169, 98, 0.38);
  border-radius: 10px;
  padding: 6px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.preset-chip:active {
  transform: scale(0.94);
  background: rgba(212, 169, 98, 0.3);
}

.connector-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: -15px 0;
  z-index: 5;
  position: relative;
}

.connector-pill {
  background: linear-gradient(135deg, #F5E6C8, #E6CB96);
  color: #2A200E;
  border: 2.5px solid var(--bg);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 0.78rem;
  font-weight: 900;
  box-shadow: 0 4px 12px rgba(30, 53, 35, 0.15);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  user-select: none;
}

.conv-sqm {
  background: var(--surface);
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
  padding-top: 22px;
}

.conv-sqm.is-active {
  border-color: var(--vine);
  box-shadow: 0 10px 26px rgba(45, 74, 51, 0.14);
}

.geo-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.geo-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
}

.geo-val {
  font-size: 0.9rem;
  font-weight: 900;
  color: var(--vine-dark);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.geo-lbl {
  font-size: 0.66rem;
  color: var(--muted);
  font-weight: 600;
  margin-top: 2px;
}

/* Bridge Banner */
.bridge-banner {
  background: linear-gradient(135deg, #FFFDF7, #F6ECDA);
  border: 1.5px solid #E3CFA8;
  border-radius: 15px;
  padding: 11px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.14s ease;
  font-family: inherit;
  width: 100%;
  text-align: start;
}

.bridge-banner:active { transform: scale(0.98); }

.bridge-left {
  display: flex;
  align-items: center;
  gap: 9px;
}

.bridge-ico {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--vine);
  color: #F5E5C5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.bridge-title {
  font-size: 0.84rem;
  font-weight: 800;
  color: var(--vine-dark);
  display: block;
}

.bridge-sub {
  font-size: 0.71rem;
  color: #6B4D1A;
  font-weight: 600;
  display: block;
  margin-top: 1px;
}

.bridge-arrow {
  font-size: 0.9rem;
  font-weight: 900;
  color: var(--vine);
  background: #FFFFFF;
  border: 1px solid #E3CFA8;
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

/* Secondary Units Accordion */
.secondary-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 3px 12px rgba(30, 53, 35, 0.04);
}

.secondary-toggle {
  width: 100%;
  background: #F6F1E6;
  border: none;
  padding: 12px 14px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: start;
  color: var(--text);
}

.sec-head-text { display: flex; flex-direction: column; gap: 2px; }
.sec-title { font-size: 0.84rem; font-weight: 800; color: var(--vine-dark); display: flex; align-items: center; gap: 6px; }
.sec-preview { font-size: 0.72rem; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }

.sec-chevron {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--vine);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.secondary-box.open .sec-chevron { transform: rotate(180deg); }
.secondary-body { display: none; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); }
.secondary-box.open .secondary-body { display: block; }
.sec-hint { font-size: 0.72rem; color: var(--muted); margin: 0 0 9px; }

.sec-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.sec-card {
  background: #FCFBF8;
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sec-card:focus-within,
.sec-card.is-active {
  border-color: var(--gold);
  background: #FFFDF8;
  box-shadow: 0 0 0 2px rgba(184, 134, 59, 0.14);
}

.sec-card-top { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.sec-name { font-size: 0.76rem; font-weight: 800; color: var(--text); }
.sec-copy-mini { background: transparent; border: none; color: var(--muted); font-size: 0.78rem; cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.sec-sub { font-size: 0.65rem; color: var(--muted); }

.sec-input {
  width: 100%;
  border: none;
  border-bottom: 1.5px solid var(--border);
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--vine-dark);
  padding: 3px 0;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: right;
}

html[dir="ltr"] .sec-input { text-align: left; }
.sec-input:focus { border-bottom-color: var(--vine); }

.diff-note {
  margin-top: 10px;
  background: var(--grape-light);
  border: 1px solid #E5C8D0;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 0.73rem;
  color: var(--grape);
  line-height: 1.5;
  display: flex;
  align-items: flex-start;
  gap: 7px;
}

.diff-note strong { color: #4D1D2A; }

/* =========================================
   TAB 2: LAND PRICE & SHARES
   ========================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--vine-dark);
  display: flex;
  align-items: center;
  gap: 6px;
}

.arisha-eq-badge {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 700;
}

.seg-control {
  display: inline-flex;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.seg-btn.active {
  background: var(--vine);
  color: #FFFFFF;
  box-shadow: 0 2px 6px rgba(30, 53, 35, 0.2);
}

.dual-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.field-box {
  background: #FCFBF8;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 8px 11px;
}

.field-box:focus-within {
  border-color: var(--vine);
  box-shadow: 0 0 0 3px rgba(45, 74, 51, 0.09);
  background: #FFFFFF;
}

.field-box.primary-tint {
  background: #F5F8F5;
  border-color: #C7D8C9;
}

.field-label {
  display: block;
  font-size: 0.71rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 3px;
}

.field-input-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.field-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 1.45rem;
  font-weight: 900;
  color: var(--vine-dark);
  padding: 2px 0;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: right;
}

html[dir="ltr"] .field-input { text-align: left; }

.field-unit {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.price-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 9px;
}

.price-input-box {
  background: #FFFDF8;
  border: 2px solid #DFCCA8;
  border-radius: 14px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.price-input-box:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184, 134, 59, 0.14);
}

.price-input-box .field-input {
  font-size: 1.65rem;
  color: #5A3B0D;
}

.curr-badge {
  background: var(--gold-light);
  color: #6B4712;
  border: 1px solid #E3CFA8;
  border-radius: 9px;
  padding: 5px 10px;
  font-size: 0.82rem;
  font-weight: 900;
  white-space: nowrap;
}

/* Optional Exchange Rate Box */
.fx-bar {
  margin-top: 10px;
  background: #F6F3EB;
  border: 1px dashed #D7C7A8;
  border-radius: 13px;
  padding: 8px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.fx-label-wrap {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.fx-title {
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--vine-dark);
}

.fx-sub {
  font-size: 0.65rem;
  color: var(--muted);
}

.fx-input-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #FFFFFF;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 4px 8px;
  min-width: 145px;
}

.fx-input-wrap:focus-within {
  border-color: var(--gold);
}

.fx-prefix {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}

.fx-input {
  width: 82px;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 900;
  color: var(--vine-dark);
  direction: ltr;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.fx-clear-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

/* Total Valuation Hero */
.total-hero {
  background: linear-gradient(145deg, #2D4A33 0%, #1D3322 100%);
  color: #FAF7F0;
  border-radius: var(--radius);
  padding: 15px 16px;
  border: 1.5px solid rgba(212, 169, 98, 0.6);
  box-shadow: 0 10px 24px rgba(30, 53, 35, 0.2);
}

.total-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.total-lbl {
  font-size: 0.84rem;
  font-weight: 700;
  color: #E7D5B3;
}

.total-area-pill {
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.12);
  color: #FAF7F0;
  padding: 3px 9px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.total-amount {
  font-size: 2.05rem;
  font-weight: 900;
  color: #FFFFFF;
  margin: 5px 0 4px;
  line-height: 1.15;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  text-align: right;
  word-break: break-word;
}

html[dir="ltr"] .total-amount { text-align: left; }

.total-curr {
  font-size: 1rem;
  font-weight: 800;
  color: #F2D79E;
  margin: 0 5px;
}

.total-fx-equiv {
  font-size: 0.86rem;
  font-weight: 800;
  color: #F2D79E;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(212, 169, 98, 0.32);
  border-radius: 10px;
  padding: 5px 10px;
  margin: 4px 0 10px;
  display: inline-block;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.derived-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding-top: 10px;
  margin-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.derived-item {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 11px;
  padding: 7px 6px;
  text-align: center;
}

.derived-val {
  font-size: 0.82rem;
  font-weight: 800;
  color: #F6E6C6;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  word-break: break-word;
}

.derived-lbl {
  font-size: 0.64rem;
  color: rgba(250, 247, 240, 0.82);
  margin-top: 2px;
}

/* Mode Tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.mode-tab {
  background: var(--surface-soft);
  border: 1.5px solid transparent;
  border-radius: 13px;
  padding: 9px 6px;
  font-family: inherit;
  font-size: 0.77rem;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}

.mode-tab .m-ico { font-size: 1.05rem; }

.mode-tab.active {
  background: var(--vine);
  color: #FFFFFF;
  border-color: var(--gold-bright);
  box-shadow: 0 4px 12px rgba(45, 74, 51, 0.24);
}

.mode-panel { display: none; }
.mode-panel.active { display: block; }

.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #FCFBF8;
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 9px 12px;
  margin-bottom: 9px;
}

.stepper-row.last-stepper {
  margin-bottom: 0;
}

.stepper-info { display: flex; flex-direction: column; }
.stepper-title { font-size: 0.84rem; font-weight: 800; color: var(--text); }
.stepper-sub { font-size: 0.69rem; color: var(--muted); }
.stepper { display: inline-flex; align-items: center; gap: 8px; }

.step-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--vine-dark);
  font-size: 1.2rem;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step-btn:active { transform: scale(0.92); background: var(--vine-light); }

.step-val {
  min-width: 28px;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--vine-dark);
  font-variant-numeric: tabular-nums;
}

.spouse-question {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.spouse-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.spouse-btn {
  background: var(--surface-soft);
  border: 1.5px solid transparent;
  border-radius: 11px;
  padding: 8px 6px;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
}

.spouse-btn.active {
  background: var(--grape);
  color: #FFFFFF;
  border-color: #A85B70;
}

.custom-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.balance-pill {
  font-size: 0.74rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.balance-pill.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #B6DEC3; }
.balance-pill.warn { background: var(--gold-light); color: #7C5214; border: 1px solid #E4CFA7; }
.balance-pill.err { background: var(--danger-bg); color: var(--danger); border: 1px solid #EABABA; }

.partner-input-row {
  display: grid;
  grid-template-columns: 1fr 110px 34px;
  gap: 7px;
  align-items: center;
  margin-bottom: 7px;
}

.p-name-in,
.p-share-in {
  border: 1.5px solid var(--border);
  border-radius: 11px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  background: #FCFBF8;
  color: var(--text);
  outline: none;
  min-width: 0;
}

.p-share-in {
  direction: ltr;
  text-align: center;
  font-weight: 900;
  color: var(--vine-dark);
  font-variant-numeric: tabular-nums;
}

.p-name-in:focus,
.p-share-in:focus {
  border-color: var(--vine);
  background: #FFFFFF;
}

.p-del-btn {
  width: 34px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid #E5C8D0;
  background: var(--grape-light);
  color: var(--grape);
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
}

.p-del-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.add-partner-btn {
  width: 100%;
  background: var(--vine-light);
  color: var(--vine-dark);
  border: 1.5px dashed #9BB8A0;
  border-radius: 12px;
  padding: 9px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  margin-top: 2px;
}

/* Improved Share Output Cards (2-col area + full-width money bar for large SYP numbers) */
.shares-out {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.share-item {
  background: #FCFBF8;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.share-item.accent-gold { border-color: #DFCCA8; background: #FFFDF8; }
.share-item.accent-grape { border-color: #E2C3CC; background: #FDF8FA; }
.share-item.empty-msg { text-align: center; color: var(--muted); font-size: 0.82rem; }

.share-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.share-who {
  font-size: 0.86rem;
  font-weight: 900;
  color: var(--vine-dark);
  word-break: break-word;
}

.share-pct-badge {
  font-size: 0.71rem;
  font-weight: 800;
  background: var(--vine-light);
  color: var(--vine);
  padding: 3px 8px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.share-area-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.sm-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 6px;
  text-align: center;
}

.sm-val {
  font-size: 0.9rem;
  font-weight: 900;
  color: var(--vine-dark);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.sm-lbl {
  font-size: 0.65rem;
  color: var(--muted);
  font-weight: 600;
  margin-top: 2px;
}

.share-money-bar {
  background: var(--gold-light);
  border: 1px solid #E3CFA8;
  border-radius: 11px;
  padding: 8px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.sm-money-lbl {
  font-size: 0.72rem;
  font-weight: 800;
  color: #6B4712;
}

.sm-money-vals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.sm-money-main {
  font-size: 0.98rem;
  font-weight: 900;
  color: #5C3D0E;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.sm-money-fx {
  font-size: 0.74rem;
  font-weight: 800;
  color: #7D5920;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.share-subnote {
  font-size: 0.72rem;
  color: var(--muted);
  border-top: 1px dashed var(--border);
  padding-top: 5px;
}

.legal-note {
  margin-top: 10px;
  background: var(--grape-light);
  border: 1px solid #E5C8D0;
  border-radius: 12px;
  padding: 9px 11px;
  font-size: 0.73rem;
  color: var(--grape);
  line-height: 1.55;
}

/* Action Buttons */
.actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.actions-sub-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.btn-primary {
  background: var(--vine);
  color: #FFFFFF;
  border: none;
  border-radius: 14px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 5px 14px rgba(45, 74, 51, 0.22);
}

.btn-gold {
  background: linear-gradient(135deg, #D4A962, #B8863B);
  color: #1A281D;
  border: none;
  border-radius: 14px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 5px 14px rgba(184, 134, 59, 0.24);
}

.btn-soft {
  background: var(--surface);
  color: var(--vine-dark);
  border: 1.5px solid var(--border);
  border-radius: 13px;
  padding: 10px 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.btn-secondary {
  background: var(--surface);
  color: var(--grape);
  border: 1.5px solid #E5C8D0;
  border-radius: 13px;
  padding: 10px 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.btn-full {
  width: 100%;
}

.btn-primary:active,
.btn-gold:active,
.btn-soft:active,
.btn-secondary:active {
  transform: scale(0.97);
}

/* Footer */
.footer {
  text-align: center;
  padding: 15px 14px 6px;
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.65;
}

.footer-author-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 5px;
}

.footer .author {
  font-weight: 800;
  color: var(--vine-dark);
}

.wa-footer-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #1B7F4B;
  color: #FFFFFF;
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  border: 1px solid #146339;
  box-shadow: 0 2px 8px rgba(27, 127, 75, 0.22);
  transition: transform 0.14s ease, background-color 0.14s ease;
  white-space: nowrap;
}

.wa-footer-btn:hover {
  background: #156A3E;
}

.wa-footer-btn:active {
  transform: scale(0.95);
}

.wa-icon {
  flex-shrink: 0;
  display: block;
}

.wa-num {
  font-variant-numeric: tabular-nums;
  opacity: 0.96;
}

.offline-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--vine-light);
  color: var(--vine);
  border: 1px solid #C8DBC9;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  margin-top: 5px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(22px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1E3523;
  color: #FFFFFF;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1200;
  max-width: 92vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.is-error {
  background: var(--danger);
}

/* Modals (Install & History) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 32, 23, 0.62);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  padding: 14px;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--surface);
  width: 100%;
  max-width: 460px;
  max-height: 85dvh;
  overflow-y: auto;
  border-radius: 22px;
  padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.02rem;
  color: var(--vine-dark);
}

.modal-close {
  background: var(--surface-soft);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--muted);
  cursor: pointer;
}

.step-list {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step-list li {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 10px 12px;
  font-size: 0.84rem;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--vine);
  color: #FFFFFF;
  font-weight: 800;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* History Modal Styles */
.save-plot-row {
  display: flex;
  gap: 7px;
  margin-bottom: 12px;
}

.plot-name-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  background: #FCFBF8;
  color: var(--text);
  outline: none;
  min-width: 0;
}

.plot-name-input:focus {
  border-color: var(--vine);
  background: #FFFFFF;
}

.save-plot-submit {
  background: var(--vine);
  color: #FFFFFF;
  border: none;
  border-radius: 12px;
  padding: 9px 14px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 18px 10px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 13px;
}

.history-card {
  background: #FCFBF8;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-name {
  font-size: 0.86rem;
  font-weight: 900;
  color: var(--vine-dark);
  word-break: break-word;
}

.history-date {
  font-size: 0.67rem;
  color: var(--muted);
  white-space: nowrap;
}

.history-meta {
  font-size: 0.76rem;
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.history-actions {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.hist-load-btn {
  flex: 1;
  background: var(--vine-light);
  color: var(--vine-dark);
  border: 1px solid #C8DBC9;
  border-radius: 9px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 800;
  cursor: pointer;
}

.hist-del-btn {
  background: var(--grape-light);
  color: var(--grape);
  border: 1px solid #E5C8D0;
  border-radius: 9px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 800;
  cursor: pointer;
}

/* =========================================
   DEDICATED PRINT / PDF STATEMENT SHEET
   ========================================= */
.print-sheet {
  display: none;
}

@media print {
  @page {
    size: A4;
    margin: 14mm;
  }

  html, body {
    background: #FFFFFF !important;
    color: #111111 !important;
    min-height: auto !important;
  }

  .app,
  .toast,
  .modal-backdrop {
    display: none !important;
  }

  .print-sheet {
    display: block !important;
    font-family: system-ui, -apple-system, 'Segoe UI', 'Noto Sans Arabic', Tahoma, Arial, sans-serif;
    color: #111111;
    line-height: 1.5;
  }

  .ps-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid #1E3523;
    padding-bottom: 10px;
    margin-bottom: 14px;
  }

  .ps-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 900;
    color: #1E3523;
  }

  .ps-subtitle {
    margin: 3px 0 0;
    font-size: 0.8rem;
    color: #444444;
  }

  .ps-date {
    font-size: 0.78rem;
    color: #444444;
    text-align: end;
  }

  .ps-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 14px;
  }

  .ps-box {
    border: 1px solid #CCCCCC;
    border-radius: 8px;
    padding: 8px 10px;
    background: #FAFAFA;
  }

  .ps-box-lbl {
    font-size: 0.72rem;
    color: #555555;
    font-weight: 700;
  }

  .ps-box-val {
    font-size: 0.95rem;
    font-weight: 900;
    color: #111111;
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
  }

  .ps-section-title {
    font-size: 0.92rem;
    font-weight: 900;
    color: #1E3523;
    margin: 12px 0 8px;
  }

  .ps-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    margin-bottom: 12px;
  }

  .ps-table th,
  .ps-table td {
    border: 1px solid #BDBDBD;
    padding: 7px 8px;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  .ps-table th {
    background: #EEF2EF;
    color: #1E3523;
    font-weight: 800;
  }

  .ps-table td.ps-name-cell {
    text-align: start;
    font-weight: 800;
  }

  .ps-note {
    border: 1px solid #CCCCCC;
    background: #F9F9F9;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.74rem;
    color: #333333;
    margin-bottom: 18px;
  }

  .ps-signatures {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-top: 24px;
    padding-top: 8px;
  }

  .ps-sig-box {
    border-top: 1px dashed #666666;
    padding-top: 6px;
    text-align: center;
    font-size: 0.75rem;
    color: #444444;
  }

  .ps-footer {
    margin-top: 22px;
    padding-top: 8px;
    border-top: 1px solid #DDDDDD;
    text-align: center;
    font-size: 0.72rem;
    color: #555555;
  }
}
