/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --judo-red: #c0392b;
  --judo-red-dark: #962d22;
  --judo-red-light: #e74c3c;
  --judo-black: #1a1a2e;
  --judo-dark: #16213e;
  --judo-navy: #0f3460;
  --judo-gold: #f39c12;
  --judo-gold-light: #f5d76e;
  --white: #ffffff;
  --gray-100: #f8f9fa;
  --gray-200: #e9ecef;
  --gray-300: #dee2e6;
  --gray-500: #adb5bd;
  --gray-700: #495057;
  --gray-900: #212529;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.18);
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, var(--judo-black) 0%, var(--judo-navy) 100%);
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  color: var(--gray-900);
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

#appContainer {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
}

/* ===== Auth Screen ===== */
.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo .logo {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border-radius: 50%;
  background: white;
  padding: 8px;
  box-shadow: var(--shadow-lg), 0 0 0 4px var(--judo-gold);
  margin-bottom: 16px;
}

.auth-logo h1 {
  color: var(--white);
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.auth-subtitle {
  color: var(--judo-gold-light);
  font-size: 1rem;
  margin-top: 4px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.auth-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 380px;
  margin-bottom: 16px;
}

.auth-row input {
  padding: 14px 16px;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 1rem;
  backdrop-filter: blur(8px);
  transition: border-color 0.2s, background 0.2s;
}

.auth-row input::placeholder {
  color: rgba(255,255,255,0.5);
}

.auth-row input:focus {
  outline: none;
  border-color: var(--judo-gold);
  background: rgba(255,255,255,0.15);
}

.auth-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 380px;
  width: 100%;
}

.auth-status {
  margin-top: 16px;
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  text-align: center;
}

/* ===== Buttons ===== */
button, .btn-primary, .btn-secondary, .btn-danger {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  letter-spacing: 0.3px;
}

.btn-primary {
  background: var(--judo-red);
  color: white;
  box-shadow: 0 2px 8px rgba(192,57,43,0.35);
}

.btn-primary:hover {
  background: var(--judo-red-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(192,57,43,0.5);
}

.btn-secondary {
  background: rgba(255,255,255,0.12);
  color: white;
  border: 1px solid rgba(255,255,255,0.25);
  backdrop-filter: blur(4px);
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.2);
  transform: translateY(-1px);
}

.btn-danger {
  background: #6c1e1e;
  color: white;
}

.btn-danger:hover {
  background: #8b2020;
  transform: translateY(-1px);
}

.btn-logout {
  padding: 8px 16px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-logout:hover {
  background: var(--judo-red);
  border-color: var(--judo-red);
}

.btn-help {
  padding: 8px 16px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-help:hover {
  background: var(--judo-gold);
  border-color: var(--judo-gold);
  color: var(--judo-black);
}

/* ===== App Header ===== */
.app-header {
  background: rgba(15, 52, 96, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 2px solid var(--judo-gold);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 100%;
}

.app-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  width: 100%;
}

.header-logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 50%;
  background: white;
  padding: 4px;
  box-shadow: 0 0 0 2px var(--judo-gold);
  flex-shrink: 0;
}

.header-title {
  flex: 1;
  min-width: 0;
}

.header-title h1 {
  color: white;
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.header-subtitle {
  color: var(--judo-gold-light);
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ===== App Body ===== */
.app-body {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

.app-body > * {
  min-width: 0;
}

/* ===== Card ===== */
.card {
  background: rgba(255,255,255,0.97);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-md);
  width: 100%;
  min-width: 0;
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}

.toolbar-label {
  display: flex;
  flex-direction: column;
  flex: 1 1 220px;
  gap: 5px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--gray-700);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.toolbar-label select,
.toolbar-label input[type="month"] {
  padding: 10px 12px;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: white;
  transition: border-color 0.2s;
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 52px;
  color: var(--gray-900);
  appearance: none;
  -webkit-appearance: none;
}

.toolbar-label select:focus,
.toolbar-label input[type="month"]:focus {
  outline: none;
  border-color: var(--judo-red);
}

.toolbar-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 8px;
  align-items: stretch;
  width: 100%;
  margin-left: 0;
}

.toolbar-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 64px;
  padding: 12px 16px;
  background: var(--judo-navy);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
  cursor: pointer;
  transition: all 0.2s;
}

.toolbar-actions button:hover {
  background: var(--judo-red);
  transform: translateY(-1px);
}

/* ===== Legend ===== */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px 20px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gray-700);
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 2px solid transparent;
  flex-shrink: 0;
}

.legend-dot.weekend {
  background: #e8e8e8;
  border-color: #999;
}

.legend-dot.holiday {
  background: #ffcdd2;
  border-color: #e57373;
}

.legend-dot.school-holiday {
  background: #ffe0b2;
  border-color: #ffb74d;
}

.legend-dot.has-data {
  background: #c8e6c9;
  border-color: #66bb6a;
}

.legend-dot.has-competition {
  background: #bbdefb;
  border-color: #42a5f5;
}

