/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4F46E5;
  --primary-dark: #4338CA;
  --primary-light: #EEF2FF;
  --success: #16A34A;
  --success-light: #DCFCE7;
  --warning: #D97706;
  --warning-light: #FEF3C7;
  --danger: #DC2626;
  --danger-light: #FEE2E2;
  --gray-50: #F8FAFC;
  --gray-100: #F1F5F9;
  --gray-200: #E2E8F0;
  --gray-300: #CBD5E1;
  --gray-400: #94A3B8;
  --gray-500: #64748B;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1E293B;
  --gray-900: #0F172A;
  --white: #FFFFFF;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.12), 0 4px 10px rgba(0,0,0,.08);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.error { color: var(--danger); font-size: .875rem; margin-top: .5rem; }
.label-hint { color: var(--gray-400); font-size: .75rem; font-weight: 400; }

/* ── Buttons ── */
button { cursor: pointer; border: none; font-family: inherit; font-size: .875rem; font-weight: 500; border-radius: var(--radius-sm); transition: all .15s; }

.btn-primary {
  background: var(--primary);
  color: var(--white);
  padding: .5rem 1rem;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(.98); }

.btn-secondary {
  background: var(--white);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
  padding: .5rem 1rem;
}
.btn-secondary:hover { background: var(--gray-50); border-color: var(--gray-300); }

.btn-ghost {
  background: transparent;
  color: var(--gray-600);
  padding: .5rem .75rem;
}
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-800); }

.btn-success {
  background: var(--success);
  color: var(--white);
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  border: none;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.btn-success:hover { background: #15803D; }

.btn-full { width: 100%; padding: .75rem; font-size: 1rem; }

.btn-icon {
  display: flex;
  align-items: center;
  gap: .375rem;
  background: var(--white);
  color: var(--gray-700);
  border: 1px solid var(--gray-200);
  padding: .5rem .875rem;
}
.btn-icon:hover { background: var(--gray-50); }
.btn-icon svg { width: 15px; height: 15px; }

/* ── Login ── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
  background: var(--white);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo { font-size: 2.5rem; margin-bottom: .75rem; }
.login-card h1 { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); margin-bottom: .375rem; }
.login-sub { color: var(--gray-500); font-size: .9rem; margin-bottom: 1.5rem; }

.login-card input[type="password"] {
  width: 100%;
  padding: .75rem 1rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  margin-bottom: .75rem;
  transition: border-color .15s;
  outline: none;
}
.login-card input[type="password"]:focus { border-color: var(--primary); }

/* ── App Header ── */
.app-header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-left { display: flex; align-items: center; gap: .625rem; }
.header-logo { font-size: 1.375rem; }
.header-title { font-size: 1.125rem; font-weight: 700; color: var(--gray-900); }

.header-right { display: flex; align-items: center; gap: .5rem; }

/* ── Tab Nav ── */
.tab-nav {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  padding: 0 1.5rem;
  gap: 0;
}

.tab-btn {
  background: transparent;
  color: var(--gray-500);
  padding: .875rem 1.25rem;
  border-radius: 0;
  border-bottom: 2.5px solid transparent;
  font-size: .9rem;
  font-weight: 500;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--gray-800); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Main ── */
.app-main { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-100);
}

.stat-label { font-size: .75rem; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .375rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--gray-900); line-height: 1.2; }
.stat-icon { font-size: 1.25rem; margin-bottom: .5rem; }

/* ── Section Heading ── */
.section-heading {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 1rem;
}

/* ── Booking Cards (Today) ── */
.booking-card {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  margin-bottom: .75rem;
  overflow: hidden;
  transition: box-shadow .15s;
}
.booking-card:hover { box-shadow: var(--shadow); }

.booking-card-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  cursor: pointer;
  user-select: none;
}

.booking-time {
  font-size: .875rem;
  font-weight: 600;
  color: var(--primary);
  min-width: 60px;
}

.booking-main { flex: 1; min-width: 0; }
.booking-client { font-size: .9375rem; font-weight: 600; color: var(--gray-900); }
.booking-meta { font-size: .8125rem; color: var(--gray-500); margin-top: .125rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.booking-right { display: flex; align-items: center; gap: .625rem; flex-shrink: 0; }

.badge {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .2rem .5rem;
  border-radius: 20px;
}
.badge-paid { background: var(--success-light); color: var(--success); }
.badge-pending { background: var(--warning-light); color: var(--warning); }

.chevron { color: var(--gray-400); font-size: .75rem; transition: transform .2s; }
.chevron.open { transform: rotate(180deg); }

.booking-card-body {
  display: none;
  border-top: 1px solid var(--gray-100);
  padding: 1rem 1.25rem;
  background: var(--gray-50);
}
.booking-card-body.open { display: block; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .625rem 1.5rem;
  margin-bottom: 1rem;
}
.detail-item label { font-size: .75rem; color: var(--gray-500); font-weight: 500; display: block; }
.detail-item span { font-size: .875rem; color: var(--gray-800); word-break: break-word; }

.booking-card-actions { display: flex; gap: .5rem; }
.btn-sm {
  font-size: .8125rem;
  padding: .375rem .75rem;
  border-radius: var(--radius-sm);
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray-400);
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.empty-state p { font-size: .9375rem; }

/* ── Week View ── */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.week-label { font-weight: 600; color: var(--gray-700); font-size: .9375rem; }

.week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .5rem;
  margin-bottom: 1.5rem;
}

