:root {
  --ink: #0f172a;
  --ink-light: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-light: #f1f5f9;
  --paper: #ffffff;
  --back: #f8fafc;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-light: #ccfbf1;
  --warn: #dc2626;
  --warn-hover: #b91c1c;
  --warn-light: #fee2e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px -1px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
}

*, *::before, *::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background: var(--back);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  line-height: 1.5;
}

/* Sidebar & Navigation */
.sidebar {
  background: #0f172a;
  color: white;
  padding: 24px 16px;
  border-right: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: #1e293b;
  border-radius: 8px;
  color: #14b8a6;
  flex-shrink: 0;
}

.brand h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  color: #ffffff;
  letter-spacing: -0.2px;
}

.menu-toggle {
  display: none;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #94a3b8;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.sidebar nav a .nav-icon {
  flex-shrink: 0;
  opacity: 0.8;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.sidebar nav a:hover {
  background: #1e293b;
  color: #ffffff;
}

.sidebar nav a:hover .nav-icon {
  opacity: 1;
  transform: translateX(1px);
}

.sidebar nav a.active {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(15, 118, 110, 0.35);
}

.sidebar nav a.active .nav-icon {
  opacity: 1;
}

/* Main Content Area */
main {
  padding: 28px 32px;
  overflow-x: hidden;
  max-width: 1400px;
  width: 100%;
}

/* Page Header */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 22px;
}

h2, h3 {
  margin: 0 0 10px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--ink);
}

h2 {
  font-size: 24px;
  line-height: 1.25;
}

h3 {
  font-size: 18px;
  line-height: 1.3;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin: 0 0 4px;
}

/* Stat Cards */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stats article {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-xs);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stats article:hover {
  box-shadow: var(--shadow-sm);
}

.stats article span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.stats article strong {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  margin-top: 6px;
  line-height: 1.2;
  word-break: break-word;
}

/* Two-column grid */
.grid {
  display: grid;
  gap: 16px;
  margin-bottom: 24px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(280px, 1fr));
}

/* Panels and Containers */
article, .panel, .danger-panel, .grid > div, .receipt {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-xs);
  margin-bottom: 22px;
}

/* Table Responsive Containers */
.table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 24px;
  box-shadow: var(--shadow-xs);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper);
  border-radius: var(--radius);
  text-align: left;
}

.table-container table {
  border: none;
  border-radius: 0;
  margin-bottom: 0;
  min-width: 620px;
}

thead {
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

th {
  padding: 12px 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 14px;
  color: var(--ink);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #fcfdfe;
}

/* Row highlight for completed/partial payments */
tr.row-paid,
tr.row-paid td {
  background-color: #ecfdf5 !important;
}

tr.row-paid:hover,
tr.row-paid:hover td {
  background-color: #d1fae5 !important;
}

tr.row-paid td:first-child {
  border-left: 4px solid #10b981;
}

tr.row-part-paid,
tr.row-part-paid td {
  background-color: #fffbeb !important;
}

tr.row-part-paid:hover,
tr.row-part-paid:hover td {
  background-color: #fef3c7 !important;
}

tr.row-part-paid td:first-child {
  border-left: 4px solid #f59e0b;
}

/* Forms & Inputs */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.field-label, label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-form input {
  width: auto;
}

/* Buttons */
button, .button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  background: var(--accent);
  color: white;
  min-height: 40px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

button:hover, .button-link:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-sm);
}

button:active, .button-link:active {
  transform: translateY(1px);
}

.button-danger {
  background: var(--warn);
  color: white;
}

.button-danger:hover {
  background: var(--warn-hover);
}

.button-warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

.button-warning:hover {
  background: #fde68a;
  color: #78350f;
}

