@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

:root {
  font-family: 'Cairo', Tahoma, sans-serif;
  color: #1d2b27;
  background: #f5f6f1;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --green: #1c5143;
  --green-dark: #153a31;
  --green-soft: #e8f1ec;
  --muted: #78827d;
  --line: #e5e9e3;
  --white: #fff;
  --gold: #c99a45;
  --red: #b94d48;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 7% 3%, rgba(201, 154, 69, .09), transparent 28rem),
    #f5f6f1;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(28, 81, 67, .25);
  outline-offset: 2px;
}

.page-shell { max-width: 1240px; margin: 0 auto; padding: 0 36px; }
.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid rgba(218, 224, 216, .85);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  width: 46px; height: 46px; display: grid; place-items: center;
  border-radius: 15px; color: #fff; background: var(--green-dark);
  font-size: 24px; font-weight: 800; box-shadow: 0 7px 16px rgba(21, 58, 49, .15);
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 19px; line-height: 1.3; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.local-status { display: flex; align-items: center; gap: 7px; color: #69756e; font-size: 11px; margin-left: 9px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #4a9b70; box-shadow: 0 0 0 3px #e0efe4; }

.button {
  min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 11px; padding: 0 15px;
  font-size: 12px; font-weight: 700; transition: .18s ease;
}
.button-primary { background: var(--green); color: #fff; box-shadow: 0 5px 12px rgba(28, 81, 67, .14); }
.button-primary:hover { background: var(--green-dark); transform: translateY(-1px); }
.button-outline { border-color: #dce3db; background: rgba(255,255,255,.72); color: #47544d; }
.button-outline:hover { border-color: #9db4a5; background: #fff; }

main { padding: 36px 0 64px; }
.hero { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 27px; }
.eyebrow { margin: 0 0 5px; color: #8a7651; font-size: 10px; font-weight: 800; letter-spacing: .04em; }
h1, h2, p { margin-top: 0; }
.hero h1 { margin-bottom: 7px; font-size: clamp(26px, 4vw, 36px); letter-spacing: -.04em; line-height: 1.4; }
.hero h1 span { color: var(--green); }
.hero-description { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.hero-button { min-height: 47px; padding: 0 19px; font-size: 13px; white-space: nowrap; }
.hero-button span { font-size: 19px; line-height: 1; }

.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 25px; }
.summary-card {
  position: relative; overflow: hidden; min-height: 143px; padding: 18px 20px;
  border: 1px solid var(--line); border-radius: 17px; background: var(--white);
  box-shadow: 0 5px 18px rgba(32, 54, 41, .025);
}
.summary-card p { margin: 0 0 8px; color: #66736b; font-size: 12px; font-weight: 700; }
.summary-card strong { display: block; font-size: clamp(20px, 3vw, 27px); letter-spacing: -.025em; }
.summary-card small { display: block; margin-top: 5px; color: #8b948e; font-size: 10px; }
.summary-icon {
  position: absolute; left: 18px; top: 17px; display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 11px; color: var(--green); background: var(--green-soft);
  font-size: 19px; font-weight: 800;
}
.incoming-icon { color: #327751; background: #e7f3e8; }
.outgoing-icon { color: #a7544d; background: #f8ece9; }
.balance-card { background: linear-gradient(130deg, #fff 42%, #f0f5ef); border-color: #dbe8dd; }
.balance-card strong { color: var(--green-dark); }

.panel {
  border: 1px solid var(--line); border-radius: 18px; background: var(--white);
  box-shadow: 0 6px 24px rgba(32, 54, 41, .03);
}
.vault-panel { padding: 23px; margin-bottom: 22px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 15px; margin-bottom: 20px; }
.section-heading h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.section-heading .eyebrow { margin-bottom: 2px; }
.section-hint { margin: 0 0 2px; color: var(--muted); font-size: 11px; }
.vault-tree { display: grid; gap: 15px; }
.vault-card {
  width: 100%; padding: 15px 17px; border: 1px solid #e6eae4; border-radius: 15px;
  color: inherit; background: #fff; text-align: right; transition: .18s ease;
}
.vault-card:hover { border-color: #b5cbbb; box-shadow: 0 5px 15px rgba(24, 77, 57, .06); transform: translateY(-1px); }
.vault-card.is-selected { border-color: #78a38c; background: #f1f7f1; box-shadow: 0 0 0 2px rgba(61, 120, 83, .08); }
.vault-card-main { padding: 18px 20px; border-color: #d7e3d9; background: linear-gradient(110deg, #f8fbf7, #fff); }
.vault-card-main .vault-name { font-size: 17px; }
.vault-card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.vault-title { display: flex; align-items: center; min-width: 0; gap: 12px; }
.vault-symbol {
  width: 39px; height: 39px; flex: 0 0 auto; display: grid; place-items: center;
  border-radius: 12px; color: var(--green); background: #edf4ee; font-size: 17px; font-weight: 800;
}
.vault-card-main .vault-symbol { color: #fff; background: var(--green); }
.vault-name { display: block; overflow: hidden; color: #24352e; font-size: 14px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.vault-meta { display: block; margin-top: 3px; color: #89938d; font-size: 10px; font-weight: 500; }
.vault-balance { text-align: left; white-space: nowrap; }
.vault-balance small { display: block; color: #839087; font-size: 10px; }
.vault-balance strong { display: block; margin-top: 3px; color: var(--green-dark); font-size: 15px; }
.vault-card-bottom { display: flex; gap: 17px; margin-top: 13px; padding-top: 10px; border-top: 1px solid rgba(222, 230, 222, .8); }
.flow { display: flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 700; }
.flow-in { color: #367a51; }
.flow-out { color: #b25b52; }
.rollup-equation {
  display: flex; align-items: stretch; justify-content: center; gap: 8px;
  padding: 11px; border: 1px solid #e8ede7; border-radius: 14px;
  background: #f8faf7; direction: ltr;
}
.rollup-part {
  min-width: 0; flex: 1; display: flex; flex-direction: column; justify-content: center;
  gap: 3px; padding: 8px 10px; border-radius: 10px; background: #fff;
  text-align: center; direction: rtl;
}
.rollup-part small { color: #78847b; font-size: 9px; font-weight: 700; }
.rollup-part strong { overflow: hidden; color: #385344; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.rollup-part.rollup-total { background: #e8f1e9; }
.rollup-total strong { color: var(--green-dark); }
.rollup-operator { align-self: center; color: #91a096; font-size: 18px; font-weight: 700; }
.rollup-equals { color: var(--green); }
.tree-branches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.vault-branch {
  min-width: 0; padding: 15px; border: 1px solid #e3e9e2; border-radius: 16px;
  background: linear-gradient(160deg, #f8faf7, #fff 45%);
}
.branch-flow-label {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 10px; color: #718076; font-size: 9px; font-weight: 700;
}
.branch-flow-label span:last-child { color: #39744f; }
.branch-flow-label b { display: inline-block; margin-right: 3px; color: var(--green); font-size: 14px; }
.branch-children-heading {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 13px 0 8px; color: #6d7a71; font-size: 10px; font-weight: 800;
}
.branch-children-heading span:last-child { color: #939c95; font-size: 9px; font-weight: 600; }
.branch-children { display: grid; gap: 8px; padding-right: 12px; border-right: 2px solid #e5ece5; }
.tree-note { margin: 16px 3px 0; padding: 11px 13px; border-radius: 10px; color: #777e74; background: #f7f8f4; font-size: 10px; line-height: 1.8; }

.history-panel { overflow: hidden; }
.history-heading { align-items: center; margin: 0; padding: 20px 22px; border-bottom: 1px solid #edf0ec; }
.history-heading h2 { font-size: 17px; }
.movement-count { padding: 5px 10px; border-radius: 100px; color: #69766d; background: #f1f3ef; font-size: 10px; font-weight: 700; }
.empty-state { padding: 47px 18px; color: #8a938c; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 42px; height: 42px; margin: 0 auto 10px; border-radius: 14px; color: #84998b; background: #eff4ef; font-size: 19px; }
.empty-state strong { display: block; color: #59665e; font-size: 12px; }
.empty-state p { margin: 4px 0 0; font-size: 10px; }
.movement-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 21px; border-bottom: 1px solid #f0f2ef; }
.movement-row:last-child { border-bottom: 0; }
.movement-main { display: flex; align-items: center; min-width: 0; gap: 11px; }
.movement-icon { width: 35px; height: 35px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 11px; font-size: 15px; font-weight: 800; }
.movement-icon.deposit { color: #367a51; background: #eaf4eb; }
.movement-icon.withdrawal { color: #ad514b; background: #f8eeeb; }
.movement-description { min-width: 0; }
.movement-description strong { display: block; overflow: hidden; color: #34443b; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.movement-description small { display: block; margin-top: 3px; color: #8a938d; font-size: 10px; }
.movement-side { display: flex; align-items: center; gap: 11px; }
.movement-amount { white-space: nowrap; font-size: 13px; font-weight: 800; }
.movement-amount.deposit { color: #367a51; }
.movement-amount.withdrawal { color: #b4534c; }
.delete-movement { border: 0; border-radius: 8px; padding: 6px 8px; color: #9b645c; background: transparent; font-size: 10px; }
.delete-movement:hover { color: #a63831; background: #fbefed; }

footer { display: flex; justify-content: space-between; gap: 15px; padding: 0 0 24px; color: #89938c; font-size: 10px; }
footer span:first-child { color: #5d7164; font-weight: 800; }

.movement-dialog { width: min(460px, calc(100% - 28px)); max-width: none; padding: 0; border: 0; border-radius: 19px; color: #26362e; box-shadow: 0 22px 80px rgba(15, 36, 27, .25); }
.movement-dialog::backdrop { background: rgba(13, 30, 23, .48); backdrop-filter: blur(3px); }
.movement-dialog form { padding: 23px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.dialog-heading h2 { margin: 0; font-size: 19px; }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 10px; color: #67736b; background: #f1f3ef; font-size: 23px; line-height: 1; }
.field { display: grid; gap: 6px; margin-top: 13px; }
.field > span { color: #526057; font-size: 11px; font-weight: 700; }
.field input, .field select { width: 100%; min-height: 43px; border: 1px solid #dfe5dd; border-radius: 10px; padding: 8px 11px; color: #27392f; background: #fff; font-size: 12px; }
.field input::placeholder { color: #a7afa8; }
.movement-help { margin: 7px 0 0; color: #7d8981; font-size: 10px; line-height: 1.6; }
.form-error { min-height: 17px; margin: 8px 0 0; color: #b14740; font-size: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 13px; border-top: 1px solid #edf0ec; }

.toast { position: fixed; z-index: 20; right: 50%; bottom: 24px; max-width: calc(100% - 32px); padding: 11px 17px; border-radius: 11px; color: #fff; background: #263c32; box-shadow: 0 9px 28px rgba(17, 35, 25, .23); font-size: 12px; opacity: 0; pointer-events: none; transform: translate(50%, 10px); transition: .2s ease; }
.toast.is-visible { opacity: 1; transform: translate(50%, 0); }
.toast.is-error { background: #a5443d; }

@media (max-width: 760px) {
  .page-shell { padding: 0 18px; }
  .topbar { align-items: flex-start; flex-direction: column; padding: 15px 0 13px; gap: 13px; }
  .topbar-actions { width: 100%; flex-wrap: wrap; }
  .local-status { flex: 1 1 100%; margin: 0 0 2px; }
  .topbar-actions .button { flex: 1; padding: 0 9px; font-size: 10px; }
  main { padding-top: 27px; }
  .hero { align-items: flex-start; flex-direction: column; gap: 16px; }
  .summary-grid { grid-template-columns: 1fr; gap: 9px; }
  .summary-card { min-height: 115px; padding: 15px 17px; }
  .summary-card strong { font-size: 22px; }
  .vault-panel { padding: 17px 13px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .history-heading { align-items: center; flex-direction: row; padding: 17px 15px; }
  .tree-branches { grid-template-columns: 1fr; }
  .vault-branch { padding: 12px; }
  .rollup-equation { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .rollup-operator { display: none; }
  .vault-card { padding: 13px; }
  .vault-card-top { align-items: flex-start; }
  .vault-balance strong { font-size: 12px; }
  .vault-title { gap: 8px; }
  .vault-symbol { width: 34px; height: 34px; }
  .vault-name { font-size: 12px; }
  .vault-meta { font-size: 9px; }
  .vault-card-bottom { gap: 12px; }
  .flow { font-size: 9px; }
  .movement-row { align-items: flex-start; padding: 13px 12px; }
  .movement-side { flex-direction: column-reverse; align-items: flex-end; gap: 2px; }
  .movement-description small { line-height: 1.6; }
  footer { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
