:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --green-bg: #e8f8ee;
  --red: #dc2626;
  --red-bg: #fdecec;
  --border: #e5e7eb;
  --radius: 10px;
  --nav-h: 62px;
  --top-h: 54px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--top-h);
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 20;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.logout-btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

.app-content {
  padding: 12px 12px calc(var(--nav-h) + 20px) 12px;
  margin-top: var(--top-h);
  min-height: calc(100vh - var(--top-h) - var(--nav-h));
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}
.bottomnav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
  gap: 2px;
}
.bottomnav a.active { color: var(--primary); font-weight: 600; }
.bottomnav .icon { font-size: 20px; line-height: 1; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid var(--border);
}

.card h3 { margin: 0 0 10px 0; font-size: 15px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--border);
  text-align: center;
}
.stat .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat .value { font-size: 18px; font-weight: 700; }

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 4px;
}
input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }

.btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn:active { background: var(--primary-dark); }
.btn.secondary { background: #eef1f5; color: var(--text); }
.btn.danger { background: var(--red-bg); color: var(--red); }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn.small { padding: 6px 10px; font-size: 12px; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.tab {
  padding: 8px 14px;
  border-radius: 20px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  color: var(--muted);
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); font-weight: 600; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}
.badge.cr { background: var(--green-bg); color: var(--green); }
.badge.dr { background: var(--red-bg); color: var(--red); }
.badge.draft { background: #fff4e0; color: #b45309; }
.badge.posted { background: var(--green-bg); color: var(--green); }

.row-flex { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.muted { color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 14px; }

.client-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.client-header .name { font-weight: 700; font-size: 15px; }
.userid-item {
  border-top: 1px dashed var(--border);
  padding: 8px 0;
  font-size: 13px;
}
.userid-item .top-row { display: flex; justify-content: space-between; font-weight: 600; }
.terms { color: var(--muted); font-size: 11.5px; margin-top: 2px; line-height: 1.5; }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--nav-h) + 14px);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 26px;
  border: none;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  z-index: 15;
  cursor: pointer;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-sheet {
  background: #fff;
  width: 100%;
  max-width: 720px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 16px;
}
.modal-sheet h3 { margin-top: 0; }
.modal-close-row { display:flex; justify-content: flex-end; }

.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 14px);
  left: 50%;
  transform: translateX(-50%);
  background: #1c1e21;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 50;
}
.toast.show { opacity: 1; }

.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 16px 0 8px; text-transform: uppercase; letter-spacing: 0.03em; }

.hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

.dim-section { opacity: 0.55; }
.dim-section label, .dim-section .section-title { color: var(--muted); }
