:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1c2333;
  --ink-soft: #5b6478;
  --border: #e3e6ec;
  --accent: #2f6f4f;
  --accent-soft: #e8f3ec;
  --warn: #b5762b;
  --warn-soft: #fbf1e2;
  --danger: #b23b3b;
  --danger-soft: #fbeaea;
  --radius: 10px;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
  width: 230px;
  background: #1c2333;
  color: #cfd4e0;
  padding: 20px 14px;
  flex-shrink: 0;
}
.sidebar .brand { color: #fff; font-weight: 700; font-size: 18px; margin-bottom: 4px; }
.sidebar .role-tag {
  display: inline-block; font-size: 12px; color: #9fb6a8; margin-bottom: 20px;
}
.sidebar nav a {
  display: block; color: #cfd4e0; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; font-size: 14px;
}
.sidebar nav a:hover, .sidebar nav a.active { background: #2c3550; color: #fff; text-decoration: none; }
.sidebar .section-label {
  text-transform: uppercase; font-size: 11px; letter-spacing: .06em; color: #6d7690;
  margin: 18px 0 6px 10px;
}
.sidebar form { margin-top: 20px; }
.sidebar .logout-btn {
  width: 100%; background: transparent; border: 1px solid #3c4664; color: #cfd4e0;
  padding: 8px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.sidebar .logout-btn:hover { background: #2c3550; }

.main { flex: 1; padding: 24px 32px; max-width: 1200px; }

.page-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px;
}
.page-header h1 { font-size: 22px; margin: 0; }

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

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; } }

.stat-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .label { color: var(--ink-soft); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat-card .value.accent { color: var(--accent); }
.stat-card .value.warn { color: var(--warn); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--ink-soft); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: #fafbfc; }

.btn {
  display: inline-block; background: var(--accent); color: #fff; border: none; padding: 10px 16px;
  border-radius: 8px; font-size: 14px; cursor: pointer; touch-action: manipulation; line-height: 1.3;
}
.btn:hover { opacity: .9; text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f4f5f7; color: var(--ink); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 8px 12px; font-size: 13px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-pending { background: var(--warn-soft); color: var(--warn); }
.badge-in_progress { background: #e5edfb; color: #2b559c; }
.badge-done { background: var(--accent-soft); color: var(--accent); }
.badge-paid { background: #e8f3ec; color: #1c6b3f; }
.badge-cancelled { background: var(--danger-soft); color: var(--danger); }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 4px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 10px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 16px;
  font-family: inherit; background: #fff;
}
.form-row textarea { min-height: 70px; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .form-row { margin-bottom: 0; flex: 1; min-width: 140px; }

/* Bare (non form-row-wrapped) inputs/selects used inline, e.g. dashboard branch
   filter and cash-transaction "kind" filter — same 16px floor to avoid iOS zoom. */
select, input[type="text"], input[type="date"], input[type="number"], input[type="email"],
input[type="tel"], input[type="password"], input[type="file"], textarea {
  font-size: 16px;
}

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-size: 14px; }
.messages .success { background: var(--accent-soft); color: var(--accent); }
.messages .error { background: var(--danger-soft); color: var(--danger); }

.text-soft { color: var(--ink-soft); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a {
  padding: 7px 14px; border-radius: 20px; font-size: 13.5px; background: #fff; border: 1px solid var(--border); color: var(--ink);
}
.tabs a.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.tabs a:hover { text-decoration: none; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-soft); }
.empty-state .empty-icon { font-size: 34px; margin-bottom: 10px; }
.empty-state h3 { margin: 0 0 6px; color: var(--ink); font-size: 15.5px; }
.empty-state p { margin: 0 0 16px; font-size: 13.5px; max-width: 360px; margin-left: auto; margin-right: auto; }

/* --------------------------------------------------------------- Getting started checklist */
.setup-card {
  background: linear-gradient(135deg, #1c2333, #2a3348);
  color: #fff; border-radius: var(--radius); padding: 22px 24px; margin-bottom: 20px;
}
.setup-card h2 { margin: 0 0 4px; font-size: 18px; }
.setup-card .setup-sub { color: #b7bdd0; font-size: 13.5px; margin: 0 0 16px; }
.setup-progress-track { background: rgba(255,255,255,.15); border-radius: 6px; height: 8px; overflow: hidden; margin-bottom: 18px; }
.setup-progress-fill { background: #6fcf97; height: 100%; border-radius: 6px; transition: width .3s ease; }
.setup-list { display: grid; gap: 10px; }
.setup-item {
  display: flex; align-items: center; gap: 12px; background: rgba(255,255,255,.06);
  border-radius: 8px; padding: 12px 14px; text-decoration: none; color: #fff; transition: background .15s ease;
}
.setup-item:hover { background: rgba(255,255,255,.12); text-decoration: none; color: #fff; }
.setup-item.done { opacity: .6; }
.setup-item .setup-check {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 13px; font-weight: 700;
  background: rgba(255,255,255,.15); border: 1.5px solid rgba(255,255,255,.35);
}
.setup-item.done .setup-check { background: #6fcf97; border-color: #6fcf97; color: #1c2333; }
.setup-item .setup-label { flex: 1; font-size: 14.5px; }
.setup-item .setup-arrow { opacity: .6; font-size: 14px; }
.setup-item.disabled { opacity: .4; cursor: default; pointer-events: none; }

/* --------------------------------------------------------------- Mobile */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.mobile-toggle {
  display: none;
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  z-index: 50;
  background: #1c2333; color: #fff; border: none; border-radius: 8px;
  width: 44px; height: 44px; font-size: 18px; cursor: pointer; touch-action: manipulation;
}

@media (max-width: 780px) {
  .mobile-toggle { display: block; }

  .layout { flex-direction: column; }

  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39;
  }
  .sidebar-backdrop.open { display: block; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 260px; max-width: 82vw;
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    padding-left: calc(14px + env(safe-area-inset-left));
    transform: translateX(-100%); transition: transform .2s ease;
    z-index: 40; overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar nav a { padding: 12px 10px; font-size: 15px; }

  .main {
    padding: calc(64px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
    padding-left: calc(16px + env(safe-area-inset-left));
    padding-right: calc(16px + env(safe-area-inset-right));
    max-width: 100%;
  }

  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }

  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header > div { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
  .page-header > div .btn, .page-header > div .btn-secondary { flex: 1 1 auto; text-align: center; }

  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form .form-row { width: 100%; }

  th, td { padding: 10px 8px; font-size: 13.5px; }
}

/* iPhone/iPad landscape or devices with a home indicator: keep the sidebar's
   logout button clear of the gesture bar even when the sidebar isn't in the
   mobile drawer mode (e.g. iPad in split view). */
@supports (padding: max(0px)) {
  .sidebar form { padding-bottom: env(safe-area-inset-bottom); }
}
