/* SageTimer - Application Styles */

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #dce1e8;
  --primary: #3498db;
  --primary-dark: #2980b9;
  --danger: #e74c3c;
  --success: #27ae60;
  --warning: #f39c12;
}

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

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

/* Navigation */
.top-nav {
  background: var(--text);
  color: white;
  padding: 0.75rem 1.5rem;
}
.nav-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-title { font-size: 1.25rem; color: white; text-decoration: none; font-weight: 700; }
.nav-links a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  margin-left: 1.5rem;
  font-weight: 500;
}
.nav-links a:hover { color: white; }

/* Container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Flash messages */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.flash-notice { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.flash-alert { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 0.875rem;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--bg); }
.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.btn-danger:hover { background: #c0392b; }
.btn-small { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
.btn-disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* Headings */
h1 { margin-bottom: 1rem; font-size: 1.5rem; }

/* Date picker */
.date-picker {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.date-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.date-form input[type="date"] {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}
.date-nav { display: flex; gap: 0.25rem; }

/* Schedule Grid */
.grid-wrapper {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: inline-block;
  position: relative;
  max-height: calc(100vh - 180px);
}
#current-time-line {
  position: absolute;
  left: 0; right: 0;
  height: 2px;
  background: #e74c3c;
  pointer-events: none;
  z-index: 20;
}

.schedule-grid {
  border-collapse: collapse;
  font-size: 0.8rem;
}
.schedule-grid th {
  background: var(--text);
  color: white;
  padding: 0.5rem 0.25rem;
  position: sticky;
  top: 0;
  z-index: 10;
  font-weight: 600;
  text-align: center;
}
.schedule-grid thead tr:nth-child(2) th {
  top: 30px;
}
.time-col { width: 70px; min-width: 70px; }
.lane-col { min-width: 120px; }
.lane-col-single { min-width: 65px; max-width: 65px; width: 65px; }
.sub-lane-col {
  min-width: 65px;
  font-size: 0.7rem;
  background: var(--text);
  color: white;
  padding: 0.15rem 0.25rem;
}

.schedule-grid td {
  border: 1px solid var(--border);
  padding: 0;
  height: 24px;
  text-align: center;
  vertical-align: middle;
}
.schedule-grid td.lane-start {
  border-left: 2px solid var(--text);
}
.schedule-grid th.lane-col,
.schedule-grid th.lane-col-single {
  border-left: 2px solid var(--text);
}
.time-cell {
  font-size: 0.75rem;
  color: var(--text-light);
  padding: 2px 6px !important;
  background: #fafbfc;
  white-space: nowrap;
  font-weight: 500;
}
.hour-row .time-cell {
  font-weight: 700;
  color: var(--text);
  border-top: 2px solid var(--border);
}
.session-col { width: 80px; min-width: 80px; }
.session-cell {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary);
  padding: 4px 6px !important;
  background: #fafbfc;
  vertical-align: middle;
  text-align: center;
  letter-spacing: 0.03em;
}
.hour-row td { border-top: 2px solid var(--border); }

/* Empty (bookable) cell */
.empty-cell {
  cursor: pointer;
  transition: background-color 0.15s;
}
.empty-cell:hover {
  background: #ebf5fb;
}

/* Non-bookable / closed cells */
.disabled-cell {
  background: #6c757d;
  cursor: not-allowed;
}
.session-closed {
  color: var(--danger);
}
.closed-label {
  font-size: 0.6rem;
  color: var(--danger);
  font-weight: 600;
}
.session-break {
  color: var(--warning);
}
.break-label {
  font-size: 0.6rem;
  color: var(--warning);
  font-weight: 600;
}

/* Hidden team booking */
.booked-cell.team-hidden {
  background: var(--surface) !important;
  border-left: 1px solid var(--border) !important;
  cursor: default;
  pointer-events: none;
}
.booked-cell.team-hidden > * { display: none; }

/* Team filter action buttons row */
.team-filter-actions {
  display: flex;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}

/* Booked cell */
.booked-cell {
  padding: 0 !important;
  vertical-align: top;
  position: relative;
  cursor: pointer;
}
.booked-cell .booking-content {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 4px 6px;
}
.booking-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.team-name {
  font-weight: 700;
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.booking-time {
  font-size: 0.7rem;
  color: var(--text-light);
}
.booking-name {
  font-size: 0.7rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.booking-phone {
  font-size: 0.65rem;
  color: var(--text-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0.5;
}
.btn-remove:hover { opacity: 1; background: rgba(231,76,60,0.1); }

/* Resize handles */
.resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.15s;
}
.booked-cell:hover .resize-handle {
  opacity: 1;
}
.resize-handle-top {
  top: 0;
  cursor: n-resize;
  background: linear-gradient(to bottom, rgba(52,152,219,0.4), transparent);
}
.resize-handle-bottom {
  bottom: 0;
  cursor: s-resize;
  background: linear-gradient(to top, rgba(52,152,219,0.4), transparent);
}
.resizing {
  opacity: 0.7;
}

/* Drag and drop */
.dragging {
  opacity: 0.4;
}
.drag-over {
  background: #d5f5e3 !important;
  box-shadow: inset 0 0 0 2px var(--success);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-light);
  font-size: 1.1rem;
}
.empty-state a { color: var(--primary); }

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  min-width: 300px;
  max-width: 400px;
  overflow: hidden;
  width: 100%;
}
.modal-content h3 { margin-bottom: 1rem; }

/* Forms */
.field {
  margin-bottom: 1rem;
}
.field-checkbox label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0;
}
.field-checkbox input[type="checkbox"] {
  margin: 0;
  width: auto;
}
.field label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
}
.field input, .field select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}
.field input[type="color"] {
  height: 40px;
  padding: 4px;
  cursor: pointer;
}
.actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Errors */
.errors {
  background: #f8d7da;
  border: 1px solid #f5c6cb;
  color: #721c24;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
.errors h3 { font-size: 0.875rem; margin-bottom: 0.5rem; }
.errors ul { margin-left: 1.25rem; }

/* Teams table */
.teams-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-top: 1rem;
}
.sort-link {
  color: inherit;
  text-decoration: none;
}
.sort-link:hover {
  text-decoration: underline;
}
.teams-table th, .teams-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.teams-table th {
  background: #fafbfc;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-light);
}
.teams-table td { font-size: 0.9rem; }
.teams-table tr:hover td { background: #fafbfc; }

.actions-cell { white-space: nowrap; }
.actions-cell form { display: inline-block; }

.color-swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  vertical-align: middle;
  border: 1px solid var(--border);
}

