:root {
  --ink: #161d2e;
  --ink-soft: #4a5570;
  --ink-gradient: linear-gradient(135deg, #1f2942 0%, #161d2e 100%);
  --brass: #b8873a;
  --brass-light: #d1a35f;
  --brass-soft: #f3e6cd;
  --bg: #f4f3ef;
  --card-bg: #ffffff;
  --border: #e7e4da;
  --success: #2f7a4f;
  --success-bg: #e7f4ec;
  --error: #b3392f;
  --error-bg: #fbe9e7;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(22, 29, 46, 0.06);
  --shadow-md: 0 6px 20px rgba(22, 29, 46, 0.08);
  --shadow-lg: 0 20px 45px rgba(22, 29, 46, 0.14);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- APP SHELL ---------- */
.app-shell { display: flex; min-height: 100vh; }
.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--ink-gradient);
  color: #fff;
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-brand { font-weight: 700; font-size: 16px; }
.hamburger-btn {
  background: rgba(255,255,255,0.1); border: none; color: #fff; width: 38px; height: 38px;
  border-radius: 10px; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
}
.hamburger-btn:hover { background: rgba(255,255,255,0.18); }
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15,19,30,0.5);
  z-index: 25; opacity: 0; transition: opacity 0.2s ease;
}
.sidebar-overlay-visible { display: block; opacity: 1; }
.no-scroll { overflow: hidden; }
.sidebar {
  width: 232px;
  background: var(--ink-gradient);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 0;
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 22px 20px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 14px;
}
.sidebar-brand svg { color: var(--brass-light); }
.sidebar-nav { display: flex; flex-direction: column; flex: 1; gap: 2px; padding: 0 12px; }
.sidebar-nav a {
  padding: 11px 14px;
  color: rgba(255,255,255,0.68);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.07); color: #fff; }