/* ===== Calendar ===== */
.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.calendar-header {
  background: var(--judo-navy);
  color: white;
  font-weight: 700;
  text-align: center;
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.calendar-day {
  aspect-ratio: 1;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 6px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  background: white;
  min-height: 60px;
}

.calendar-day:hover:not(.disabled) {
  transform: scale(1.06);
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  z-index: 1;
  border-color: var(--judo-red);
}

/* Weekends */
.calendar-day.weekend {
  background: #f0f0f0;
  border-color: #bbb;
}

/* Public holidays */
.calendar-day.holiday {
  background: #ffcdd2;
  border-color: #e57373;
}

/* School holidays */
.calendar-day.school-holiday {
  background: #fff3e0;
  border-color: #ffb74d;
}

/* Public holiday on weekend */
.calendar-day.weekend.holiday {
  background: #ef9a9a;
  border-color: #e57373;
}

/* School holiday on weekend */
.calendar-day.weekend.school-holiday {
  background: #ffcc80;
  border-color: #ffa726;
}

.calendar-day.disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

/* Training days */
.calendar-day.has-data {
  background: #e8f5e9;
  border-color: #66bb6a;
  font-weight: 600;
}

/* Competition days */
.calendar-day.has-competition {
  background: #e3f2fd;
  border-color: #42a5f5;
  font-weight: 600;
}

/* Competition/training days override combined weekend+holiday selectors (higher specificity) */
.calendar-day.weekend.school-holiday.has-data,
.calendar-day.weekend.holiday.has-data {
  background: #e8f5e9;
  border-color: #66bb6a;
}

.calendar-day.weekend.school-holiday.has-competition,
.calendar-day.weekend.holiday.has-competition {
  background: #e3f2fd;
  border-color: #42a5f5;
}

.day-number {
  font-weight: 700;
  font-size: 1rem;
  color: var(--gray-900);
  line-height: 1;
}

.day-info {
  font-size: 0.65rem;
  color: #c0392b;
  font-weight: 600;
  line-height: 1.2;
  margin-top: 2px;
}

.day-hours {
  font-size: 0.72rem;
  color: #1b5e20;
  font-weight: 700;
  margin-top: 4px;
}

/* ===== Summary ===== */
.summary-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--judo-navy);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--gray-200);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--gray-100);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--judo-navy);
}

.summary-item.total {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--judo-navy), var(--judo-red));
  color: white;
  border-left: none;
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  font-size: 1.1rem;
}

.summary-item .label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--gray-700);
}

.summary-item .value {
  font-weight: 700;
  color: var(--judo-navy);
  font-size: 1rem;
}

.summary-item.total .label,
.summary-item.total .value {
  color: white;
  font-size: 1.05rem;
}

/* ===== Actions ===== */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.actions button {
  padding: 11px 20px;
}

#mileageBtn {
  background: var(--gray-200);
  color: var(--gray-900);
  border: none;
}

#mileageBtn:hover {
  background: var(--gray-300);
}

#backupBtn {
  background: var(--gray-200);
  color: var(--gray-900);
  border: none;
}

#backupBtn:hover {
  background: var(--gray-300);
}

.import-group {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.import-group input[type="file"] {
  font-size: 0.85rem;
  color: var(--gray-700);
}

#importBtn {
  background: var(--gray-200);
  color: var(--gray-900);
  border: none;
}

#importBtn:hover {
  background: var(--gray-300);
}

#freezeBtn {
  background: var(--judo-navy);
  color: white;
  border: none;
}

#freezeBtn:hover {
  background: var(--judo-red);
}

#freezeBtn.frozen {
  background: var(--judo-red);
}

#freezeBtn.frozen:hover {
  background: var(--judo-red-dark);
}

.frozen-banner {
  background: rgba(192, 57, 43, 0.08);
  border: 1px solid var(--judo-red);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  color: var(--judo-red);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
}

