:root {
  --bg: #eef3f1;
  --surface: #ffffff;
  --surface-2: #f3f7f5;
  --text: #10201c;
  --muted: #687874;
  --border: #e2e9e6;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #dcf2ed;
  --in: #15803d;
  --in-soft: #def7e5;
  --out: #d93636;
  --out-soft: #fde6e6;
  --warn: #d97706;
  --hero: linear-gradient(135deg, #0f766e 0%, #0d9488 60%, #14b8a6 100%);
  --shadow: 0 1px 2px rgba(16, 32, 28, .04), 0 8px 28px rgba(16, 32, 28, .06);
  --radius: 22px;
  --tabbar-h: 68px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a100f;
    --surface: #121a18;
    --surface-2: #19231f;
    --text: #e7efec;
    --muted: #8fa19b;
    --border: #22302b;
    --accent: #2dd4bf;
    --accent-ink: #042f2a;
    --accent-soft: #0f302b;
    --in: #4ade80;
    --in-soft: #12301d;
    --out: #f87171;
    --out-soft: #391818;
    --hero: linear-gradient(135deg, #0b4f4a 0%, #0f766e 60%, #0d9488 100%);
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 Roboto, "HarmonyOS Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.error { color: var(--out); margin: 0; }

/* ---------- düymələr ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 10px 18px;
  min-height: 46px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--out); border-color: color-mix(in srgb, var(--out) 30%, var(--border)); }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 14px; border-radius: 11px; }
.btn.wide { width: 100%; margin-top: 12px; }
.icon-btn {
  border: 0; background: transparent; width: 44px; height: 44px; border-radius: 12px;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); font-size: 26px;
}
.icon-btn:hover, .icon-btn:active { background: var(--surface-2); color: var(--text); }
.link-btn { border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 600; padding: 2px 0; cursor: pointer; }

/* ---------- giriş ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 28px; padding: 36px 28px;
  box-shadow: var(--shadow); display: grid; gap: 12px; text-align: center;
}
.login-logo { width: 68px; height: 68px; margin: 0 auto; }
.login-card h1 { font-size: 28px; }
.login-card p { margin: 0 0 8px; }
.login-card input { text-align: center; }

input, textarea {
  width: 100%; border: 1.5px solid var(--border); background: var(--surface-2); border-radius: 14px;
  padding: 11px 14px; min-height: 48px; outline: none; transition: border-color .15s, background .15s, box-shadow .15s;
}
input:focus, textarea:focus {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent);
}
input.invalid { border-color: var(--out); box-shadow: 0 0 0 4px color-mix(in srgb, var(--out) 14%, transparent); }
textarea { resize: vertical; }

/* ---------- əsas çərçivə ---------- */
.app { min-height: 100vh; padding-bottom: calc(var(--tabbar-h) + 96px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  min-height: 64px; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 700; font-size: 18px; }
.brand-date { font-size: 13px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 4px; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.sync-dot.ok { background: var(--in); }
.sync-dot.busy { background: var(--accent); animation: pulse 1s infinite; }
.sync-dot.pending { background: var(--warn); }
.sync-dot.offline { background: var(--out); }
@keyframes pulse { 50% { opacity: .35; } }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  border: 0; background: none; display: grid; justify-items: center; align-content: center; gap: 3px;
  color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer;
}
.tab svg { width: 24px; height: 24px; padding: 3px 18px; box-sizing: content-box; border-radius: 16px; transition: background .15s; }
.tab.active { color: var(--accent); }
.tab.active svg { background: var(--accent-soft); }

.views { max-width: 1480px; margin: 0 auto; padding: 4px 12px 0; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.col { display: grid; gap: 14px; align-content: start; min-width: 0; }
.today-grid, .money-grid { display: grid; gap: 14px; }

.card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { font-size: 17px; }

/* ---------- ümumi pul ---------- */
.hero {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: var(--hero); color: #fff; border-radius: var(--radius); padding: 20px 22px; margin-bottom: 14px;
  box-shadow: 0 10px 30px rgba(15, 118, 110, .22);
}
.hero-main { display: grid; gap: 2px; min-width: 0; }
.hero-label { font-size: 14px; font-weight: 600; opacity: .85; }
.hero-amount { font-size: 34px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.15; }
.hero-sub { font-size: 13px; opacity: .85; font-variant-numeric: tabular-nums; }
.hero-edit {
  display: inline-flex; align-items: center; gap: 8px; border: 0; cursor: pointer; font-weight: 600;
  background: rgba(255, 255, 255, .18); color: #fff; padding: 10px 16px; border-radius: 14px; min-height: 44px;
  transition: background .15s;
}
.hero-edit:hover { background: rgba(255, 255, 255, .28); }

/* ---------- statistika ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface-2); border-radius: 16px; padding: 12px 14px; min-width: 0; }
.stat span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.stat b { display: block; font-size: 18px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.stat.net { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.stat.net b { font-size: 21px; }
.stat.in b { color: var(--in); }
.stat.out b { color: var(--out); }
.stat.net.neg b { color: var(--out); }

/* ---------- sürətli yazı ---------- */
.quick { margin: 16px 0 6px; container-type: inline-size; }
.quick-form { display: grid; gap: 10px; }
.quick-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.quick-fields .amt, .quick-fields .add-btn { grid-column: 1 / -1; }
.field { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); min-width: 0; }
.field input { color: var(--text); font-weight: 400; font-size: 16px; }
.field.amt input { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.add-btn { min-height: 48px; }
@container (min-width: 560px) {
  .quick-fields { grid-template-columns: 150px 1fr 1fr auto; }
  .quick-fields .amt, .quick-fields .add-btn { grid-column: auto; }
  .add-btn { padding: 10px 26px; }
}
.search { margin: 14px 0 4px; }

/* ---------- siyahılar ---------- */
.event-list, .tx-list, .people-list { list-style: none; margin: 0; padding: 0; }
.empty { color: var(--muted); font-size: 14px; padding: 10px 2px; }

.event {
  display: flex; gap: 12px; align-items: center; padding: 11px 14px; margin-top: 8px;
  border-radius: 14px; background: var(--surface-2); border-left: 4px solid var(--accent); cursor: pointer;
  transition: background .15s;
}
.event:hover { background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface-2)); }
.event.past { opacity: .55; border-left-color: var(--muted); }
.ev-time { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 50px; text-align: center; }
.ev-time small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
.ev-main { min-width: 0; }
.ev-title { font-weight: 600; overflow-wrap: anywhere; }
.ev-sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

.tx { display: flex; align-items: center; gap: 12px; padding: 11px 6px; border-radius: 12px; cursor: pointer; transition: background .15s; }
.tx + .tx { border-top: 1px solid var(--border); }
.tx:hover { background: var(--surface-2); }
.tx-icon { flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; }
.tx-icon.in { background: var(--in-soft); color: var(--in); }
.tx-icon.out { background: var(--out-soft); color: var(--out); }
.tx-main { flex: 1; min-width: 0; }
.tx-note { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 13px; color: var(--muted); }
.tx-amt { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx-amt.in, b.in { color: var(--in); }
.tx-amt.out, b.out { color: var(--out); }
.chip { display: inline-block; padding: 0 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px; cursor: pointer; }

.day-group { margin-top: 18px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-weight: 600; padding: 0 6px 6px; border-bottom: 1px solid var(--border); }

.people-list li { display: flex; align-items: center; gap: 12px; padding: 9px 6px; border-radius: 12px; cursor: pointer; transition: background .15s; }
.people-list li + li { border-top: 1px solid var(--border); }
.people-list li:hover { background: var(--surface-2); }
.people-list li.empty { cursor: default; }
.people-list li.empty:hover { background: none; }
.avatar { width: 36px; height: 36px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.pname { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pnums { display: grid; text-align: right; font-size: 14px; font-variant-numeric: tabular-nums; }

/* ---------- dövr seçimi ---------- */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); padding: 4px; border-radius: 14px; gap: 4px; }
.segmented button { border: 0; background: transparent; border-radius: 10px; padding: 9px 4px; font-weight: 600; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented button.active.in { color: var(--in); }
.segmented button.active.out { color: var(--out); }
.period-nav { display: flex; align-items: center; justify-content: space-between; margin: 12px 0; text-align: center; }
.period-label { font-weight: 700; }

/* ---------- həftə ---------- */
.week { display: grid; gap: 10px; }
.day { border: 1px solid var(--border); border-radius: 16px; padding: 12px 14px; background: var(--surface); }
.day.today { border-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
.day.past { opacity: .6; }
.day-title { display: flex; align-items: center; gap: 8px; }
.day-title > div { flex: 1; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.day-title span { color: var(--muted); font-size: 14px; }
.day-title em { font-style: normal; font-size: 12px; font-weight: 700; color: var(--accent-ink); background: var(--accent); padding: 2px 9px; border-radius: 999px; }
.add-day { border: 0; width: 34px; height: 34px; border-radius: 11px; background: var(--surface-2); color: var(--accent); font-size: 22px; cursor: pointer; flex: none; }
.add-day:hover { background: var(--accent-soft); }
.day.free .free-note { padding: 4px 0 0; cursor: pointer; }

/* ---------- üzən düymə ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 25;
  width: 60px; height: 60px; border-radius: 20px; border: 0; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 10px 28px rgba(15, 118, 110, .38); display: grid; place-items: center; cursor: pointer;
  transition: transform .1s;
}
.fab:active { transform: scale(.94); }

/* ---------- pəncərə ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; display: grid; align-items: end; justify-items: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(5, 15, 13, .45); opacity: 0; transition: opacity .2s; backdrop-filter: blur(2px); }
.sheet-panel {
  position: relative; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; background: var(--surface);
  border-radius: 28px 28px 0 0; padding: 8px 22px calc(22px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .22s ease;
}
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet.open .sheet-panel { transform: none; }
.sheet-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: 0 auto 16px; }
.sheet h2 { font-size: 21px; margin-bottom: 16px; }
.sheet h3 { font-size: 15px; margin: 12px 0 0; }

.form { display: grid; gap: 14px; }
.form.tight { gap: 10px; }
.form label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.form label input, .form label textarea { color: var(--text); font-weight: 400; font-size: 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-btn { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 7px 15px; font-size: 14px; cursor: pointer; }
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.form-actions .danger { margin-right: auto; }
.set-line { display: flex; align-items: center; gap: 10px; }
.set-state { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; flex: none; font-size: 14px; }
.set-state.ok { background: var(--in-soft); color: var(--in); }
.set-state.bad { background: var(--out-soft); color: var(--out); }
.set-label { flex: 1; font-size: 14px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 92px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 12px); opacity: 0; transition: .2s; display: flex; align-items: center; gap: 14px;
  background: #16211f; color: #fff; padding: 11px 18px; border-radius: 14px; max-width: calc(100% - 32px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); font-size: 14px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast button { border: 0; background: none; color: #5eead4; font-weight: 700; cursor: pointer; padding: 4px; }

/* ---------- planşet və kompüter ---------- */
@media (min-width: 760px) {
  :root { --tabbar-h: 0px; }
  .app { padding-bottom: 40px; }
  .topbar { padding-left: 24px; padding-right: 24px; }
  /* bölmələr yuxarı paneldə, ortada */
  .tabs {
    position: fixed; top: calc(9px + env(safe-area-inset-top)); bottom: auto; left: 50%; right: auto; z-index: 40;
    transform: translateX(-50%); width: min(480px, calc(100% - 380px)); height: auto;
    border: 1px solid var(--border); border-radius: 16px; padding: 4px; gap: 4px; background: var(--surface);
    backdrop-filter: none;
  }
  .tab { grid-auto-flow: column; gap: 8px; font-size: 15px; padding: 8px; border-radius: 12px; }
  .tab svg { padding: 0; width: 20px; height: 20px; background: none !important; }
  .tab:hover { color: var(--text); }
  .tab.active { background: var(--accent-soft); color: var(--accent); }
  .views { padding: 8px 24px 0; }
  .today-grid, .money-grid { grid-template-columns: 1fr 1fr; align-items: start; gap: 18px; }
  .col { gap: 18px; }
  .card { padding: 22px; }
  .hero { padding: 26px 30px; margin-bottom: 18px; }
  .hero-amount { font-size: 44px; }
  .fab { bottom: 28px; right: 28px; }
  .toast { bottom: 104px; }
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 28px; padding: 26px 28px; }
  .sheet-grip { display: none; }
}

@media (min-width: 1100px) {
  .views { padding: 8px 32px 0; }
  .money-grid { grid-template-columns: 420px 1fr; }
  .week { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .day { min-height: 260px; padding: 12px; }
  .day-title { align-items: flex-start; }
  .day-title > div { flex-direction: column; gap: 0; }
  .day-title em { display: none; }
  .day .event { flex-direction: column; align-items: flex-start; gap: 2px; border-left-width: 3px; padding: 8px 10px; }
  .day .ev-time { text-align: left; min-width: 0; }
}
