:root {
  --bg: #f3f6f5;
  --bg-soft: #e8efed;
  --panel: #ffffff;
  --text: #1c2b28;
  --muted: #6b7c77;
  --line: #d7e2de;
  --brand: #1f6f63;
  --brand-2: #2a8a7b;
  --brand-soft: #e4f3ef;
  --income: #1f7a4d;
  --expense: #b24a3c;
  --warn: #b7791f;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(28, 43, 40, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --side: 248px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
[hidden] { display: none !important; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d9ebe6 0%, transparent 55%),
    radial-gradient(900px 420px at 100% 0%, #e7eef3 0%, transparent 50%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-wrap { width: min(420px, 100%); }
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}
.login-brand h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.02em;
}
.login-brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}
.login-form label {
  display: block;
  margin-bottom: 14px;
}
.login-form label span,
.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
.login-form input,
.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcfc;
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-form input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: #7bb5aa;
  box-shadow: 0 0 0 3px rgba(31, 111, 99, 0.12);
  background: #fff;
}
.field textarea { min-height: 84px; resize: vertical; }
.field textarea[name="project_name"] { min-height: 96px; }

.cat-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}
.cat-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.cat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.cat-row:last-child { border-bottom: none; }
.cat-name-wrap { min-width: 0; }
.cat-input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcfc;
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
}
.cat-input:focus {
  border-color: #7bb5aa;
  box-shadow: 0 0 0 3px rgba(31, 111, 99, 0.12);
  background: #fff;
}
.cat-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.cat-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}
@media (max-width: 520px) {
  .cat-row {
    grid-template-columns: 1fr;
  }
  .cat-actions {
    justify-content: flex-end;
  }
}
.form-error {
  color: var(--danger);
  background: #fef3f2;
  border: 1px solid #f5c2c0;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 12px;
  font-size: 13px;
}

.app {
  display: grid;
  grid-template-columns: var(--side) 1fr;
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: rgba(255,255,255,.86);
  backdrop-filter: blur(10px);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 10px;
}
.sidebar-brand strong {
  font-size: 17px;
  letter-spacing: -0.02em;
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  color: var(--muted);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--bg-soft); color: var(--text); }
.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand);
}
.sidebar-foot { display: grid; gap: 10px; }
.user-chip {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}
.user-chip strong { display: block; font-size: 14px; }
.user-chip small { color: var(--muted); }

.main {
  min-width: 0;
  padding: 22px 24px 40px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.mobile-only { display: none; }
.topbar h2 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.03em;
}
.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}
.content { display: grid; gap: 16px; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--bg-soft);
  color: var(--text);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .1s, background .15s, opacity .15s;
}
.btn:hover { filter: brightness(0.98); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: #fef3f2; color: var(--danger); border-color: #f5c2c0; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 10px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  display: grid;
  place-items: center;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat .label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}
.stat .value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.stat.income .value { color: var(--income); }
.stat.expense .value { color: var(--expense); }
.stat.profit .value { color: var(--brand); }
.stat.profit {
  background: linear-gradient(180deg, #eef8f5 0%, #ffffff 70%);
  border-color: #c5e4dc;
}
.stat .sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}
.period-bar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  gap: 12px;
}
.period-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.period-tab {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
}
.period-tab.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.period-custom {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.period-custom.is-hidden { display: none; }
.period-custom input[type="date"] {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 9px 11px;
}
.period-sep { color: var(--muted); font-size: 13px; }
.period-hint {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h3 {
  margin: 0;
  font-size: 16px;
}
.panel-body { padding: 8px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.toolbar input,
.toolbar select {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 9px 11px;
  min-width: 140px;
}

.list {
  display: grid;
  gap: 8px;
}
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.item:hover {
  background: #f7faf9;
  border-color: var(--line);
}
.item-main { min-width: 0; }
.item-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-weight: 600;
}
.item-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}
.item-side {
  text-align: right;
  display: grid;
  align-content: center;
  gap: 6px;
}
.amount { font-weight: 700; letter-spacing: -0.02em; }
.amount.plus { color: var(--income); }
.amount.minus { color: var(--expense); }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-soft);
  color: var(--muted);
}
.badge.warn { background: #fff7e8; color: var(--warn); }
.badge.danger { background: #fef3f2; color: var(--danger); }
.badge.ok { background: #eaf7ef; color: var(--income); }
.badge.info { background: var(--brand-soft); color: var(--brand); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 16px;
}
.empty svg { margin-bottom: 8px; opacity: .7; }

.grid-2 {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 16px;
}
.alert-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
}
.alert-row:hover { background: #f7faf9; }
.alert-row .left { min-width: 0; }
.alert-row strong { display: block; font-size: 14px; }
.alert-row small { color: var(--muted); }

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 32, 29, 0.42);
  display: grid;
  place-items: end center;
  padding: 0;
  z-index: 50;
}
.modal {
  width: min(720px, 100%);
  max-height: min(92vh, 900px);
  background: #fff;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 40px rgba(0,0,0,.15);
}
.modal-head, .modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-foot {
  border-bottom: none;
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body {
  padding: 16px;
  overflow: auto;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }
.field { display: block; }

.files {
  display: grid;
  gap: 8px;
}
.file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfc;
}
.file-row a { color: var(--brand); font-weight: 500; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  background: #17332e;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 80;
  box-shadow: var(--shadow);
}

.mobile-nav { display: none; }

@media (min-width: 901px) {
  .modal-mask { place-items: center; padding: 24px; }
  .modal { border-radius: 18px; }
}

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-only { display: grid; }
  .main {
    padding: 16px 14px calc(88px + var(--safe-b));
  }
  .topbar h2 { font-size: 22px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + var(--safe-b));
    z-index: 40;
  }
  .mobile-nav a {
    display: grid;
    place-items: center;
    gap: 2px;
    color: var(--muted);
    font-size: 11px;
    padding: 6px 2px;
  }
  .mobile-nav a.active { color: var(--brand); font-weight: 600; }
}

@media (max-width: 520px) {
  .item {
    grid-template-columns: 1fr;
  }
  .item-side {
    text-align: left;
    grid-auto-flow: column;
    justify-content: space-between;
    align-items: center;
  }
}
