:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --danger: #dc2626;
  --green: #16a34a;
  --amber: #d97706;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font: inherit; cursor: pointer; }
a { color: var(--primary); }

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 390px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
}
.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.brand-block .brand-logo { width: 44px; height: 44px; }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: #0f172a;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  position: fixed;
  inset: 0 auto 0 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 20px;
}
.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}
.brand strong { display: block; }
.brand-sub { color: #94a3b8; font-size: 12px; }
.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  border: 0;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
}
.nav-btn:hover { background: #1e293b; color: #fff; }
.nav-btn.active { background: var(--primary); color: #fff; }
.sidebar-foot { border-top: 1px solid #1e293b; padding-top: 10px; margin-top: 10px; }
.user-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 4px; }
.user-name { font-size: 13px; color: #94a3b8; overflow: hidden; text-overflow: ellipsis; }

.content {
  flex: 1;
  margin-left: 240px;
  padding: 28px;
  max-width: 1180px;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.dashboard-title-wrap { display: flex; align-items: center; gap: 14px; }
.dashboard-logo {
  width: 54px;
  height: 54px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
}
.page-head h1 { margin: 0 0 4px; font-size: 28px; }
.page-head p { margin: 0; }
.head-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.head-tools input[type="month"] { border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; font: inherit; background: #fff; }
.period-control { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.period-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.period-btn { padding: 7px 10px; font-size: 13px; }
.period-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.custom-range { display: flex; align-items: center; gap: 6px; }
.custom-range input[type="date"] { border: 1px solid var(--border); border-radius: 9px; padding: 7px 9px; font: inherit; background: #fff; }
.total-pill { font-weight: 700; color: var(--text); background: #e0e7ff; padding: 8px 12px; border-radius: 999px; white-space: nowrap; }
.monthly-list { display: flex; flex-wrap: wrap; gap: 8px; }
.month-chip {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.month-chip:hover { border-color: var(--primary); }
.month-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.metric {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; font-size: 26px; margin-top: 8px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
@media (max-width: 800px) {
  .app { display: block; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    height: auto;
    flex-direction: column;
    padding: 6px 8px;
    z-index: 20;
  }
  .brand { display: none; }
  .sidebar nav { flex-direction: row; gap: 4px; overflow-x: auto; }
  .nav-btn { flex: 1 0 auto; text-align: center; padding: 10px 4px; font-size: 12px; white-space: nowrap; }
  .sidebar-foot { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 6px; border: 0; padding: 4px 0 0; margin: 0; }
  .user-box { display: flex; align-items: center; gap: 4px; padding: 0; }
  .user-name { display: none; }
  .sidebar-foot .nav-btn { flex: 0 0 auto; padding: 8px 9px; font-size: 12px; }
  .content { margin-left: 0; margin-top: 108px; padding: 14px; max-width: none; }
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-head h1 { font-size: 24px; }
  .head-tools { justify-content: space-between; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .metric { padding: 14px; }
  .metric strong { font-size: 22px; }
  .two-col { grid-template-columns: 1fr; }
  .workspace-grid { grid-template-columns: 1fr; }
  .row { align-items: flex-start; flex-wrap: wrap; }
  .row-actions { width: 100%; justify-content: flex-end; }
  .btn { padding: 11px 13px; font-size: 15px; }
  .field input, .field textarea, .field select { padding: 12px 11px; font-size: 16px; }
  .item-row { grid-template-columns: 1fr; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { width: 100%; max-height: 94vh; border-radius: 18px 18px 0 0; padding: 16px; }
  .photo-picker { display: grid; grid-template-columns: 1fr 1fr; }
  .photo-capture-btn { text-align: center; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 18px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 18px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.row .main { min-width: 0; flex: 1; }
.row strong { display: block; }
.row .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.row .amount { font-weight: 700; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 9px;
  padding: 8px 12px;
  color: var(--text);
}
.btn:hover { background: #f8fafc; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-block { width: 100%; }

.field { margin-bottom: 14px; }
.check-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 14px; font-size: 14px; }
.photo-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.photo-capture-btn { position: relative; overflow: hidden; cursor: pointer; }
.photo-file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-preview { max-width: 100%; max-height: 220px; border-radius: 12px; border: 1px solid var(--border); margin-top: 10px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  font: inherit;
}
.field textarea { min-height: 80px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-panel { max-width: 720px; }
.form-panel h2 { margin-top: 0; }
.item-row { display: grid; grid-template-columns: 1fr 70px 90px 40px; gap: 8px; margin-bottom: 8px; align-items: center; }
.item-row input { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 8px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 30;
}
.modal-card {
  width: min(680px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: var(--panel);
  border-radius: 16px;
  padding: 22px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { margin: 0; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 10px; }
.photo-grid img { width: 100%; height: 120px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); background: #f8fafc; }
.photo-tile { position: relative; }
.photo-tile .btn-photo-delete { position: absolute; top: 6px; right: 6px; padding: 5px 8px; font-size: 12px; }
.photo-preview { max-width: 100%; max-height: 220px; border-radius: 10px; margin-top: 8px; }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #e2e8f0;
}
.badge.paid, .badge.sent { background: #dcfce7; color: #166534; }
.badge.draft { background: #f1f5f9; color: #475569; }
.badge.partial { background: #fef3c7; color: #92400e; }
.badge.overdue { background: #fee2e2; color: #991b1b; }

.empty { color: var(--muted); padding: 22px; text-align: center; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  z-index: 40;
}
.workspace-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.workspace-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  text-align: left;
  text-decoration: none;
  color: var(--text);
}
.workspace-card strong { display: block; margin-bottom: 6px; }
.workspace-card span { color: var(--muted); }
.workspace-card:hover { border-color: var(--primary); }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 22px; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; font-weight: 700; font-size: .84rem; color: var(--muted); cursor: pointer; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.business-selector { padding: 8px 0 12px; }
.business-selector label { display: block; font-size: .74rem; margin-bottom: 6px; }
.business-selector select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  white-space: nowrap;
}
.pill-pending { background: #fef3c7; color: #92400e; }
.pill-accepted { background: #dcfce7; color: #166534; }
.pill-expired { background: #f1f5f9; color: #475569; }
.pill-revoked { background: #fee2e2; color: #b91c1c; }