.week-day-card {
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  padding: .75rem .5rem;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  min-height: 90px;
}
.week-day-card:hover { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.week-day-card.selected { border-color: var(--primary); background: var(--primary-light); }
.week-day-card.is-today .day-name { color: var(--primary); }
.week-day-card.is-today .day-num { background: var(--primary); color: var(--white); border-radius: 50%; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; margin: .25rem auto; }

.day-name { font-size: .6875rem; font-weight: 600; text-transform: uppercase; color: var(--gray-500); letter-spacing: .05em; }
.day-num { font-size: 1.125rem; font-weight: 700; color: var(--gray-800); margin: .25rem 0; }
.day-count { font-size: .6875rem; color: var(--gray-500); }
.day-count.has-jobs { background: var(--primary); color: var(--white); border-radius: 10px; padding: .1rem .4rem; font-weight: 600; }

.week-detail {
  background: var(--white);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.week-detail h3 { font-size: 1rem; font-weight: 600; color: var(--gray-700); margin-bottom: 1rem; }

/* ── All Bookings Table ── */
.all-toolbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
}
.search-icon {
  position: absolute;
  left: .75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--gray-400);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  padding: .5rem .75rem .5rem 2.375rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.search-wrap input:focus { border-color: var(--primary); }

.table-wrap { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow-sm); }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  font-size: .875rem;
}
thead th {
  background: var(--gray-50);
  padding: .75rem 1rem;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--gray-800); }
thead th .sort-arrow { margin-left: .25rem; opacity: .5; }
tbody tr { border-bottom: 1px solid var(--gray-100); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); }
tbody td { padding: .875rem 1rem; color: var(--gray-700); vertical-align: middle; }
tbody td.mono { font-family: monospace; font-size: .8125rem; color: var(--gray-500); }
.td-actions { display: flex; gap: .375rem; }

/* ── Modals ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  background: var(--white);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card-sm { max-width: 420px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-100);
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 1;
}
.modal-header h2 { font-size: 1.0625rem; font-weight: 700; color: var(--gray-900); }
.close-btn { background: var(--gray-100); color: var(--gray-500); width: 28px; height: 28px; border-radius: 50%; font-size: .8125rem; display: flex; align-items: center; justify-content: center; }
.close-btn:hover { background: var(--gray-200); color: var(--gray-800); }

.pay-job-label { padding: .75rem 1.5rem 0; font-size: .875rem; color: var(--gray-500); }

/* ── Forms ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  padding: 1.25rem 1.5rem;
}
.form-full { grid-column: 1 / -1; }

.form-group label {
  display: block;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: .375rem;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: .5625rem .75rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: inherit;
  color: var(--gray-800);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: var(--white);
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .1);
}
.form-group textarea { resize: vertical; min-height: 72px; }

.form-error {
  margin: 0 1.5rem .25rem;
  padding: .625rem .875rem;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: .8125rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
  border-radius: 0 0 14px 14px;
}

/* ── Status Bar ── */
.status-bar {
  text-align: center;
  padding: .625rem 1rem;
  font-size: .75rem;
  color: var(--gray-400);
  border-top: 1px solid var(--gray-200);
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
}
.poll-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gray-300);
  display: inline-block;
  transition: background .3s;
}
.poll-dot.active { background: var(--success); }
.status-error { color: var(--danger); }

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  margin-right: .375rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Skeleton loader ── */
.skeleton {
  background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
  height: 80px;
  margin-bottom: .75rem;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ── Responsive ── */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .week-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 640px) {
  .app-header { padding: .75rem 1rem; }
  .header-title { font-size: 1rem; }
  .btn-icon span { display: none; }
  .header-right gap { gap: .375rem; }

  .tab-nav { padding: 0 .5rem; overflow-x: auto; }
  .tab-btn { padding: .75rem .875rem; font-size: .8125rem; white-space: nowrap; }

  .app-main { padding: 1rem; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: .625rem; }
  .stat-card { padding: 1rem; }
  .stat-value { font-size: 1.375rem; }

  .week-grid { grid-template-columns: repeat(4, 1fr); }

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

  .modal-card { max-height: 95vh; }

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

  table { font-size: .8125rem; }
  thead th, tbody td { padding: .625rem .75rem; }

  .td-actions { flex-direction: column; gap: .25rem; }
  .td-actions .btn-sm { width: 100%; }
}

@media (max-width: 480px) {
  .week-grid { grid-template-columns: repeat(4, 1fr); }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
