:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #1e293b;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-sidebar: #e2e8f0;
  --border: #e2e8f0;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}

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

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

/* Login */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}

.login-card {
  background: var(--bg-card);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  text-align: center;
}

.login-card p,
.login-desc {
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
}

.login-form {
  transition: opacity 0.2s;
}

.login-switch {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 1rem;
}

.login-switch a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.login-switch a:hover {
  text-decoration: underline;
}

/* Form */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-block { width: 100%; justify-content: center; }

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

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 0 1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
  margin-bottom: 0.5rem;
}

.sidebar-brand h2 {
  font-size: 1.125rem;
  color: #fff;
}

.sidebar-brand small {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sidebar-nav {
  list-style: none;
  flex: 1;
}

.sidebar-nav li a {
  display: block;
  padding: 0.625rem 1rem;
  color: var(--text-sidebar);
  text-decoration: none;
  font-size: 0.875rem;
  transition: background 0.2s;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
  background: rgba(255,255,255,.1);
}

.sidebar-footer {
  padding: 0.5rem 1rem;
  border-top: 1px solid rgba(255,255,255,.1);
}

.sidebar-footer button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
}

.sidebar-footer button:hover {
  color: #fff;
}

/* Main content */
.main-content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.5rem;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-header h3 {
  font-size: 1rem;
}

/* Stat cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  text-align: left;
  padding: 0.75rem;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}

tbody td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

tbody tr:hover {
  background: #f1f5f9;
}

tbody tr.clickable {
  cursor: pointer;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }

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

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: 0 20px 25px -5px rgba(0,0,0,.1);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1.125rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* Toast */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.875rem;
  min-width: 250px;
  animation: slideIn 0.3s ease;
}

.toast-success { background: #dcfce7; color: #166534; border-left: 4px solid var(--success); }
.toast-error { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--danger); }
.toast-info { background: #dbeafe; color: #1e40af; border-left: 4px solid var(--primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-bar .form-group {
  margin-bottom: 0;
  min-width: 150px;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.25rem;
  margin-top: 1rem;
}

.pagination button {
  padding: 0.375rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
}

.pagination button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Loading */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

/* Hidden */
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 200px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-bar { flex-direction: column; }
}

/* Settings page */
.settings-section {
  margin-bottom: 1.5rem;
}

/* Discount table inputs */
.discount-pct,
.discount-desc {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
}

/* Form grid */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid .full-width {
  grid-column: 1 / -1;
}

@media (max-width: 640px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    padding: 0.5rem;
  }
  .sidebar-brand { display: none; }
  .sidebar-nav { display: flex; }
  .sidebar-nav li a { white-space: nowrap; }
  .sidebar-footer { display: none; }
  .stats-grid { grid-template-columns: 1fr; }
}

/* Billing styles */
.billing-alert {
  border-left: 4px solid var(--warning);
  background: #fffbeb;
}

.billing-alert ul {
  list-style: none;
  padding: 0;
}

.billing-alert li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.billing-alert li:last-child {
  border-bottom: none;
}

.payment-voided {
  text-decoration: line-through;
}