.button-success {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.button-success:hover {
  background: #d1fae5;
  color: #065f46;
}

.button-outline {
  background: white;
  color: var(--text);
  border: 1px solid var(--line);
}

.button-outline:hover {
  background: #f8fafc;
  color: var(--accent);
  border-color: var(--accent);
}

.button-sm {
  min-height: 32px;
  padding: 5px 11px;
  font-size: 12px;
  border-radius: 6px;
}

.actions-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

/* WhatsApp Notice Button */
.whatsapp-btn {
  background: #25d366;
  color: #ffffff;
  padding: 6px 12px;
  min-height: 32px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  transition: all 0.15s ease;
}

.whatsapp-btn:hover {
  background: #20bd5a;
  color: #ffffff;
  box-shadow: 0 2px 5px rgba(37, 211, 102, 0.28);
  transform: translateY(-1px);
}

.whatsapp-btn:active {
  transform: translateY(1px);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  border: 1px solid transparent;
  background: #f1f5f9;
  color: #475569;
}

.badge-paid, .badge.paid {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
}

.badge-part-paid, .badge.part-paid {
  background: #fffbeb;
  color: #b45309;
  border-color: #fde68a;
}

.badge-overdue, .badge.overdue {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecaca;
}

.badge-unpaid, .badge.unpaid {
  background: #f8fafc;
  color: #475569;
  border-color: #cbd5e1;
}

.badge-active, .badge.active {
  background: #f0fdf4;
  color: #15803d;
  border-color: #bbf7d0;
}

.badge-inactive, .badge-reversed, .badge.inactive, .badge.reversed {
  background: #f1f5f9;
  color: #64748b;
  border-color: #e2e8f0;
}

.badge-left, .badge.left {
  background: #fffbeb;
  color: #b45309;
  border-color: #fde68a;
}

.badge-booking, .badge.booking, .badge-soon, .badge.soon, .badge-soon-to-arrive {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #bae6fd;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
  transition: all 0.15s ease;
  cursor: pointer;
}

.tab-btn:hover {
  background: #f8fafc;
  color: var(--text);
  border-color: var(--accent);
}

.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Danger Panel */
.danger-panel {
  border-color: #fecaca;
  background: #fff5f5;
}

.fee-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 600px) {
  .fee-summary-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}

.danger-panel button {
  background: var(--warn);
}

.danger-panel button:hover {
  background: var(--warn-hover);
}

/* Flash Messages */
.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.message {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  border: 1px solid transparent;
  box-shadow: var(--shadow-xs);
}

.message.success {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}

.message.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

/* Receipt Details */
.receipt {
  max-width: 620px;
}

dl {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 10px;
  margin: 16px 0 20px;
}

dt {
  color: var(--muted);
  font-size: 14px;
}

dd {
  margin: 0;
  font-weight: 600;
  color: var(--ink);
  font-size: 14px;
}

/* ======================================================== */
/* Responsive & Mobile Enhancements                         */
/* ======================================================== */
@media (max-width: 860px) {
  body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid #1e293b;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }

  .sidebar-header {
    margin-bottom: 0;
  }

  .brand h1 {
    font-size: 17px;
  }

  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1e293b;
    border: 1px solid #334155;
    color: #f8fafc;
    border-radius: 8px;
    width: 38px;
    height: 38px;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s ease;
  }

  .menu-toggle:active {
    background: #334155;
  }

  .menu-toggle .close-icon {
    display: none;
  }

  .menu-toggle.is-open .hamburger-icon {
    display: none;
  }

  .menu-toggle.is-open .close-icon {
    display: block;
  }

  .sidebar nav {
    display: none;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #1e293b;
    display: none;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .sidebar nav.nav-open {
    display: grid;
    animation: menuSlide 0.18s ease-out;
  }

  @keyframes menuSlide {
    from {
      opacity: 0;
      transform: translateY(-6px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .sidebar nav a {
    padding: 10px;
    font-size: 13px;
  }

  main {
    padding: 18px 16px 36px;
  }

  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 18px;
  }

  .inline-form {
    width: 100%;
  }

  .inline-form input[type="month"] {
    flex: 1;
    min-width: 0;
  }

  .inline-form button {
    flex-shrink: 0;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 18px;
  }

  .stats article {
    padding: 14px 12px;
    border-radius: 10px;
  }

  .stats article strong {
    font-size: 18px;
  }

  .grid.two {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  /* Uncontained tables scroll horizontally on small screens */
  table:not(.table-container table) {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: 10px;
  }

  th, td {
    padding: 10px 12px;
    font-size: 13px;
    white-space: nowrap;
  }

  /* Inputs on mobile have 16px to prevent iOS auto-zoom */
  input, select, textarea {
    font-size: 16px;
    min-height: 44px;
  }
}

@media (max-width: 540px) {
  .sidebar nav {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  main {
    padding: 14px 12px 28px;
  }

  .panel, article, .danger-panel, .grid > div, .receipt {
    padding: 14px;
    border-radius: 10px;
  }

  dl {
    grid-template-columns: 120px 1fr;
    gap: 8px;
    font-size: 13px;
  }

  h2 {
    font-size: 20px;
  }

  h3 {
    font-size: 16px;
  }

  button, .button-link {
    width: 100%;
  }

  .actions-cell button,
  .actions-cell .button-link,
  .inline-form button {
    width: auto;
  }
}

@media print {
  .sidebar, .messages, button, .menu-toggle {
    display: none !important;
  }
  body {
    display: block;
    background: white;
  }
  main {
    padding: 0;
    max-width: 100%;
  }
}
