* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #f1f3f6;
  color: #1c2733;
}
.hidden { display: none !important; }
.muted { color: #77828f; font-size: 13px; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card { width: 340px; display: flex; flex-direction: column; gap: 12px; padding: 28px; }
.login-card h1 { font-size: 20px; text-align: center; margin: 0 0 8px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: #143a5c;
  color: #fff;
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 17px; }
#nav { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.nav-btn {
  background: transparent;
  border: none;
  color: #cfe0ef;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.nav-btn:hover { background: rgba(255,255,255,.1); }
.nav-btn.active { background: #fff; color: #143a5c; font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 14px; }

main { padding: 20px; max-width: 1100px; margin: 0 auto; }
.page h2 { font-size: 18px; margin: 20px 0 10px; }

.card {
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(16,40,66,.08);
  margin-bottom: 14px;
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.store-card .store-name { font-size: 14px; color: #55616e; margin-bottom: 6px; }
.store-card .store-bal { font-size: 20px; font-weight: 700; }
.store-card.total { background: #e8f3fb; }
.neg { color: #c0262f; }
.pos { color: #1d7a3e; }
.loan-card { font-size: 14px; }

.form-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.form-grid input, .form-grid select {
  padding: 10px 12px;
  border: 1px solid #c8d2dc;
  border-radius: 8px;
  font-size: 14px;
  min-width: 140px;
  flex: 1;
}
.lbl { font-size: 13px; color: #55616e; }

.btn {
  border: 1px solid #c8d2dc;
  background: #fff;
  color: #1c2733;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: #f4f7fa; }
.btn.primary { background: #1d6fb8; border-color: #1d6fb8; color: #fff; }
.btn.primary:hover { background: #185f9f; }
.btn.danger { color: #c0262f; border-color: #e5b9bd; }
.btn.small { padding: 5px 10px; font-size: 13px; }

.err { color: #c0262f; font-size: 14px; min-height: 18px; margin: 6px 0; }

.hint {
  font-size: 13px;
  color: #55616e;
  background: #f4f7fa;
  border: 1px solid #e7ecf1;
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 18px;
  margin: 4px 0 2px;
  white-space: normal;
}
.hint b { color: #1c2733; }

.table-wrap { overflow-x: auto; background: #fff; border-radius: 10px; box-shadow: 0 1px 3px rgba(16,40,66,.08); }
.table-wrap.small { max-height: 340px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid #e7ecf1; white-space: nowrap; line-height: 1.5; }
th { background: #f7fafc; color: #55616e; font-weight: 600; font-size: 13px; }
tr:last-child td { border-bottom: none; }

.badge { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.on { background: #fdf3d8; color: #8a6a00; }
.badge.off { background: #e3f2e6; color: #1d7a3e; }

#loan-table tbody tr.overdue { background: #fff7e0; }
#loan-table tbody tr.overdue td { border-bottom-color: #f3e3b0; }
.loan-card.overdue-card { background: #fff7e0; border: 1px solid #eedc9d; }
#dl-backup { margin-top: 4px; }
#logout-all-btn { margin-top: 8px; }

.chk { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; padding: 4px 0; }
.chk input { width: 18px; height: 18px; }

td.wrap { white-space: normal; word-break: break-word; min-width: 320px; }

.loan-detail td { background: #f7fafc; padding: 8px 16px; }
.inner { width: auto; min-width: 300px; font-size: 13px; }
.inner th, .inner td { padding: 6px 12px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.two-col > .card { min-width: 0; }
.two-col .card { margin-bottom: 0; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
#store-table, #user-table { width: 100%; }

@media (max-width: 760px) {
  .two-col { grid-template-columns: 1fr; }
  body { padding-bottom: 84px; }
  main { padding: 12px 12px 8px; }
  .topbar { padding: 10px 12px; gap: 8px; }
  .brand { font-size: 15px; }
  .userbox { font-size: 13px; margin-left: auto; }
  #nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #143a5c;
    display: flex;
    gap: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 10px rgba(16,40,66,.25);
    z-index: 50;
  }
  .nav-btn {
    flex: 1;
    text-align: center;
    padding: 12px 4px;
    font-size: 13px;
    white-space: nowrap;
  }
  .page h2 { font-size: 16px; margin: 16px 0 8px; }
  .form-grid { gap: 8px; }
  .form-grid input, .form-grid select { min-width: 100%; font-size: 16px; padding: 12px; }
  .form-grid .btn { flex: 1 1 100%; padding: 13px; font-size: 16px; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .store-card { padding: 12px; }
  .store-card .store-name { font-size: 13px; }
  .store-card .store-bal { font-size: 16px; }
  .loan-card { font-size: 13px; }
  .btn { padding: 12px 14px; }
  .btn.small { padding: 8px 12px; font-size: 14px; }
  .login-card { width: calc(100% - 32px); max-width: 340px; }
  .lbl { width: 100%; font-size: 12px; }

  .table-wrap { overflow: visible; background: transparent; box-shadow: none; }
  .table-wrap.small { max-height: none; overflow-y: visible; }
  .table-wrap > table { display: block; }
  .table-wrap > table > thead { display: none; }
  .table-wrap > table > tbody { display: block; }
  .table-wrap > table > tbody > tr {
    display: block;
    background: #fff;
    border-radius: 12px;
    padding: 8px 14px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(16,40,66,.08);
  }
  .table-wrap > table > tbody > tr.loan-detail { background: transparent; box-shadow: none; padding: 0 0 4px; margin: -4px 0 10px; }
  .table-wrap > table > tbody > tr > td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    border: none;
    padding: 6px 0;
    white-space: normal;
    text-align: right;
  }
  .table-wrap > table > tbody > tr > td:first-child { padding-top: 8px; }
  .table-wrap > table > tbody > tr.loan-detail > td { display: block; text-align: left; }
  .table-wrap td::before { content: attr(data-label); color: #77828f; font-size: 12px; flex-shrink: 0; text-align: left; }
  .table-wrap td.pos::before, .table-wrap td.neg::before { color: #77828f; }
  .table-wrap tr.loan-detail td::before { display: none; }
  .inner th, .inner td { padding: 6px 12px; }
}

.zero-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  color: #55616e;
  font-size: 14px;
  border: 1px dashed #c8d2dc;
  box-shadow: none;
}
.zero-grid { margin-top: 8px; }
.zero-grid .store-card.zero { box-shadow: none; border: 1px solid #e7ecf1; }
.zero-grid .store-bal { font-size: 14px; color: #55616e; }

.debt-card .store-name { margin-bottom: 6px; }
.debt-row { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; color: #55616e; }
.debt-row b { color: #1c2733; }
#set-card .chk { margin-bottom: 10px; }
#dl-backup { margin-top: 4px; }
