:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --sidebar-bg: #111c1a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1b2e2a;
  --accent: #0f766e;
  --accent-hover: #0d5e57;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

/* Login Page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
}

.login-card p {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 13px;
}

/* App Shell */
.app-layout {
  display: flex;
  min-height: 100vh;
}

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

.sidebar-header {
  padding: 18px 16px;
  font-weight: 600;
  font-size: 15px;
  color: #ffffff;
  border-bottom: 1px solid #1e293b;
}

.sidebar-nav {
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  padding: 9px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--sidebar-active);
  color: #ffffff;
}

.nav-item.active {
  background: var(--accent);
  color: #ffffff;
  font-weight: 500;
}

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid #1e293b;
}

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

.topbar {
  height: 54px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.menu-toggle {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 14px;
}

.page-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.admin-badge {
  font-size: 13px;
  color: var(--text-muted);
}

.main-content {
  padding: 24px 28px;
  width: 100%;
}

/* Cards & Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.stat-value {
  margin-top: 6px;
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.chart-card {
  margin-bottom: 20px;
}

.chart-summary {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.segmented-control {
  display: inline-flex;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.svg-chart {
  width: 100%;
  height: auto;
  display: block;
}

.chart-val-label {
  font-size: 11px;
  font-weight: 600;
  fill: var(--text);
  font-variant-numeric: tabular-nums;
}

.chart-day-label {
  font-size: 11px;
  font-weight: 500;
  fill: var(--text-muted);
}

.chart-day-label.is-today {
  fill: var(--accent);
  font-weight: 700;
}

.chart-date-label {
  font-size: 10px;
  fill: #94a3b8;
  font-variant-numeric: tabular-nums;
}

.chart-bar-group rect {
  transition: opacity 0.15s ease;
}

.chart-bar-group:hover rect {
  opacity: 0.85;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

/* Toolbar & Filters */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar input,
.toolbar select {
  width: auto;
  min-width: 150px;
}

.toolbar input[type="search"] {
  flex: 1;
  min-width: 200px;
}

/* Forms */
.form-group {
  margin-bottom: 14px;
}

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

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn:hover {
  background: #f1f5f9;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

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

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

.actions-cell {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-weight: 600;
  color: var(--text-muted);
  background: #f8fafc;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.badge-available, .badge-confirmed {
  background: #dcfce7;
  color: #166534;
}

.badge-pending, .badge-maintenance {
  background: #fef3c7;
  color: #92400e;
}

.badge-completed {
  background: #dbeafe;
  color: #1e40af;
}

.badge-cancelled, .badge-inactive {
  background: #f1f5f9;
  color: #475569;
}

/* Alerts & Toasts */
.alert-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 9px 12px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 13px;
}

.summary-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 13px;
}

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  background: var(--text);
  color: #ffffff;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  max-width: 320px;
}

.toast.toast-error {
  background: var(--danger);
}

.toast.toast-success {
  background: var(--accent);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 900;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
}

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

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.hidden {
  display: none !important;
}

/* Schedule Grid */
.schedule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 16px;
}

.schedule-court-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.schedule-court-header {
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.schedule-empty {
  padding: 12px 14px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Responsive */
@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .main-content {
    padding: 16px;
  }

  .schedule-grid {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: -240px;
    top: 0;
    bottom: 0;
    z-index: 950;
    transition: left 0.15s ease;
  }

  .sidebar.open {
    left: 0;
  }

  .menu-toggle {
    display: inline-block;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .toolbar input,
  .toolbar select {
    width: 100%;
  }
}
