:root {
  --bg: #F4F7F6;
  --surface: #FFFFFF;
  --surface-hover: #F8FAF9;
  --border: #E2E8E6;
  --text: #115243;
  --text-muted: #6B8881;
  --primary: #115243;
  --accent: #EE8524;
  --accent-light: rgba(238, 133, 36, 0.1);
  --amber: #F79F1F;
  --green: #2ecc71;
  --red: #e74c3c;
  --purple: #9b59b6;
  --shadow-sm: 0 2px 8px rgba(17, 82, 67, 0.05);
  --shadow-md: 0 8px 24px rgba(17, 82, 67, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app { 
  display: flex; 
  flex-direction: column; 
  height: 100vh; 
  height: 100dvh; 
  overflow: hidden; 
  position: relative; 
  background: var(--bg);
}

/* App Bar */
.app-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  box-shadow: var(--shadow-sm);
}
.brand h1 { 
  font-size: 20px; 
  font-weight: 700;
  letter-spacing: 0.5px; 
  color: var(--primary);
  margin: 0; 
}
.status-indicator { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; font-weight: 500; }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; background: var(--amber); margin-right: 6px;
}
.dot.ok { background: var(--green); }
.dot.err { background: var(--red); }

/* Content */
.content { flex: 1; overflow-y: auto; padding: 20px 16px 100px; }
.content::-webkit-scrollbar { display: none; }
.view { display: none; animation: fadeIn 0.3s ease; }
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.view-header h2 { font-size: 22px; font-weight: 700; color: var(--primary); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }

/* Inputs and Forms */
select, 
input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]), 
textarea {
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid #D1D5DB;
  background: #F9FAFB;
  color: var(--primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

select:hover, 
input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):hover, 
textarea:hover {
  background: var(--surface);
  border-color: #9CA3AF;
}

select:focus, 
input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):focus, 
textarea:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(238, 133, 36, 0.15), 0 4px 12px rgba(0,0,0,0.05);
  transform: translateY(-1px);
}

textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

/* Filter Bar (Search & Filter Icon) */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
}
.search-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap .search-icon {
  position: absolute;
  left: 12px;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-select {
  width: 100%;
  padding: 10px 12px 10px 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  appearance: none;
  outline: none;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.02);
  cursor: pointer;
}
.search-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 42px;
  height: 42px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.btn-icon:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-icon svg { width: 20px; height: 20px; stroke-width: 2px; }

.form-group { margin-bottom: 20px; }
.form-group label { 
  display: block; 
  color: #475569; 
  font-size: 13px; 
  margin-bottom: 8px; 
  font-weight: 600; 
  letter-spacing: 0.2px; 
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hint { color: #64748b; font-size: 12px; margin-top: 6px; font-weight: 500; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.card h3 { margin-bottom: 16px; color: var(--text-muted); text-transform: uppercase; font-size: 11px; font-weight: 700; letter-spacing: 1px; }

/* List Cards */
.list-wrap { display: flex; flex-direction: column; gap: 12px; }
.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 3px rgba(17,82,67,0.04);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}
.list-card:hover { background: var(--surface-hover); border-color: var(--accent); }
.list-card:active { transform: scale(0.98); }

.lc-main { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.lc-title { font-weight: 700; color: var(--primary); font-size: 14px; word-break: break-word; white-space: normal; }
.lc-sub { color: var(--text-muted); font-size: 12px; word-break: break-word; white-space: normal; }
.lc-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }

.lc-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-left: 12px; flex-shrink: 0; text-align: right; }
.lc-val { font-weight: 700; color: var(--text); font-size: 14px; }
.lc-val-sub { color: var(--text-muted); font-size: 12px; }

