:root {
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #F6F5F9;
  --text: #1A1020;
  --muted: #8A849A;
  --line: #EFEDF3;
  --primary: #4A55EC;
  --primary-soft: #EEEFFE;
  --primary-dark: #333DBF;
  --in: #12855F;
  --in-soft: #E4F5EE;
  --out: #D2454B;
  --out-soft: #FCEAEA;
  --warn: #B45309;
  --radius: 24px;
  --radius-sm: 14px;
  --pill: 100px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Poppins, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-height: 72px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--text);
  font-size: 1.2rem;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand span { color: var(--primary); }

.nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }

.nav a {
  padding: .5rem 1rem;
  border-radius: var(--pill);
  color: var(--muted);
  font-weight: 500;
  font-size: .92rem;
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }

.topbar form { margin: 0; }

main { max-width: 1080px; margin: 0 auto; padding: 1.25rem 24px 4rem; }

h1 { font-size: 1.9rem; font-weight: 600; margin: 0 0 .25rem; letter-spacing: -.025em; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 1.25rem; letter-spacing: -.01em; }
.sub { color: var(--muted); font-size: .95rem; margin: 0 0 1.75rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem 1.6rem;
  margin-bottom: 1rem;
}

.card.stat {
  background: var(--surface-2);
  border: 0;
}

.grid { display: grid; gap: 1rem; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: 1.55fr minmax(0, 1fr); }

.stat .label {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .09em;
}
.stat .value { font-size: 1.85rem; font-weight: 600; letter-spacing: -.03em; margin-top: .5rem; }
.stat .foot { color: var(--muted); font-size: .82rem; margin-top: .15rem; }

.in { color: var(--in); }
.out { color: var(--out); }

.period {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.period .label { font-weight: 500; min-width: 150px; }
.period .btn-sm { width: 36px; height: 36px; padding: 0; border-radius: 50%; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--pill); padding: 4px; margin-left: auto; }
.seg a { padding: .45rem 1.15rem; border-radius: var(--pill); font-size: .86rem; font-weight: 500; color: var(--muted); }
.seg a:hover { text-decoration: none; color: var(--text); }
.seg a.active { background: var(--surface); color: var(--text); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: var(--pill);
  padding: .55rem 1.25rem;
  font-size: .88rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-sm { padding: .4rem 1rem; font-size: .82rem; }
.btn-danger { color: var(--out); }
.btn-danger:hover { background: var(--out-soft); color: var(--out); }

input, select, textarea {
  font-family: inherit;
  font-size: .9rem;
  padding: .6rem .85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 3px solid var(--primary-soft);
  border-color: var(--primary);
}
label { font-size: .8rem; font-weight: 500; color: var(--muted); display: block; margin-bottom: .3rem; }
input[type="color"] {
  display: block;
  width: 42px;
  height: 42px;
  min-width: 42px;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--line);
}
input[type="color"]:hover { box-shadow: 0 0 0 1px var(--muted); }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 50%;
}
input[type="color"]::-moz-color-swatch {
  border: 0;
  border-radius: 50%;
}
input[type="color"]:focus {
  outline: 3px solid var(--primary-soft);
  outline-offset: 2px;
  border: 0;
}

.form-row { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.form-row > div { flex: 1; min-width: 130px; }
.form-row > div.shrink { flex: 0 0 auto; min-width: 0; }

.tx { list-style: none; margin: 0; padding: 0; }

.tx li {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .9rem 2px;
  border-bottom: 1px solid var(--line);
}
.tx li:last-child { border-bottom: 0; }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }

.tx .body { flex: 1; min-width: 0; }
.tx .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .meta { color: var(--muted); font-size: .8rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .1rem; }
.tx .raw { color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tx .amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; text-align: right; }

.pill {
  font-size: .73rem;
  font-weight: 500;
  padding: .15rem .65rem;
  border-radius: var(--pill);
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.pill.edited { background: var(--primary-soft); color: var(--primary); }
.pill.pending { background: var(--out-soft); color: var(--out); }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 150px; margin-top: .5rem; }
.bars .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; min-width: 0; }
.bars .bar-out { background: var(--out); border-radius: 5px 5px 0 0; min-height: 1px; }
.bars .bar-in { background: var(--in); border-radius: 5px 5px 0 0; min-height: 1px; }
.bars .tick { font-size: .62rem; color: var(--muted); text-align: center; overflow: hidden; }

.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); margin-top: .75rem; flex-wrap: wrap; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: .35rem; }

.catline { display: flex; align-items: center; gap: .7rem; padding: .6rem 0; }
.catline .name { flex: 0 0 34%; display: flex; align-items: center; gap: .55rem; min-width: 0; }
.catline .name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catline .track { flex: 1; background: var(--surface-2); border-radius: var(--pill); height: 8px; overflow: hidden; }
.catline .fill { height: 100%; border-radius: var(--pill); }
.catline .val { font-variant-numeric: tabular-nums; font-size: .86rem; font-weight: 500; white-space: nowrap; }

.progress { background: var(--surface-2); border-radius: var(--pill); height: 9px; overflow: hidden; margin: .5rem 0 .35rem; }
.progress .fill { height: 100%; background: var(--primary); border-radius: var(--pill); }
.progress .fill.over { background: var(--out); }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: .73rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  padding: 0 .5rem .65rem;
}
td { padding: .7rem .5rem; border-top: 1px solid var(--line); vertical-align: middle; }

.empty { color: var(--muted); text-align: center; padding: 2.25rem .75rem; }
.empty strong { display: block; color: var(--text); font-weight: 500; margin-bottom: .35rem; }

.alert { border-radius: var(--radius-sm); padding: .85rem 1.1rem; margin-bottom: 1rem; font-size: .9rem; }
.alert-ok { background: var(--in-soft); color: var(--in); }
.alert-bad { background: var(--out-soft); color: var(--out); }
.alert-info { background: var(--primary-soft); color: var(--primary); }

details.inline summary { cursor: pointer; color: var(--muted); font-size: .8rem; font-weight: 500; list-style: none; }
details.inline summary::-webkit-details-marker { display: none; }
details.inline summary:hover { color: var(--primary); }
details.inline .panel { margin-top: .6rem; padding: 1rem; background: var(--surface-2); border-radius: var(--radius-sm); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; padding: 2rem 2rem 2.25rem; }
.login-card .brand { font-size: 1.5rem; display: block; margin-bottom: .25rem; }
.login-card .field { margin-bottom: .9rem; }
.login-card .btn { width: 100%; }

@media (max-width: 860px) {
  .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .catline .name { flex-basis: 45%; }
  .bars { height: 110px; }
}

@media (max-width: 560px) {
  main { padding: 1rem 16px 3rem; }
  .topbar-inner { min-height: 0; padding: .7rem 16px; gap: .6rem; row-gap: .5rem; }
  .brand { flex: 1; }
  .nav {
    order: 3;
    flex: 0 0 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: .25rem;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }

  .tx li { flex-wrap: wrap; row-gap: .25rem; align-items: flex-start; }
  .dot { margin-top: 7px; }
  .tx .body { flex: 1 1 auto; width: calc(100% - 80px); }
  .tx .amount { flex: 0 0 auto; margin-left: auto; }

  h1 { font-size: 1.55rem; }
  .stat .value { font-size: 1.5rem; }
  .period .label { min-width: 100%; }
  .seg { margin-left: 0; }
}
