:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #fff;
  --bg-sidebar: #1e293b;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --line: 1px solid var(--border);
  --sidebar-line: 1px solid rgba(255,255,255,.08);
  --header-height: 56px;
  --footer-height: 52px;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: rgba(0,0,0,.06);
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-sidebar: #0f172a;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --border: #334155;
  --line: 1px solid var(--border);
  --sidebar-line: 1px solid rgba(255,255,255,.08);
  --shadow: rgba(0,0,0,.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  color: #e2e8f0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  min-height: var(--header-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  font-weight: 700;
  font-size: 1.1rem;
  border-bottom: var(--sidebar-line);
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  color: #cbd5e1;
  text-decoration: none;
  transition: background .15s, color .15s;
}

.sidebar-nav a:hover, .sidebar-nav a.active {
  background: rgba(255,255,255,.08);
  color: #fff;
}

.sidebar-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  background: transparent;
  border: none;
  color: #e2e8f0;
  cursor: pointer;
}
.sidebar-toggle span { display: block; width: 22px; height: 2px; background: currentColor; border-radius: 1px; }
@media (max-width: 768px) {
  .sidebar-toggle { display: flex; order: 2; }
}

.sidebar-nav .submenu {
  padding-left: 20px;
  list-style: none;
}

.sidebar-nav .submenu a { padding: 8px 20px; font-size: .95rem; }

.theme-toggle {
  background: rgba(255,255,255,.1);
  border: none;
  color: #e2e8f0;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  margin: 8px 20px;
}

.theme-toggle:hover { background: rgba(255,255,255,.15); }

.auth-page .theme-toggle {
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}
.auth-page .theme-toggle:hover {
  background: var(--border);
  color: var(--text-primary);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  min-height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: var(--line);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.content {
  flex: 1;
  padding: 24px;
}

.page-title { font-size: 1.5rem; font-weight: 600; margin-bottom: 24px; }

.card {
  background: var(--bg-secondary);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background .15s, color .15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--border); color: var(--text-primary); }
.btn-secondary:hover { background: var(--text-secondary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 14px; color: var(--text-secondary); }
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg-secondary);
  color: var(--text-primary);
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.2); }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
[data-theme="dark"] .alert-error { background: rgba(220,38,38,.15); border-color: rgba(220,38,38,.3); }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
[data-theme="dark"] .alert-success { background: rgba(22,163,74,.15); border-color: rgba(22,163,74,.3); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-secondary); font-size: 13px; }
tr:hover { background: var(--bg-primary); }

.footer-page {
  min-height: var(--footer-height);
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  border-top: var(--line);
  background: var(--bg-secondary);
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-box {
  width: 100%;
  max-width: 420px;
  background: var(--bg-secondary);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 24px var(--shadow);
  padding: 32px;
}

.auth-tabs { display: flex; margin-bottom: 24px; gap: 8px; }
.auth-tabs a {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-secondary);
  font-weight: 500;
}
.auth-tabs a.active { background: var(--accent); color: #fff; }
.auth-tabs a:not(.active):hover { background: var(--bg-primary); }

.auth-form .form-group:last-of-type { margin-bottom: 20px; }
.auth-form .btn { width: 100%; padding: 12px; }

.logo-auth { text-align: center; margin-bottom: 24px; font-size: 1.25rem; font-weight: 700; color: var(--accent); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.modal {
  background: var(--bg-secondary);
  border-radius: 12px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  border: 1px solid var(--border);
}

.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

.receipt-popup { max-width: 400px; }
.receipt-popup .receipt-body { font-family: monospace; font-size: 13px; white-space: pre-wrap; padding: 16px; background: var(--bg-primary); border-radius: 8px; }

.badge { display: inline-block; padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 500; }
.badge-awaiting { background: #fef3c7; color: #92400e; }
.badge-partial { background: #dbeafe; color: #1e40af; }
.badge-paid { background: #d1fae5; color: #065f46; }
.badge-active { background: #e0e7ff; color: #3730a3; }
.badge-cancelled { background: #f1f5f9; color: #64748b; }
[data-theme="dark"] .badge-awaiting { background: rgba(245,158,11,.2); }
[data-theme="dark"] .badge-partial { background: rgba(59,130,246,.2); }
[data-theme="dark"] .badge-paid { background: rgba(34,197,94,.2); }
[data-theme="dark"] .badge-active { background: rgba(99,102,241,.2); }
[data-theme="dark"] .badge-cancelled { background: rgba(100,116,139,.2); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 24px; }
.stats-card { padding: 20px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-secondary); }
.stats-card h3 { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.stats-card .value { font-size: 24px; font-weight: 700; }

.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.admin-card { display: block; padding: 20px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-secondary); color: var(--text-primary); text-decoration: none; transition: border-color .15s, box-shadow .15s; }
.admin-card:hover { border-color: var(--accent); box-shadow: 0 4px 12px var(--shadow); }
.admin-card-title { display: block; font-weight: 600; font-size: 1.05rem; margin-bottom: 6px; }
.admin-card-desc { display: block; font-size: 13px; color: var(--text-secondary); }

.btn-resend {
  display: inline-block;
  margin-top: 10px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background .15s;
}
.btn-resend:hover { background: var(--accent-hover); color: #fff; }

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 0 12px;
    min-height: auto;
  }
  .sidebar-brand { flex: 1; border-bottom: none; min-height: 48px; }
  .sidebar-nav {
    order: 3;
    width: 100%;
    flex: none;
    padding: 8px 0;
    border-top: var(--sidebar-line);
    max-height: 0;
    overflow: hidden;
    transition: max-height .2s;
  }
  .sidebar-nav.open { max-height: 400px; }
  .sidebar .theme-toggle { order: 2; margin: 8px 0; }
  .sidebar-nav a { padding: 12px 20px; min-height: 44px; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; min-height: 48px; flex-wrap: wrap; gap: 8px; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }
  th, td { padding: 10px 12px; font-size: 14px; }
  .btn { min-height: 44px; padding: 12px 16px; }
  .auth-box { padding: 24px 20px; margin: 12px; }
  .auth-tabs a { padding: 12px; min-height: 44px; display: flex; align-items: center; justify-content: center; }
  .form-control { min-height: 44px; padding: 12px; }
  .page-title { font-size: 1.25rem; margin-bottom: 16px; }
  .admin-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .auth-page { padding: 12px; }
  .auth-box { padding: 20px 16px; }
}
