:root {
  --blue: #2563EB;
  --blue-dark: #1D4ED8;
  --green: #16A34A;
  --green-bg: #DCFCE7;
  --red: #DC2626;
  --red-bg: #FEE2E2;
  --bg: #F1F5F9;
  --card: #FFFFFF;
  --text: #0F172A;
  --muted: #64748B;
  --border: #E2E8F0;
  --radius: 16px;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: contain;
}

#app { min-height: 100%; display: flex; flex-direction: column; }

.screen { flex: 1; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* Header */
.appbar {
  background: var(--blue);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 16px) 16px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.appbar h1 { font-size: 18px; margin: 0; font-weight: 700; flex: 1; }
.appbar .back {
  background: rgba(255,255,255,.18);
  border: none; color: #fff; width: 36px; height: 36px;
  border-radius: 10px; font-size: 20px; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
}
.appbar .logout {
  background: rgba(255,255,255,.18); border: none; color: #fff;
  padding: 8px 12px; border-radius: 10px; font-size: 13px; cursor: pointer;
}

.content { padding: 16px; flex: 1; overflow-y: auto; }

/* Login */
.login-wrap {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: 24px; background: linear-gradient(160deg, var(--blue), var(--blue-dark));
}
.login-card {
  background: var(--card); border-radius: 20px; padding: 28px 22px;
  box-shadow: var(--shadow);
}
.login-logo {
  width: 72px; height: 72px; border-radius: 20px; margin: 0 auto 16px;
  display: block;
}
.login-card h2 { text-align: center; margin: 0 0 4px; font-size: 22px; }
.login-card p.sub { text-align: center; color: var(--muted); margin: 0 0 22px; font-size: 14px; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; padding: 14px; border: 1.5px solid var(--border);
  border-radius: 12px; font-size: 16px; background: #fff; color: var(--text);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); }
textarea { resize: vertical; min-height: 70px; }

.btn {
  width: 100%; padding: 15px; border: none; border-radius: 12px;
  font-size: 16px; font-weight: 700; cursor: pointer; margin-top: 18px;
  background: var(--blue); color: #fff; transition: opacity .15s;
}
.btn:active { opacity: .85; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.green { background: var(--green); }
.btn.red { background: var(--red); }

.error-msg {
  background: var(--red-bg); color: var(--red); padding: 12px 14px;
  border-radius: 10px; font-size: 14px; margin-top: 14px; display: none;
}
.error-msg.show { display: block; }

/* Home tiles */
.hello { color: var(--muted); font-size: 14px; margin: 4px 0 18px; }
.tiles { display: flex; flex-direction: column; gap: 14px; }
.tile {
  display: flex; align-items: center; gap: 16px; padding: 20px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: none; width: 100%; text-align: left; cursor: pointer;
}
.tile:active { transform: scale(.99); }
.tile .ico {
  width: 52px; height: 52px; border-radius: 14px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 26px;
}
.tile.in .ico { background: var(--green-bg); }
.tile.out .ico { background: var(--red-bg); }
.tile.rep .ico { background: #DBEAFE; }
.tile .txt strong { display: block; font-size: 17px; color: var(--text); }
.tile .txt span { font-size: 13px; color: var(--muted); }

/* Report */
.summary { display: flex; gap: 12px; margin-bottom: 16px; }
.sumcard {
  flex: 1; background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); text-align: center;
}
.sumcard .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sumcard .val { font-size: 18px; font-weight: 800; margin-top: 6px; }
.sumcard.in .val { color: var(--green); }
.sumcard.out .val { color: var(--red); }
.balance {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); text-align: center; margin-bottom: 16px;
}
.balance .lbl { font-size: 13px; color: var(--muted); }
.balance .val { font-size: 28px; font-weight: 800; margin-top: 4px; }

.filters { display: flex; gap: 10px; margin-bottom: 16px; }
.filters select { flex: 1; padding: 10px; font-size: 14px; }

.op-list { display: flex; flex-direction: column; gap: 10px; }
.op {
  display: flex; align-items: center; gap: 12px; background: var(--card);
  border-radius: 12px; padding: 14px; box-shadow: var(--shadow);
}
.op .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.op.in .dot { background: var(--green); }
.op.out .dot { background: var(--red); }
.op .info { flex: 1; min-width: 0; }
.op .info strong { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op .info span { font-size: 12px; color: var(--muted); }
.op .amt { font-weight: 700; font-size: 15px; white-space: nowrap; }
.op.in .amt { color: var(--green); }
.op.out .amt { color: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%) translateY(100px);
  background: var(--text); color: #fff; padding: 12px 20px; border-radius: 30px;
  font-size: 14px; box-shadow: var(--shadow); opacity: 0; transition: all .25s;
  z-index: 100; max-width: 90%; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

.hint {
  font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.5;
}
.spinner {
  display: inline-block; width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-full {
  flex: 1; display: flex; align-items: center; justify-content: center;
}
.loading-full .spinner { border-color: rgba(37,99,235,.25); border-top-color: var(--blue); width: 34px; height: 34px; }
