:root {
  --blue: #1d6fb8;
  --blue-light: #e6f1fa;
  --blue-dark: #15578f;
  --orange: #f5921e;
  --orange-light: #fef3e6;
  --green: #4caf50;
  --green-light: #eaf7eb;
  --red: #c0274a;
  --red-light: #fbe9ee;
  --amber: #92400e;
  --amber-light: #fef3c7;

  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;

  --radius: 10px;
  --radius-lg: 16px;

  --bg: #e7ebf0;
  --surface: #e7ebf0;
  --text-dark: #2c3440;
  --text-muted: #62707f;

  --shadow-out: 7px 7px 14px rgba(163,177,198,0.5), -7px -7px 14px rgba(255,255,255,0.85);
  --shadow-out-sm: 4px 4px 8px rgba(163,177,198,0.45), -4px -4px 8px rgba(255,255,255,0.8);
  --shadow-out-xs: 2px 2px 5px rgba(163,177,198,0.4), -2px -2px 5px rgba(255,255,255,0.75);
  --shadow-in: inset 4px 4px 8px rgba(163,177,198,0.5), inset -4px -4px 8px rgba(255,255,255,0.8);
  --shadow-pressed: inset 3px 3px 6px rgba(163,177,198,0.55), inset -3px -3px 6px rgba(255,255,255,0.65);

  --shadow: var(--shadow-out-sm);
  --shadow-md: var(--shadow-out);
}

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

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

.screen:not(.active) { display: none !important; }
.screen.active { display: block; }
#login-screen.active { display: flex; }
#main-screen { min-height: 100vh; }
.hidden { display: none !important; }

/* LOGIN */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1rem;
}

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

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 1.75rem;
}

.login-logo h1 { font-size: 20px; font-weight: 600; color: var(--text-dark); }
.login-logo p { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.csj-logo {
  width: 48px; height: 48px; object-fit: contain; flex-shrink: 0;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-out-sm);
  padding: 4px;
}
.csj-logo-small {
  width: 28px; height: 28px; object-fit: contain; flex-shrink: 0;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-out-xs);
  padding: 2px;
}

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

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 1rem 0;
  color: var(--text-muted);
  font-size: 12px;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(163,177,198,0.35);
}

/* NAVBAR */
.navbar {
  background: var(--surface);
  box-shadow: 0 3px 10px rgba(163,177,198,0.35);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  height: 60px;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-dark);
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  background: none;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: box-shadow 0.15s, color 0.15s;
}
.nav-btn:hover { box-shadow: var(--shadow-out-xs); color: var(--text-dark); }
.nav-btn.active { box-shadow: var(--shadow-pressed); color: var(--blue); }

.nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--text-muted);
}

#nav-username { font-weight: 600; color: var(--text-dark); }

.nav-burger {
  display: none;
  background: var(--surface);
  border: none;
  color: var(--text-dark);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius);
  flex-shrink: 0;
  box-shadow: var(--shadow-out-xs);
}
.nav-burger:active { box-shadow: var(--shadow-pressed); }

.nav-links-divider { display: none; }
.nav-user-mobile { display: none; }

/* MAIN */
main { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }

/* FORMS */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}
input[type=text], input[type=password], input[type=email],
input[type=date], input[type=time], select, textarea {
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface);
  color: var(--text-dark);
  outline: none;
  box-shadow: var(--shadow-in);
  transition: box-shadow 0.15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  box-shadow: var(--shadow-pressed), 0 0 0 2px rgba(29,111,184,0.25);
}
textarea { resize: vertical; min-height: 80px; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s;
  font-family: inherit;
  line-height: 1;
  background: var(--surface);
  color: var(--text-dark);
  box-shadow: var(--shadow-out-sm);
}
.btn:hover { box-shadow: var(--shadow-out); }
.btn:active { box-shadow: var(--shadow-pressed); transform: scale(0.98); }

.btn-primary {
  background: var(--blue);
  color: white;
  box-shadow: 4px 4px 10px rgba(29,111,184,0.4), -2px -2px 6px rgba(255,255,255,0.5);
}
.btn-primary:hover { box-shadow: 6px 6px 14px rgba(29,111,184,0.45), -2px -2px 6px rgba(255,255,255,0.5); }
.btn-primary:active { box-shadow: inset 3px 3px 6px rgba(0,0,0,0.25); }

.btn-danger {
  background: var(--red);
  color: white;
  box-shadow: 4px 4px 10px rgba(192,39,74,0.4), -2px -2px 6px rgba(255,255,255,0.5);
}
.btn-danger:hover { box-shadow: 6px 6px 14px rgba(192,39,74,0.45), -2px -2px 6px rgba(255,255,255,0.5); }
.btn-danger:active { box-shadow: inset 3px 3px 6px rgba(0,0,0,0.25); }

