:root {
  --bg: #0B0F1A;
  --panel: #131A2A;
  --panel-2: #1A2236;
  --border: #262F45;
  --text: #E9ECF4;
  --muted: #8B93AC;
  --amber: #E8A33D;
  --amber-dim: #4A3A1F;
  --teal: #45B8AC;
  --teal-dim: #1B3A37;
  --red: #E2605A;
  --red-dim: #3A2222;
  --blue: #5B8DEF;
  --mono: 'JetBrains Mono', monospace;
  --display: 'Space Grotesk', sans-serif;
  --body: 'Inter', sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
}

a {
  color: inherit;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */

.sidebar {
  width: 220px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  flex-shrink: 0;
}

.brand {
  font-family: var(--display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.3px;
  padding: 0 8px 22px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.brand span {
  color: var(--amber);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  transition: background .15s, color .15s;
}

.nav-item:hover {
  background: var(--panel-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--panel-2);
  color: var(--amber);
}

.nav-ico {
  width: 16px;
  text-align: center;
  font-size: 15px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.ghost-btn {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 6px;
  font-family: var(--body);
}

.ghost-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

/* MAIN */

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 32px 60px 32px;
}

.topline {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 14px;
}

.topline h1 {
  font-family: var(--display);
  font-size: 24px;
  margin: 0;
  font-weight: 600;
}

.topline .sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.strip {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  min-width: 150px;
}

.stat .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.stat .value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  margin-top: 4px;
}

.stat .value.amber {
  color: var(--amber);
}

.stat .value.red {
  color: var(--red);
}

.stat .value.teal {
  color: var(--teal);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.panel h2 {
  font-family: var(--display);
  font-size: 16px;
  margin: 0 0 14px 0;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel h2 .h2-actions {
  display: flex;
  gap: 8px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* CALENDAR */

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.cal-head .month-label {
  font-family: var(--display);
  font-size: 15px;
  font-weight: 600;
}

.cal-nav button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 28px;
  height: 28px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
}

.cal-nav button:hover {
  border-color: var(--amber);
  color: var(--amber);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7,1fr);
  gap: 6px;
}

.cal-dow {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.cal-cell {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 78px;
  padding: 6px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cal-cell.other-month {
  opacity: .35;
}

.cal-cell.today {
  border-color: var(--blue);
}

.cal-date {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.cal-cell.today .cal-date {
  color: var(--blue);
  font-weight: 700;
}

.cal-chip {
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 5px;
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.cal-chip.due {
  background: var(--amber-dim);
  color: var(--amber);
  border: 1px solid #6b5327;
}

.cal-chip.overdue {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid #6b3838;
}

.cal-chip.paid {
  background: var(--teal-dim);
  color: var(--teal);
  border: 1px solid #2c5e57;
}

.legend {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

/* TABLES */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

td.num, th.num {
  font-family: var(--mono);
  text-align: left;
}

.val {
  max-width: 80px;
}

input, select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  font-family: var(--body);
}

input.mono, td input, td select {
  font-family: var(--mono);
  width: 100%;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--amber);
}

.btn {
  background: var(--amber);
  color: #231604;
  border: none;
  padding: 8px 14px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--body);
}

.btn:hover {
  filter: brightness(1.08);
}

.btn.secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid #6b3838;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
}

.icon-btn:hover {
  color: var(--red);
}

.row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit,minmax(140px,1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.form-grid label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 20px;
  font-weight: 600;
}

.badge.charge {
  background: var(--red-dim);
  color: var(--red);
}

.badge.payment {
  background: var(--teal-dim);
  color: var(--teal);
}

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

::-webkit-scrollbar {
  height: 8px;
  width: 8px;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.d-none {
  display: none;
}

#nua-overlay.show, #nua-stdv.show {
  opacity: 1;
}

/* ==========================================================
   MOBILE APP SHELL
   Bottom tab bar + sticky app-bar header + slide-up sheet,
   matching native iOS/Android navigation conventions.
========================================================== */

body {
  -webkit-tap-highlight-color: transparent;
}

button, .nav-item, .btn, .icon-btn, .ghost-btn {
  touch-action: manipulation;
}

@media (max-width: 1000px) {
  .app {
    flex-direction: column;
  }
}

/* Sticky app-bar: the existing .topline becomes the native-style header */

@media (max-width: 1000px) {
  .topline {
    position: sticky;
    top: 0;
    z-index: 30;
    margin: -18px -18px 16px -18px;
    padding: max(14px, env(safe-area-inset-top)) 18px 14px 18px;
    background: rgba(11, 15, 26, 0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    align-items: center;
  }
}

@media (max-width: 1000px) {
  .topline h1 {
    font-size: 19px;
  }
}

@media (max-width: 1000px) {
  .main {
    padding: 18px 18px calc(84px + env(safe-area-inset-bottom)) 18px;
  }
}

/* Stat strip becomes a fixed 2-column grid — all 4 cards fit the screen, no scrolling */

@media (max-width: 1000px) {
  .strip {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 0;
    padding: 0;
  }
}

@media (max-width: 1000px) {
  .stat {
    min-width: 0;
    padding: 10px 12px;
  }
}

@media (max-width: 1000px) {
  .stat .label {
    font-size: 10px;
  }
}

@media (max-width: 1000px) {
  .stat .value {
    font-size: 16px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Tables scroll horizontally inside their panel instead of blowing out the layout */

@media (max-width: 1000px) {
  .panel > div:has(table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Bottom tab bar */

@media (max-width: 1000px) {
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-evenly;
    padding: 6px 4px max(6px, env(safe-area-inset-bottom)) 4px;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 50;
  }
}

@media (max-width: 1000px) {
  .brand {
    display: none;
  }
}

@media (max-width: 1000px) {
  .nav-item {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    font-size: 10px;
    padding: 6px 4px;
    margin-bottom: 0;
    border-radius: 10px;
  }
}

@media (max-width: 1000px) {
  .nav-item .nav-ico {
    font-size: 18px;
    width: auto;
  }
}

/* Secondary actions (export/import/reset/logout) move into a slide-up sheet,
     opened via the "More" tab appended in HTML — keeps original IDs intact
     so credit.js's existing getElementById wiring needs no changes. */

@media (max-width: 1000px) {
  .sidebar-footer {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 18px 18px 0 0;
    padding: 10px 16px calc(20px + env(safe-area-inset-bottom)) 16px;
    transform: translateY(110%);
    transition: transform .25s ease;
    z-index: 70;
    margin-top: 0;
    padding-top: 10px;
    border-top: none;
  }
}

@media (max-width: 1000px) {
  .sidebar-footer::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 4px auto 14px auto;
  }
}

@media (max-width: 1000px) {
  .sidebar.sheet-open .sidebar-footer {
    transform: translateY(0);
  }
}

@media (max-width: 1000px) {
  .sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 60;
  }
}

@media (max-width: 1000px) {
  .sidebar.sheet-open ~ .sheet-backdrop, .sidebar.sheet-open .sheet-backdrop {
    display: block;
  }
}

/* Prevent iOS auto-zoom on focus: inputs/selects need >=16px font-size */

@media (max-width: 1000px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}

@media (max-width: 1000px) {
  .cal-cell {
    min-height: 56px;
  }
}

@media (max-width: 1000px) {
  .cal-grid {
    min-width: 0;
  }
}

@media (max-width: 1000px) {
  .cal-cell {
    min-width: 0;
    overflow: hidden;
  }
}

@media (max-width: 1000px) {
  .cal-chip {
    min-width: 0;
    max-width: 100%;
  }
}

@media (max-width: 1000px) {
  .cred {
    font-size: 11px;
  }
}

@media (max-width: 1000px) {
  .cred::after {
    content: attr(data-short);
  }
}

@media (max-width: 1000px) {
  .cred {
    visibility: hidden;
    position: relative;
  }
}

@media (max-width: 1000px) {
  .cred::after {
    visibility: visible;
    position: absolute;
    left: 0;
    top: 0;
  }
}

/* login */

.body-login {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter',sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom)) 16px;
}

@media (max-width: 480px) {
  .card {
    padding: 28px 22px;
  }
}

@media (max-width: 480px) {
  input {
    font-size: 16px !important;
  }
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 34px;
  width: 100%;
  max-width: 360px;
}

.brand {
  font-family: 'Space Grotesk',sans-serif;
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 6px;
}

.brand span {
  color: var(--amber);
}

.sub {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 24px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 16px;
  font-family: 'Inter',sans-serif;
}

input:focus {
  outline: none;
  border-color: var(--amber);
}

button {
  width: 100%;
  background: var(--amber);
  color: #231604;
  border: none;
  padding: 11px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

.error {
  color: var(--red);
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}