/* Columns dropdown */
.columns-dropdown {
  position: relative;
  display: inline-block;
}
.columns-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 0.5rem;
  z-index: 100;
  min-width: 160px;
}
.columns-menu label {
  display: block;
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 4px;
}
.columns-menu label:hover {
  background: var(--bg);
}
.columns-menu input[type="checkbox"] {
  margin-right: 0.5rem;
}

/* Teams toolbar */
.teams-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.teams-toolbar-left {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.import-form {
  display: inline-block;
}
.search-form { display: flex; }
.search-input { width: 220px; }
.import-form input[type="file"] {
  display: none;
}

/* Search */
.search-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.search-input {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  width: 250px;
}

/* Team form */
.team-form {
  max-width: 400px;
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}
.page-link {
  display: inline-block;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--primary);
  text-decoration: none;
  font-size: 0.875rem;
  min-width: 2rem;
  text-align: center;
}
.page-link:hover { background: var(--bg); }
.page-link-current {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.page-link-disabled {
  color: var(--text-light);
  cursor: default;
}
.page-ellipsis {
  padding: 0.35rem 0.25rem;
  color: var(--text-light);
  font-size: 0.875rem;
}

/* Login page */
.login-container {
  max-width: 380px;
  margin: 6rem auto;
  background: var(--surface);
  padding: 2.5rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}
.login-logo-wrap {
  position: relative;
  width: 160px;
  margin: 0 auto 0.5rem;
}
.login-stopwatch {
  position: absolute;
  width: 100px;
  height: auto;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0.15;
  z-index: 0;
}
.login-sage {
  position: relative;
  display: block;
  width: 160px;
  height: auto;
  z-index: 1;
}
.login-title {
  text-align: center;
  font-size: 1.75rem;
  margin-bottom: 1.75rem;
  color: var(--text);
}
.login-form .form-group {
  margin-bottom: 1.25rem;
}
.login-form label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}
.login-form .form-control {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}
.login-form .form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(52,152,219,0.15);
}
.btn-full {
  width: 100%;
  padding: 0.65rem;
  font-size: 1rem;
  margin-top: 0.5rem;
}