.btn-ghost { background: var(--surface); color: var(--text-muted); box-shadow: var(--shadow-out-xs); }
.btn-ghost:hover { color: var(--text-dark); }
.btn-ghost:active { box-shadow: var(--shadow-pressed); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-icon { padding: 7px; box-shadow: var(--shadow-out-xs); color: var(--text-muted); }
.btn-icon:hover { color: var(--text-dark); }

.btn-office {
  background: var(--surface);
  color: var(--text-dark);
  box-shadow: var(--shadow-out-sm);
}
.btn-office:hover { box-shadow: var(--shadow-out); }
.btn-office:active { box-shadow: var(--shadow-pressed); }

/* CARDS */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-out);
  padding: 1.25rem;
}

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface);
  box-shadow: var(--shadow-out-xs);
}
.badge-blue { color: var(--blue); }
.badge-green { color: var(--green); }
.badge-red { color: var(--red); }
.badge-amber { color: var(--amber); }
.badge-gray { color: var(--text-muted); }

/* ALERTS */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-in);
}
.alert-error { color: var(--red); }
.alert-success { color: var(--green); }

/* CALENDAR */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 10px;
}

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.calendar-nav h2 {
  font-size: 16px;
  font-weight: 600;
  min-width: 180px;
  text-align: center;
}

.calendar-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.calendar-filters select { width: auto; }

.week-grid {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-out);
  overflow: hidden;
}

.week-grid-header {
  display: grid;
  grid-template-columns: 64px repeat(5, 1fr);
  box-shadow: var(--shadow-in);
}

.week-grid-header div {
  padding: 10px 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.week-grid-header .today-col { color: var(--blue); }

.week-grid-body {
  display: grid;
  grid-template-columns: 64px repeat(5, 1fr);
  grid-auto-rows: 48px;
  max-height: 600px;
  overflow-y: auto;
}

.time-label {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  padding: 0 8px;
  height: 48px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding-top: 4px;
}

.day-col {
  border-left: 1px solid rgba(163,177,198,0.25);
  position: relative;
}

.time-slot {
  height: 48px;
  border-bottom: 1px solid rgba(163,177,198,0.18);
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}

.time-slot:hover { background: rgba(29,111,184,0.07); }
.time-slot.unavailable { background: rgba(163,177,198,0.15); cursor: not-allowed; }

.booking-block {
  position: absolute;
  border-radius: 8px;
  padding: 5px 7px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  z-index: 2;
  overflow: hidden;
  line-height: 1.35;
  transition: box-shadow 0.1s, transform 0.1s;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--surface);
  box-shadow: var(--shadow-out-xs);
}
.booking-block:hover { box-shadow: var(--shadow-out-sm); transform: translateY(-1px); }
.booking-block.mine { color: var(--blue-dark); border-left: 3px solid var(--blue); }
.booking-block.other { color: #b35a00; border-left: 3px solid var(--orange); }
.booking-block strong { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-dark); }
.booking-block-meta { font-size: 10px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.booking-block-user { font-size: 10px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: auto; }

.booking-block.crowded { padding: 4px 6px; border-left-width: 2px; }
.booking-block.crowded strong { font-size: 10.5px; }
.booking-block.crowded .booking-block-meta { font-size: 9px; }

/* MY BOOKINGS */
.bookings-list { display: flex; flex-direction: column; gap: 10px; }

.booking-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-out-sm);
  padding: 14px 16px;
}

.booking-date-box {
  background: var(--surface);
  box-shadow: var(--shadow-in);
  border-radius: var(--radius);
  padding: 8px 10px;
  text-align: center;
  flex-shrink: 0;
  min-width: 50px;
}

.booking-date-box .day { font-size: 22px; font-weight: 700; color: var(--blue); line-height: 1; }
.booking-date-box .month { font-size: 11px; color: var(--blue); text-transform: uppercase; margin-top: 2px; }

.booking-info { flex: 1; }
.booking-info h3 { font-size: 14px; font-weight: 600; margin-bottom: 3px; }
.booking-info p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.booking-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* RESOURCES */
.resources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.resource-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-out);
  overflow: hidden;
}

.resource-card-header {
  padding: 16px 16px 10px;
}

.resource-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-out-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  font-size: 20px;
}

.resource-card h3 { font-size: 14px; font-weight: 600; }
.resource-card p { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.resource-card-body { padding: 12px 16px 16px; }

.resource-meta { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.resource-meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ADMIN */
.admin-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 1.5rem;
  background: var(--surface);
  box-shadow: var(--shadow-in);
  border-radius: var(--radius);
  padding: 6px;
}

.admin-tab {
  padding: 9px 16px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  transition: box-shadow 0.15s, color 0.15s;
}
.admin-tab.active { color: var(--blue); background: var(--surface); box-shadow: var(--shadow-out-sm); }
.admin-tab:hover:not(.active) { color: var(--text-dark); }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 12px 12px;
  font-weight: 600;
  color: var(--text-muted);
  box-shadow: var(--shadow-in);
}
.data-table td {
  padding: 12px 12px;
  vertical-align: middle;
  border-bottom: 1px solid rgba(163,177,198,0.2);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(29,111,184,0.05); }

/* PAGE HEADER */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 10px;
}

