:root {
  --primary: #0a3d62;
  --primary-dark: #062a45;
  --accent: #ff6b35;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e4e8ee;
  --green: #16a34a;
  --red: #dc2626;
  --yellow: #d97706;
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
}
a { color: var(--primary); text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg,#062a45,#0a3d62); padding: 20px; }
.login-card { background: #fff; border-radius: 14px; padding: 36px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-card h1 { margin: 0 0 6px; color: var(--primary); font-size: 24px; }
.login-card p { margin: 0 0 20px; color: var(--muted); }

/* Layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--primary-dark); color: #fff; padding: 20px 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 0 22px 20px; font-size: 20px; font-weight: 800; border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: 14px; display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; background: linear-gradient(135deg,#1b6ca8,#ff6b35); display: grid; place-items: center; font-weight: 900; }
.brand-logo { display: block; height: 44px; width: auto; max-width: 100%; object-fit: contain; background: #fff; padding: 6px 10px; border-radius: 8px; }
.login-logo { display: block; max-width: 220px; height: auto; margin: 0 auto 12px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 12px 22px;
  color: #cfd8e2; font-weight: 500; cursor: pointer;
}
.sidebar nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.sidebar .logout { margin-top: 30px; padding: 12px 22px; color: #ff9b9b; cursor: pointer; }

.main { padding: 24px 32px; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px;
}
.topbar h2 { margin: 0; color: var(--primary); font-size: 24px; }
.user-pill { background: #fff; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); font-weight: 600; }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--card); border-radius: 12px; padding: 18px; border: 1px solid var(--border); }
.stat .label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 26px; font-weight: 800; color: var(--primary); margin-top: 6px; }
.stat.alert .value { color: var(--red); }
.stat.good .value { color: var(--green); }

/* Card / Table */
.card { background: var(--card); border-radius: 12px; border: 1px solid var(--border); padding: 20px; margin-bottom: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-head h3 { margin: 0; color: var(--primary); font-size: 18px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 12px; letter-spacing: .5px; }
tr:hover td { background: #fafbfc; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 8px; border: 0; font-weight: 600; font-size: 14px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-outline { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-sm { padding: 6px 10px; font-size: 13px; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.new { background: #dbeafe; color: #1e40af; }
.badge.contacted { background: #fef3c7; color: #92400e; }
.badge.scheduled { background: #e0e7ff; color: #3730a3; }
.badge.completed { background: #dcfce7; color: #166534; }
.badge.cancelled { background: #fee2e2; color: #991b1b; }
.badge.paid { background: #dcfce7; color: #166534; }
.badge.unpaid { background: #fef3c7; color: #92400e; }
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.failed { background: #fee2e2; color: #991b1b; }
.badge.refunded { background: #e0e7ff; color: #3730a3; }
.badge.adjusted { background: #dcfce7; color: #166534; }

/* Forms */
.field { display: flex; flex-direction: column; margin-bottom: 14px; }
.field label { font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.field input, .field select, .field textarea {
  font: inherit; padding: 10px 12px; border-radius: 8px; border: 1.5px solid var(--border); background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row > .field { min-width: 0; }
.field input, .field select, .field textarea { min-width: 0; max-width: 100%; box-sizing: border-box; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal.open { display: flex; }
.modal-body { background: #fff; border-radius: 12px; padding: 24px; width: 100%; max-width: 720px; max-height: 90vh; overflow-y: auto; overflow-x: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { margin: 0; color: var(--primary); }
.modal-close { background: none; border: 0; font-size: 24px; color: var(--muted); }

/* Toolbar */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: 9px 12px; border-radius: 8px; border: 1.5px solid var(--border); background: #fff; }

/* Bill items table — horizontally scrollable inside modal so the modal itself never scrolls */
.items-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.items-table { width: 100%; min-width: 560px; border-collapse: collapse; }
.items-table th, .items-table td { padding: 6px 4px; vertical-align: middle; }
.items-table input, .items-table select { padding: 6px 8px; font-size: 13px; width: 100%; box-sizing: border-box; min-width: 0; }
.items-table .num { text-align: right; }
.items-table select { max-width: 180px; }

/* ---------- Hamburger (mobile sidebar toggle) ---------- */
.sidebar-toggle {
  display: none; background: var(--primary); color: #fff; border: 0;
  width: 42px; height: 42px; border-radius: 8px; align-items: center;
  justify-content: center; font-size: 20px; flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--primary-dark); }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 79; opacity: 0; transition: opacity .2s;
}
.sidebar-backdrop.open { display: block; opacity: 1; }

/* ---------- Tablet ---------- */
@media (max-width: 1100px) {
  .main { padding: 18px 20px; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .topbar-right input#global-search { width: 220px; }
}

/* ---------- Mobile ---------- */
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 250px;
    transform: translateX(-100%); transition: transform .25s ease;
    z-index: 80; box-shadow: 4px 0 20px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; }
  .main { padding: 14px; }
  .topbar { gap: 10px; flex-wrap: wrap; align-items: center; }
  .topbar h2 { font-size: 18px; flex: 1; min-width: 0; }
  .topbar-right { width: 100%; flex-direction: column; align-items: stretch; gap: 8px; order: 3; }
  .topbar-right input#global-search { width: 100%; min-width: 0; max-width: none; }
  .user-pill { align-self: flex-start; font-size: 12px; padding: 6px 10px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px; }
  .stat .value { font-size: 20px; }
  .stat .label { font-size: 11px; }
  .form-row { grid-template-columns: 1fr; }
  .card { padding: 14px; border-radius: 10px; }
  .card-head { flex-wrap: wrap; gap: 8px; }
  .card-head h3 { font-size: 15px; }
  /* Make any table inside a card horizontally scrollable */
  .card > table,
  .card > div > table:not(.items-table) { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  th, td { padding: 9px 8px; font-size: 13px; }
  .toolbar { gap: 8px; }
  .toolbar input, .toolbar select { flex: 1 1 140px; min-width: 0; padding: 8px 10px; font-size: 13px; }
  .modal { padding: 10px; }
  .modal-body { padding: 18px 16px; max-height: 92vh; border-radius: 10px; }
  .modal-head h3 { font-size: 16px; }
  .drawer-panel { width: 100%; max-width: 100%; padding: 18px; }
  .kv { grid-template-columns: 90px 1fr; font-size: 13px; }
  .search-results { right: 10px; left: 10px; width: auto; top: 60px; }
  .btn { padding: 8px 12px; font-size: 13px; }
  .btn-sm { padding: 6px 9px; font-size: 12px; }
  /* Make settings table-like field grids stack */
  .field input, .field select, .field textarea { font-size: 14px; padding: 10px; }
}

/* ---------- Tiny phones ---------- */
@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr; }
  .main { padding: 10px; }
  .topbar h2 { font-size: 16px; }
  .brand-logo { height: 36px; }
}

/* ---------- Topbar with global search ---------- */
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-right input#global-search {
  width: 320px; max-width: 50vw; padding: 9px 14px; border-radius: 999px;
  border: 1.5px solid var(--border); background: #fff; font-size: 14px;
}
.topbar-right input#global-search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(10,61,98,.12); }

.search-results {
  position: fixed; top: 70px; right: 32px; width: 460px; max-width: calc(100vw - 40px);
  max-height: 70vh; overflow-y: auto; background: #fff; border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.15); z-index: 50; padding: 8px;
}
.search-results .search-group { padding: 8px 6px; }
.search-results h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }
.search-results ul { list-style: none; margin: 0; padding: 0; }
.search-results li a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); font-size: 14px; }
.search-results li a:hover { background: var(--bg); }
.search-results .search-empty { padding: 16px; text-align: center; color: var(--muted); }

/* ---------- Sidebar new-booking badge ---------- */
.sidebar nav a { position: relative; }
.nav-badge {
  display: inline-block; margin-left: auto; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; min-width: 22px; text-align: center;
}

/* ---------- Drawer (slide-in from right) ---------- */
.drawer { position: fixed; inset: 0; z-index: 90; visibility: hidden; }
.drawer.open { visibility: visible; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); opacity: 0; transition: opacity .2s; }
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer-panel {
  position: absolute; top: 0; right: 0; height: 100vh; width: 540px; max-width: 96vw;
  background: #fff; box-shadow: -20px 0 50px rgba(0,0,0,.2); overflow-y: auto;
  transform: translateX(100%); transition: transform .25s ease; padding: 24px;
}
.drawer.open .drawer-panel { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin: 0 0 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { margin: 0; color: var(--primary); }
.drawer-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.drawer-section { margin: 18px 0; }
.drawer-section h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 14px; }
.kv b { color: var(--muted); font-weight: 600; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); padding-left: 16px; }
.timeline li { margin-bottom: 14px; position: relative; }
.timeline li::before {
  content: ''; position: absolute; left: -22px; top: 6px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px #fff;
}
.timeline li.kind-status::before { background: var(--accent); }
.timeline li.kind-bill::before { background: var(--green); }
.timeline-meta { color: var(--muted); font-size: 12px; }

/* Dashboard charts */
.charts-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 16px; margin-bottom: 20px; }
@media (max-width: 1100px) { .charts-grid { grid-template-columns: 1fr; } }
.chart-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.chart-card h4 { margin: 0 0 14px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; }
.bars .bar { flex: 1; background: linear-gradient(180deg, var(--primary), #1b6ca8); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars .bar .bar-unpaid { position: absolute; bottom: 0; left: 0; right: 0; background: var(--accent); opacity: .7; border-radius: 3px 3px 0 0; }
.bars-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.bars-legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.bars-legend .leg-paid::before { background: var(--primary); }
.bars-legend .leg-unpaid::before { background: var(--accent); }

.top-list { list-style: none; margin: 0; padding: 0; }
.top-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.top-list li:last-child { border-bottom: 0; }
.top-list .count { font-weight: 700; color: var(--primary); }

.funnel { display: flex; flex-direction: column; gap: 6px; }
.funnel-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; border-radius: 6px; font-size: 14px; color: #fff; font-weight: 600; }
.funnel-row.new { background: #1e40af; }
.funnel-row.contacted { background: #92400e; }
.funnel-row.scheduled { background: #3730a3; }
.funnel-row.completed { background: #166534; }
.funnel-row.cancelled { background: #991b1b; }

/* Bulk action bar */
.bulk-bar { display: flex; gap: 10px; align-items: center; padding: 8px 12px; background: #fff3e0; border: 1px solid #ffcc80; border-radius: 8px; margin-bottom: 12px; }
.bulk-bar.empty { display: none; }
.row-check { width: 28px; }
.row-check input { transform: scale(1.2); cursor: pointer; }

/* Print page chrome */
@media print {
  .sidebar, .topbar, .drawer, .modal, .no-print { display: none !important; }
  .app { display: block !important; }
  .main { padding: 0 !important; }
}