/* ===== Modals ===== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(3px);
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  padding: 28px;
  border-radius: var(--radius);
  min-width: 400px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border-top: 4px solid var(--judo-red);
}

.modal-content h2 {
  margin-bottom: 20px;
  color: var(--judo-navy);
  font-size: 1.3rem;
  font-weight: 700;
}

.modal-content label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--gray-700);
  margin-top: 12px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.modal-content input[type="text"],
.modal-content input[type="number"],
.modal-content input[type="email"],
.modal-content input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  transition: border-color 0.2s;
  color: var(--gray-900);
}

.modal-content input:focus {
  outline: none;
  border-color: var(--judo-red);
}

.modal-content input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-right: 8px;
  accent-color: var(--judo-red);
  vertical-align: middle;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.modal-actions button {
  flex: 1;
  min-width: 100px;
  padding: 11px 16px;
}

.modal-actions .btn-primary {
  background: var(--judo-red);
  color: white;
}

.modal-actions .btn-primary:hover {
  background: var(--judo-red-dark);
}

.modal-actions .btn-secondary {
  background: var(--gray-200);
  color: var(--gray-900);
  border: none;
}

.modal-actions .btn-secondary:hover {
  background: var(--gray-300);
}

.modal-actions .btn-danger {
  background: #6c1e1e;
  color: white;
}

.modal-actions .btn-danger:hover {
  background: #8b2020;
}

#travelGroup {
  margin-top: 8px;
  padding: 14px;
  background: var(--gray-100);
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-200);
}

#existingJustification {
  margin-top: 8px;
}

#existingJustification a {
  color: var(--judo-red);
  font-size: 0.9rem;
  text-decoration: none;
}

#existingJustification a:hover {
  text-decoration: underline;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .app-header-inner {
    padding: calc(10px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 10px calc(12px + env(safe-area-inset-left, 0px));
    gap: 10px;
  }

  .header-logo {
    width: 44px;
    height: 44px;
  }

  .header-title {
    flex: 1 1 calc(100% - 56px);
  }

  .header-title h1 {
    font-size: 1rem;
  }

  .header-subtitle {
    font-size: 0.7rem;
    letter-spacing: 0.7px;
  }

  .app-header-inner > button {
    flex: 1 1 140px;
    min-width: 0;
    text-align: center;
  }

  .app-body {
    padding: 12px calc(12px + env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px));
    gap: 12px;
  }

  .card {
    padding: 16px;
  }

  .calendar {
    gap: 4px;
  }

  .calendar-header,
  .calendar-day {
    min-width: 0;
  }

  .calendar-day {
    padding: 4px;
    min-height: 44px;
  }

  .day-number {
    font-size: 0.85rem;
  }

  .day-info,
  .day-hours {
    font-size: 0.65rem;
  }

  .modal-content {
    min-width: unset;
    width: 95vw;
    padding: 20px;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    gap: 12px;
  }

  .toolbar-label {
    flex: initial;
    min-width: 0;
  }

  .toolbar-label select,
  .toolbar-label input[type="month"] {
    min-width: 0;
    width: 100%;
    max-width: none;
    font-size: 0.9rem;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    grid-column: 1 / -1;
  }

  .toolbar-actions button {
    width: 100%;
    min-width: 0;
    min-height: 52px;
    padding: 10px 8px;
    font-size: 0.82rem;
    line-height: 1.15;
    white-space: normal;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }

  .actions button {
    width: 100%;
    min-width: 0;
  }

  .import-group {
    width: 100%;
    grid-column: 1 / -1;
  }

  .calendar.card {
    padding: 10px;
    overflow: hidden;
  }

  .calendar {
    width: 100%;
    max-width: 100%;
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .calendar-header {
    font-size: 0.72rem;
    padding: 8px 2px;
  }

  .calendar-day {
    min-height: 0;
    height: clamp(42px, 11vw, 58px);
  }
}

@media (max-width: 480px) {
  .toolbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .toolbar-label {
    width: 100%;
  }

  .toolbar-actions {
    grid-template-columns: 1fr;
  }

  .toolbar-actions button,
  .actions button {
    min-width: 0;
  }

  .calendar {
    gap: 3px;
  }

  .calendar-header {
    font-size: 0.7rem;
    padding: 8px 2px;
  }

  .calendar-day {
    padding: 3px;
    min-height: 40px;
  }

  .legend {
    gap: 10px;
    padding: 10px 14px;
  }
}

/* ===== Help Modal ===== */
.modal-content-help {
  max-width: 680px;
  width: 92vw;
}

.export-preview-content {
  width: min(96vw, 1100px);
  max-width: min(96vw, 1100px);
  min-width: min(96vw, 320px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.export-preview-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.export-preview-toolbar button {
  flex: 1 1 180px;
}

.export-preview-frame {
  width: 100%;
  min-height: 70vh;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: white;
}

.help-section {
  margin-top: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--gray-200);
}

.help-section:last-of-type {
  border-bottom: none;
}

.help-section h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--judo-navy);
  margin-bottom: 10px;
}

.help-section p {
  font-size: 0.9rem;
  color: var(--gray-700);
  line-height: 1.6;
}

.help-section ul {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-section ul li {
  font-size: 0.9rem;
  color: var(--gray-700);
  line-height: 1.5;
  padding-left: 16px;
  position: relative;
}

.help-section ul li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--judo-red);
  font-weight: 700;
}

.help-color-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 2px solid transparent;
  vertical-align: middle;
  margin-right: 4px;
}

.weekend-dot {
  background: #e8e8e8;
  border-color: #999;
}

.holiday-dot {
  background: #ffcdd2;
  border-color: #e57373;
}

.school-holiday-dot {
  background: #fff3e0;
  border-color: #ffb74d;
}

.has-data-dot {
  background: #e8f5e9;
  border-color: #66bb6a;
}

.has-competition-dot {
  background: #e3f2fd;
  border-color: #42a5f5;
}

.admin-help {
  background: var(--gray-100);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