.page-header h1 { font-size: 20px; font-weight: 600; }
.page-header p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44,52,64,0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: 12px 12px 28px rgba(20,28,40,0.35), -6px -6px 16px rgba(255,255,255,0.12);
  max-height: 90vh;
  overflow-y: auto;
}

.modal.modal-lg { max-width: 760px; }

.inventory-table input, .inventory-table select { width: 100%; min-width: 0; }
.inventory-table td { padding: 8px; }
.inventory-table th:first-child, .inventory-table td:first-child { min-width: 220px; }
.inventory-table th:nth-child(3), .inventory-table td:nth-child(3) { min-width: 180px; }

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

.modal-header h2 { font-size: 16px; font-weight: 600; }
#modal-body { padding: 0 1.25rem 1.25rem; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--surface);
  color: var(--text-dark);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  z-index: 9999;
  animation: slideUp 0.2s ease;
  max-width: 320px;
  box-shadow: var(--shadow-out);
}

.toast.success { color: var(--green); }
.toast.error { color: var(--red); }

@keyframes slideUp {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* INSTALL BANNER (PWA) */
.install-banner {
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  right: 1.5rem;
  max-width: 460px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-out);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 9998;
  animation: slideUp 0.25s ease;
}

.install-banner-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-out-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.install-banner-icon img { border-radius: 8px; }

.install-banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.install-banner-text strong { font-size: 13px; color: var(--text-dark); }
.install-banner-text span { font-size: 11.5px; color: var(--text-muted); line-height: 1.3; }

@media (max-width: 640px) {
  .install-banner { left: 0.75rem; right: 0.75rem; bottom: 0.75rem; padding: 12px; }
  .install-banner-text span { font-size: 11px; }
}

.install-steps {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.install-steps li {
  counter-increment: step;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13px;
  color: var(--text-dark);
  line-height: 1.45;
}
.install-steps li::before {
  content: counter(step);
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-out-sm);
  color: var(--blue);
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 14px; }

/* GRID ROW for forms */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* STAT CARDS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-out);
  padding: 1rem;
}

.stat-card .stat-label { font-size: 12px; color: var(--text-muted); }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; color: var(--blue); }

/* RESPONSIVE */
@media (max-width: 900px) {
  .week-grid-header, .week-grid-body { grid-template-columns: 50px repeat(5, minmax(110px, 1fr)); }
  .week-grid { overflow-x: auto; }
  .week-grid-header { min-width: 600px; }
  .week-grid-body { min-width: 600px; }
}

@media (max-width: 640px) {
  body { font-size: 13px; }

  .navbar {
    padding: 0 0.75rem;
    position: relative;
  }
  .nav-brand span { font-size: 14px; }
  .nav-brand { flex: 1; }

  .nav-burger { display: block; }

  .nav-user { display: none; }

  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0.5rem;
    right: 0.5rem;
    margin-top: 8px;
    background: var(--surface);
    box-shadow: var(--shadow-out);
    border-radius: var(--radius-lg);
    flex-direction: column;
    align-items: stretch;
    padding: 8px;
    gap: 2px;
    z-index: 200;
  }
  .nav-links.open { display: flex; }

  .nav-btn {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 12px 14px;
    font-size: 14px;
    width: 100%;
  }
  .nav-btn span { display: inline; font-size: 14px; }
  .nav-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

  .nav-links-divider {
    display: block;
    height: 1px;
    background: rgba(163,177,198,0.3);
    margin: 6px 4px;
  }
  .nav-user-mobile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px 4px;
    font-size: 13px;
    color: var(--text-muted);
  }
  .nav-user-mobile span { font-weight: 600; color: var(--text-dark); }

  main { padding: 0.75rem; }

  .page-header { flex-direction: column; align-items: stretch; }
  .page-header h1 { font-size: 17px; }
  .page-header .btn { width: 100%; justify-content: center; }

  .calendar-header { flex-direction: column; align-items: stretch; }
  .calendar-nav { justify-content: space-between; }
  .calendar-nav h2 { font-size: 14px; min-width: 0; flex: 1; }
  .calendar-filters select { width: 100%; }

  .week-grid-header, .week-grid-body { grid-template-columns: 42px repeat(5, minmax(96px, 1fr)); }
  .week-grid-header { min-width: 520px; }
  .week-grid-body { min-width: 520px; max-height: 70vh; }
  .time-label { font-size: 10px; padding-top: 2px; }
  .booking-block strong { font-size: 10.5px; }
  .booking-block-meta, .booking-block-user { font-size: 9px; }

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

  .booking-item { flex-wrap: wrap; }
  .booking-actions { width: 100%; justify-content: space-between; margin-top: 6px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  .admin-tabs { overflow-x: auto; }
  .admin-tab { white-space: nowrap; padding: 8px 12px; }

  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 6px; }

  .modal { max-width: 100%; margin: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92vh; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-header { padding: 1rem 1rem 0; }
  #modal-body { padding: 0 1rem 1rem; }

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

  .login-card { padding: 1.5rem; }
}