/* Inspired KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(17,82,67,0.03);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.kpi-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.kpi-icon.purple { background: rgba(155, 89, 182, 0.1); color: var(--purple); }
.kpi-icon.green { background: rgba(46, 204, 113, 0.1); color: var(--green); }
.kpi-icon.amber { background: rgba(247, 159, 31, 0.1); color: var(--amber); }
.kpi-icon.blue { background: rgba(79, 156, 249, 0.1); color: #4f9cf9; }
.kpi-icon svg { width: 18px; height: 18px; }

.kpi-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  white-space: nowrap;
  flex: 1;
  text-align: center;
}
.kpi-trend {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.kpi-trend.up { background: rgba(46, 204, 113, 0.15); color: var(--green); }
.kpi-trend.down { background: rgba(231, 76, 60, 0.15); color: var(--red); }
.kpi-trend svg { width: 14px; height: 14px; stroke-width: 2.5; }

.kpi-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  text-align: left;
}

/* Status Pills */
.status-strip { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px; }
.status-pill {
  border-radius: 12px; padding: 14px 16px; display: flex;
  justify-content: space-between; align-items: center; border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.status-pill .lbl { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.status-pill .num { font-size: 18px; font-weight: 700; }
.status-pill.full .num { color: var(--green); }
.status-pill.partial .num { color: var(--amber); }
.status-pill.none .num { color: var(--purple); }
.status-pill.overdue .num { color: var(--red); }

.two-col { display: grid; grid-template-columns: 1fr; gap: 20px; }
.mt { margin-top: 24px; }

/* Progress Bars */
.bar-block { margin-top: 10px; }
.bar-track { height: 12px; background: #E9ECEB; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); width: 0; transition: width 0.8s ease; }
.bar-stats { display: flex; justify-content: space-between; color: var(--text-muted); margin-top: 8px; font-size: 12px; font-weight: 500; }

.cat-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.cat-row .bar-track { height: 8px; border-radius: 4px; flex: 1; }
.cat-row .bar-fill { background: #4f9cf9; }
.cat-name { width: 110px; overflow: hidden; text-overflow: ellipsis; font-weight: 500; font-size: 13px; }
.cat-amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.cat-pct { width: 42px; text-align: right; color: var(--text-muted); font-size: 12px; }

/* Compare Rows */
.compare { display: flex; flex-direction: column; gap: 8px; }
.cmp-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.cmp-row:last-child { border-bottom: none; }
.cmp-row .lbl { color: var(--text-muted); font-size: 13px; }
.cmp-row .val { font-weight: 600; font-variant-numeric: tabular-nums; width: 110px; text-align: right; }
.cmp-row .delta { width: 80px; text-align: right; font-size: 12px; font-weight: 600; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* Buttons */
.btn {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}
.btn:hover { border-color: var(--accent); background: var(--surface-hover); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { 
  background: var(--accent); 
  border: 1px solid var(--accent); 
  color: #fff; 
}
.btn.primary:hover { background: #d35400; border-color: #d35400; color: #fff; }
.btn.sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: rgba(231,76,60,0.1); border-color: var(--red); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Badges */
.badge { padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; display: inline-block; }
.badge.paid, .badge.fully_paid { background: rgba(46,204,113,0.15); color: var(--green); }
.badge.partially_paid { background: rgba(247,159,31,0.15); color: var(--amber); }
.badge.unpaid { background: rgba(155,89,182,0.15); color: var(--purple); }
.badge.overdue { background: rgba(231,76,60,0.15); color: var(--red); }

/* Alerts */
.alert {
  display: flex; gap: 16px; align-items: flex-start;
  padding: 20px; border-radius: 16px; border: 1px solid var(--border);
  margin-bottom: 16px; background: var(--surface);
  box-shadow: 0 4px 12px rgba(17,82,67,0.02);
  transition: transform 0.2s;
}
.alert:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.alert-icon { 
  width: 40px; height: 40px; border-radius: 50%; display: flex; 
  align-items: center; justify-content: center; flex-shrink: 0; 
}
.alert-icon svg { width: 20px; height: 20px; stroke-width: 2.5; }
.alert.info .alert-icon { background: rgba(79, 156, 249, 0.15); color: #4f9cf9; }
.alert.warning .alert-icon { background: rgba(247, 159, 31, 0.15); color: var(--amber); }
.alert.danger .alert-icon { background: rgba(231, 76, 60, 0.15); color: var(--red); }
.alert-content { flex: 1; min-width: 0; }
.alert-content h4 { margin-bottom: 6px; font-size: 15px; font-weight: 700; color: var(--primary); }
.alert-content p { color: var(--text-muted); font-size: 13px; line-height: 1.5; }
.empty { color: var(--text-muted); padding: 30px 20px; text-align: center; font-style: italic; }

/* States */
.loader-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 20px; gap: 12px; }
.loader-spinner { width: 32px; height: 32px; border: 3px solid rgba(17,82,67,0.1); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.state-error { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 20px; text-align: center; gap: 12px; }
.state-error svg { width: 48px; height: 48px; stroke: var(--red); margin-bottom: 8px; }
.state-error p { color: var(--text-muted); font-size: 14px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(17, 82, 67, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  opacity: 0; animation: fadeModalIn 0.2s forwards;
}
@keyframes fadeModalIn { to { opacity: 1; } }
.modal { 
  background: var(--surface); 
  border-radius: 20px; 
  width: 520px; max-width: 94vw; max-height: 90vh; overflow-y: auto; 
  box-shadow: 0 16px 48px rgba(17,82,67,0.2);
  transform: translateY(20px); animation: slideUpModal 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}
@keyframes slideUpModal { to { transform: translateY(0); } }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 24px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 18px; font-weight: 700; color: var(--primary); }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 26px; cursor: pointer; line-height: 1; transition: color 0.2s; }
.modal-close:hover { color: var(--red); }
.modal-body { padding: 24px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; padding-top: 16px; }

/* Toast */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-30px) scale(0.95);
  background: var(--surface); color: var(--text);
  padding: 12px 24px; border-radius: 100px; z-index: 9999; box-shadow: 0 12px 32px rgba(17,82,67,0.15);
  font-weight: 600; font-size: 14px; opacity: 0; transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: flex; align-items: center; gap: 10px; pointer-events: none;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); pointer-events: auto; }
.toast.success svg { color: var(--green); }
.toast.err svg { color: var(--red); }
.toast svg { width: 22px; height: 22px; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }

/* Premium Tabbed Navigation (Tour Form) */
.ttabs { margin-top: 10px; }
.ttab-nav { 
  display: flex; 
  gap: 12px; 
  margin-bottom: 24px; 
  overflow-x: auto; 
  padding-bottom: 8px; 
  border-bottom: 1px solid var(--border);
}
.ttab-nav::-webkit-scrollbar { height: 4px; }
.ttab-nav::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 4px; }
.ttab-btn { 
  background: transparent; 
  border: none; 
  color: #64748b; 
  font-weight: 600; 
  font-size: 14px;
  padding: 10px 16px; 
  cursor: pointer; 
  border-radius: 8px; 
  transition: all 0.2s ease; 
  white-space: nowrap; 
  display: flex;
  align-items: center;
  gap: 8px;
}
.ttab-btn svg { width: 18px; height: 18px; opacity: 0.7; transition: opacity 0.2s; }
.ttab-btn:hover { background: var(--surface-hover); color: var(--primary); }
.ttab-btn:hover svg { opacity: 1; color: var(--primary); }
.ttab-btn.active { 
  background: var(--accent-light); 
  color: var(--accent); 
  box-shadow: inset 0 -2px 0 var(--accent);
  border-radius: 8px 8px 0 0;
}
.ttab-btn.active svg { opacity: 1; color: var(--accent); }
.ttab-panel { display: none; animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
.ttab-panel.active { display: block; }
.ttab-section-title { font-size: 15px; font-weight: 700; color: var(--primary); margin-bottom: 16px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }

/* Print / Hide elements */
@media print {
  .app-bar, .sidebar { display: none !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }
}

/* Ticket Rendering */
.ticket-render {
  width: 380px;
  background: #ffffff;
  border-radius: 24px;
  padding: 32px;
  box-sizing: border-box;
  font-family: inherit;
  color: #111;
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}
.ticket-render::before {
  content: "";
  position: absolute; top: 0; left: 0; width: 100%; height: 8px;
  background: var(--primary);
}
.ticket-render .t-header {
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 2px dashed #eaeaea; padding-bottom: 24px; margin-bottom: 24px;
}
.ticket-render .t-logo { height: 36px; object-fit: contain; }
.ticket-render .t-title { font-size: 14px; font-weight: 800; color: #999; text-transform: uppercase; letter-spacing: 1px; }
.ticket-render .t-row { display: flex; justify-content: space-between; margin-bottom: 20px; }
.ticket-render .t-col { flex: 1; }
.ticket-render .t-col.right { text-align: right; }
.ticket-render .t-label { font-size: 11px; color: #888; text-transform: uppercase; font-weight: 700; margin-bottom: 6px; letter-spacing: 0.5px; }
.ticket-render .t-val { font-size: 16px; font-weight: 700; color: #111; }
.ticket-render .t-val.large { font-size: 20px; color: var(--primary); }
.ticket-render .t-qr {
  margin-top: 10px; display: flex; justify-content: center; align-items: center;
  padding-top: 24px; border-top: 2px dashed #eaeaea;
}
.ticket-render .t-footer { text-align: center; font-size: 11px; color: #aaa; margin-top: 16px; font-weight: 500; }

/* Bottom Nav */
.bottom-nav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(70px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
  box-shadow: 0 -4px 12px rgba(17,82,67,0.03);
}
.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  flex: 1;
  padding: 10px 0;
  transition: color 0.2s;
}
.nav-btn span { font-size: 11px; font-weight: 600; letter-spacing: 0.2px; }
.nav-btn svg { width: 24px; height: 24px; transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.nav-btn.active { color: var(--accent); }
.nav-btn.active svg { transform: translateY(-2px); stroke: var(--accent); }

@media (min-width: 600px) {
  .app {
    max-width: 1200px;
    height: 100vh;
    border-radius: 0;
    border: none;
    margin: 0 auto;
    box-shadow: none;
  }
  
  .content {
    padding: 30px 40px 100px;
  }
  
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .form-row {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 599px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .list-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .lc-right {
    align-items: flex-start;
    margin-left: 0;
    text-align: left;
  }
}