.sidebar-nav a.active { color: #fff; background: rgba(184,135,58,0.22); font-weight: 600; box-shadow: inset 2px 0 0 var(--brass-light); }
.sidebar-footer { padding: 14px 12px 0; border-top: 1px solid rgba(255,255,255,0.1); margin-top: 10px; }
.user-chip-link {
  display: flex; align-items: center; gap: 10px; text-decoration: none;
  padding: 9px 10px; border-radius: 10px; margin-bottom: 6px; transition: background 0.15s ease;
}
.user-chip-link:hover, .user-chip-link.active { background: rgba(255,255,255,0.07); }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brass);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
  color: #1a1305; flex-shrink: 0;
}
.user-chip-text { display: flex; flex-direction: column; overflow: hidden; }
.user-chip-name { font-size: 13px; color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip-role { font-size: 11px; color: rgba(255,255,255,0.55); }
.logout-link { color: rgba(255,255,255,0.55); text-decoration: none; font-size: 12.5px; padding: 0 10px; display: inline-block; }
.logout-link:hover { color: var(--brass-light); }

.main-content { flex: 1; padding: 32px 36px; max-width: 1120px; min-width: 0; }

/* ---------- TYPOGRAPHY ---------- */
h1 { font-size: 23px; margin: 0 0 18px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0; font-weight: 700; }
.section-title { font-size: 12.5px; font-weight: 700; margin: 22px 0 10px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.05em; }
.text-muted { color: #8d92a0; }
.text-danger { color: var(--error); }

/* ---------- PANEL / CARD ---------- */
.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.panel-narrow { max-width: 480px; }
.panel-wide { max-width: 900px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.panel-header h1 { margin: 0; }

/* ---------- FORMS ---------- */
label { display: block; font-size: 12.5px; font-weight: 600; margin: 14px 0 5px; color: var(--ink-soft); }
input, select, textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px rgba(184,135,58,0.14); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-actions { margin-top: 22px; display: flex; gap: 10px; justify-content: flex-end; }
.inline-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.inline-form label { margin: 0 0 4px; }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
}
.btn-primary { background: var(--ink-gradient); color: #fff; box-shadow: 0 2px 8px rgba(22,29,46,0.22); }
.btn-primary:hover { box-shadow: 0 6px 16px rgba(22,29,46,0.28); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary { background: #fff; color: var(--ink); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: #faf9f6; border-color: #d8d4c6; }
.btn-sm { padding: 7px 15px; font-size: 13px; }
.btn-lg { padding: 13px 20px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; text-align: center; }

/* ---------- TABLE ---------- */
.data-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.data-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-soft); padding: 10px 14px; border-bottom: 2px solid var(--border);
}
.data-table td { padding: 13px 14px; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: #faf9f6; }
.empty-state { text-align: center; color: #9a9fab; padding: 34px !important; }
.row-actions a { margin-right: 12px; font-size: 13px; text-decoration: none; color: var(--brass); font-weight: 600; }
.row-actions a:hover { color: var(--ink); }

.mini-table { width: 100%; border-collapse: collapse; }
.mini-table td { padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.mini-table td:first-child { color: var(--ink-soft); width: 42%; }
.mini-table .total-row td { border-top: 2px solid var(--ink); border-bottom: none; padding-top: 12px; font-size: 17px; }

/* ---------- BADGES ---------- */
.badge {
  display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 11px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
}
.badge-booked { background: #eef1f7; color: #445; }
.badge-assigned { background: #fff3d6; color: #96660b; }
.badge-in_progress { background: #dbeafe; color: #1d4ed8; }
.badge-completed { background: var(--success-bg); color: var(--success); }
.badge-cancelled { background: var(--error-bg); color: var(--error); }

/* ---------- ALERTS ---------- */
.alert { padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; font-weight: 500; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--error-bg); color: var(--error); }

/* ---------- STAT GRID ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm); border-top: 3px solid var(--brass);
}
.stat-label { font-size: 11.5px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; font-weight: 600; }
.stat-value { font-size: 23px; font-weight: 800; letter-spacing: -0.01em; }

/* ---------- FILTER CHIPS ---------- */
.filter-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip { padding: 7px 15px; border-radius: 20px; background: #fff; border: 1.5px solid var(--border); font-size: 13px; text-decoration: none; color: var(--ink-soft); font-weight: 500; }
.chip-active { background: var(--ink); color: #fff; border-color: var(--ink); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 32px; }
.action-row { display: flex; gap: 10px; margin: 10px 0 20px; flex-wrap: wrap; align-items: center; }
.total-preview { font-size: 16px; font-weight: 700; margin: 14px 0; text-align: right; }

/* ---------- TABLE SCROLL (mobile) ---------- */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll .data-table { min-width: 560px; }

/* ---------- PLACE AUTOCOMPLETE (Mapbox) ---------- */
.place-autocomplete { position: relative; }
.place-suggestions {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); max-height: 220px; overflow-y: auto;
}
.place-suggestion-item { padding: 10px 13px; font-size: 13.5px; cursor: pointer; border-bottom: 1px solid var(--border); }
.place-suggestion-item:last-child { border-bottom: none; }
.place-suggestion-item:hover { background: #faf6ee; color: var(--brass); }

/* ---------- AUTH / SETUP ---------- */
.auth-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: var(--ink-gradient);
  background-image: radial-gradient(circle at 15% 20%, rgba(184,135,58,0.18), transparent 40%),
                     radial-gradient(circle at 85% 85%, rgba(184,135,58,0.12), transparent 45%),
                     var(--ink-gradient);
  padding: 20px;
}
.auth-wrap { width: 100%; max-width: 460px; }
.auth-card {
  background: #fff; padding: 40px 34px; border-radius: 20px; width: 100%; max-width: 400px; margin: 0 auto;
  box-shadow: var(--shadow-lg);
}
.auth-card-wide { max-width: 460px; }
.brand-mark { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: var(--ink-soft); margin-bottom: 22px; }
.brand-mark-icon { color: var(--brass); display: inline-flex; }
.setup-badge {
  display: inline-block; background: var(--brass-soft); color: #8a5f1f; font-size: 11px; font-weight: 700;
  padding: 4px 12px; border-radius: 20px; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 12px;
}
.auth-title { text-align: left; margin: 0 0 6px; font-size: 21px; }
.auth-subtitle { text-align: left; color: var(--ink-soft); font-size: 13.5px; margin-bottom: 22px; line-height: 1.5; }
.auth-footnote { font-size: 12.5px; color: #9a9fab; margin: 18px 0 0; line-height: 1.5; }

/* ---------- PUBLIC INVOICE / PAYLINK ---------- */
.public-body { background: var(--bg); min-height: 100vh; padding: 48px 16px; }
.paylink-wrap { max-width: 460px; margin: 0 auto; }
.paylink-brand { text-align: center; font-weight: 700; color: var(--ink-soft); font-size: 14px; margin-bottom: 16px; letter-spacing: 0.02em; }
.invoice-card { background: #fff; max-width: 480px; margin: 0 auto; padding: 30px; border-radius: 20px; border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.paylink-card { padding: 0; overflow: hidden; }
.paylink-hero { background: var(--ink-gradient); color: #fff; padding: 30px 30px 26px; text-align: center; }
.paylink-hero .badge { margin-bottom: 14px; }
.paylink-amount { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 8px; }
.paylink-hero .invoice-number { color: rgba(255,255,255,0.65); margin-bottom: 0; }
.paylink-card .mini-table, .paylink-card .section-title { padding-left: 30px; padding-right: 30px; }
.paylink-card .mini-table { width: calc(100% - 60px); margin-left: 30px; margin-right: 30px; }
.paylink-card > .alert, .paylink-card > .btn, .paylink-card > .security-note { margin-left: 30px; margin-right: 30px; width: calc(100% - 60px); }
.paylink-card > *:last-child { margin-bottom: 30px; }
.invoice-header { display: flex; justify-content: space-between; align-items: center; }
.invoice-number { color: var(--ink-soft); font-size: 13px; margin-bottom: 16px; }
.security-note { text-align: center; font-size: 12.5px; color: var(--ink-soft); margin-top: 12px; }
.paylink-footer { text-align: center; font-size: 12px; color: #9a9fab; margin-top: 22px; }

@media (max-width: 900px) {
  .topbar { display: flex; }
  .app-shell { flex-direction: column; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 30;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.sidebar-open { transform: translateX(0); }
  .main-content { padding: 18px; margin-left: 0; max-width: 100%; }
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .panel { padding: 18px; }
  .panel-header { flex-wrap: wrap; gap: 10px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; text-align: center; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 30px 22px; }
  .paylink-amount { font-size: 26px; }
  h1 { font-size: 20px; }
}