/* Generic form fields (used in user form, etc.) */
.form-group {
  margin-bottom: 1.25rem;
}
.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.form-control {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(52,152,219,0.15);
}
.form-hint {
  display: block;
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 0.25rem;
}

/* Password visibility toggle */
.password-wrapper {
  position: relative;
}
.password-wrapper .form-control {
  padding-right: 2.5rem;
}
.password-toggle {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: 0.25rem;
  display: flex;
  align-items: center;
}
.password-toggle:hover {
  color: var(--text);
}
.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

/* Current user badge */
.current-user-badge {
  display: inline-block;
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
  margin-left: 0.4rem;
  vertical-align: middle;
}

/* Nav auth items */
.nav-user {
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  margin-left: 1.5rem;
  font-size: 0.875rem;
}
.nav-user:hover { color: white; }
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  max-width: 420px;
  margin-top: 1.5rem;
}
.nav-logout {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  margin-left: 0.75rem;
  font-weight: 500;
  font-size: 0.875rem;
}
.nav-logout:hover { color: white; }
.nav-tools {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  margin-left: 1.5rem;
  font-weight: 500;
  font-size: 0.9rem;
}
.nav-tools:hover { color: white; }

/* Hamburger button - hidden on desktop */
.hamburger {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
}
.nav-separator { display: none; }

/* Tools page */
.tools-page { max-width: 800px; }
.tools-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.tools-section h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.tools-list { padding-left: 1.25rem; }
.tools-list li { margin-bottom: 0.4rem; }
.tools-files li { list-style: none; margin-left: -1.25rem; }
.tools-files a { font-weight: 500; }
.tools-faqs { display: flex; flex-direction: column; gap: 1rem; }
.tools-content p, .tools-faqs p { color: var(--text); line-height: 1.6; }

/* Footer */
.site-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  margin-top: 2rem;
  color: var(--text-light);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

/* Mobile navigation */
@media (max-width: 768px) {
  .nav-content {
    flex-wrap: wrap;
  }
  .hamburger {
    display: block;
  }
  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    padding-top: 0.75rem;
  }
  [data-nav-open] .nav-links {
    display: flex;
  }
  .nav-links a {
    margin-left: 0;
    padding: 0.6rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    font-size: 1rem;
  }
  .nav-links a:last-child {
    border-bottom: none;
  }
  .nav-separator {
    display: block;
    height: 1px;
    background: rgba(255,255,255,0.2);
    margin: 0.25rem 0;
  }
  .nav-user, .nav-logout {
    margin-left: 0 !important;
    padding: 0.6rem 0;
    font-size: 1rem !important;
  }

  /* Schedule grid: horizontal scroll with sticky time/session columns */
  .grid-wrapper {
    display: block;
  }

  .schedule-grid th.session-col,
  .schedule-grid .session-cell {
    position: sticky;
    left: 0;
    z-index: 3;
  }

  .schedule-grid th.time-col,
  .schedule-grid .time-cell {
    position: sticky;
    left: 80px;
    z-index: 2;
    box-shadow: 2px 0 4px rgba(0,0,0,0.08);
  }

  /* Header cells: sticky in both directions (top + left) */
  .schedule-grid th.session-col {
    z-index: 12;
  }
  .schedule-grid th.time-col {
    z-index: 11;
    box-shadow: 2px 0 4px rgba(0,0,0,0.15);
  }

  /* Container */
  .container {
    padding: 1rem;
  }
  h1 {
    font-size: 1.2rem;
  }

  /* Toolbars stack vertically */
  .teams-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .teams-toolbar-left {
    flex-wrap: wrap;
  }
  .date-picker {
    gap: 0.5rem;
  }

  /* Search inputs fill available width */
  .search-form {
    width: 100%;
  }
  .search-input {
    width: 100% !important;
    min-width: 0;
  }

  /* Tables scroll horizontally */
  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-scroll .teams-table {
    border-radius: 0;
  }
  .teams-table th,
  .teams-table td {
    padding: 0.5rem 0.75rem;
    white-space: nowrap;
  }
  .actions-cell {
    display: flex;
    gap: 0.25rem;
  }

  /* Forms take full width */
  .team-form,
  .form-card {
    max-width: 100%;
  }

  /* Modals fit mobile screens */
  .modal-content {
    min-width: auto;
    max-width: calc(100vw - 2rem);
    margin: 1rem;
    padding: 1rem;
  }

  /* Tools page */
  .tools-page {
    max-width: 100%;
  }
}
