/**
 * Site Attendance Tracker - Styles
 * Light theme: white primary, red #e0234f, blue accents
 */

:root {
  --brand-primary: #e0234f;
  --brand-dark: #000000;
  --brand-primary-hover: #c01e45;
  --accent-blue: #2563eb;
  --accent-blue-light: #3b82f6;
  --accent-blue-bg: #eff6ff;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-muted: #f1f5f9;
  --text-primary: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --error: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.06);
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  font-size: 16px;
}

/* Layout */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  width: 100%;
}

/* Logo / Header */
.app-header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.app-header img {
  max-height: 44px;
  width: auto;
  display: inline-block;
}

.app-title {
  font-size: 1.125rem;
  color: var(--text-muted);
  margin-top: 0.375rem;
  font-weight: 400;
}

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

.card h2 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
  color: var(--brand-primary);
  font-weight: 600;
}

/* Form */
label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
  color: var(--text-primary);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.75rem 0.875rem;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text-primary);
  margin-bottom: 0.875rem;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand-primary);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

textarea {
  min-height: 72px;
  padding: 0.75rem 0.875rem;
  resize: vertical;
}

/* Buttons – touch-friendly min 44px */
.btn {
  display: inline-block;
  min-height: 44px;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, transform 0.05s;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--brand-primary);
  color: white;
  width: 100%;
}

.btn-primary:hover {
  background: var(--brand-primary-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--brand-primary);
  border: 1px solid var(--brand-primary);
}

.btn-secondary:hover {
  background: rgba(224, 35, 79, 0.08);
  color: var(--brand-primary-hover);
}

.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

.btn-block-add {
  margin-top: 0.5rem;
  margin-bottom: 1rem;
}

/* Work entry block */
.work-entry {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  position: relative;
}

.work-entry:nth-of-type(even) {
  background: var(--accent-blue-bg);
  border-color: rgba(37, 99, 235, 0.2);
}

.work-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.work-entry-header span {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--brand-primary);
}

/* Top bar (user + nav) */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.user-info {
  font-size: 0.8125rem;
  color: var(--text-primary);
  word-break: break-all;
}

.user-info strong {
  color: var(--brand-primary);
  font-weight: 600;
}

/* Messages (toast) */
.message {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  display: none;
}

.message.show {
  display: block;
}

.message.error {
  background: #fef2f2;
  border: 1px solid var(--error);
  color: #b91c1c;
}

.message.success {
  background: #f0fdf4;
  border: 1px solid var(--success);
  color: #166534;
}

/* Overtime total read-only */
input[readonly] {
  background: var(--bg-page);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Login page centering */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-box {
  width: 100%;
  max-width: 400px;
}

/* Mode switcher (Single / Bulk) */
.mode-switcher {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.mode-switcher__btn {
  flex: 1;
  min-height: 44px;
  padding: 0.625rem 1rem;
  font-size: 0.9375rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-page);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.mode-switcher__btn:hover {
  background: var(--accent-blue-bg);
  color: var(--accent-blue);
  border-color: var(--accent-blue);
}

.mode-switcher__btn.active {
  background: var(--brand-primary);
  color: #fff;
  border-color: var(--brand-primary);
}

.hidden {
  display: none !important;
}

.bulk-defaults-hint,
.bulk-table-empty {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.bulk-worker-list {
  max-height: 200px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  margin-bottom: 0.75rem;
  background: #fff;
}

.bulk-worker-list label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  margin-bottom: 0;
  cursor: pointer;
  font-weight: 400;
}

.bulk-worker-list input[type="checkbox"] {
  width: auto;
  min-height: auto;
  margin: 0;
  flex-shrink: 0;
}

.bulk-table-scroll-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0 0 0.5rem 0;
  text-align: center;
  display: none;
}

.table-wrapper--bulk {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-muted);
}

/* Desktop: table uses full width of card so it isn't tight */
@media (min-width: 769px) {
  .table-wrapper--bulk {
    margin-left: -0.25rem;
    margin-right: -0.25rem;
  }
  .data-table--bulk {
    width: 100%;
    table-layout: fixed;
  }
  .data-table--bulk th:nth-child(1),
  .data-table--bulk td:nth-child(1) { width: 12%; min-width: 100px; }
  .data-table--bulk th:nth-child(2),
  .data-table--bulk td:nth-child(2) { width: 14%; min-width: 100px; }
  .data-table--bulk th:nth-child(3),
  .data-table--bulk td:nth-child(3) { width: 12%; min-width: 90px; }
  .data-table--bulk th:nth-child(4),
  .data-table--bulk td:nth-child(4) { width: 20%; min-width: 140px; }
  .data-table--bulk th:nth-child(5),
  .data-table--bulk td:nth-child(5) { width: 8%; min-width: 80px; }
  .data-table--bulk th:nth-child(6),
  .data-table--bulk td:nth-child(6) { width: 8%; min-width: 80px; }
  .data-table--bulk th:nth-child(7),
  .data-table--bulk td:nth-child(7) { width: 10%; min-width: 90px; }
  .data-table--bulk th:nth-child(8),
  .data-table--bulk td:nth-child(8) { width: 10%; min-width: 80px; }
  .data-table--bulk th:nth-child(9),
  .data-table--bulk td:nth-child(9) { width: 12%; min-width: 80px; }
  .data-table--bulk th:last-child,
  .data-table--bulk td:last-child { width: auto; min-width: 44px; }
}

.data-table--bulk {
  font-size: 0.875rem;
  min-width: 940px;
}

.data-table--bulk th,
.data-table--bulk td {
  padding: 0.5rem 0.5rem;
  vertical-align: middle;
}

/* Column min-widths so Site/Category/Work desc are usable on mobile (scroll instead of squash) */
.data-table--bulk th:nth-child(1),
.data-table--bulk td:nth-child(1) { min-width: 110px; width: 110px; }
.data-table--bulk th:nth-child(2),
.data-table--bulk td:nth-child(2) { min-width: 130px; width: 130px; }
.data-table--bulk th:nth-child(3),
.data-table--bulk td:nth-child(3) { min-width: 120px; width: 120px; }
.data-table--bulk th:nth-child(4),
.data-table--bulk td:nth-child(4) { min-width: 160px; width: 180px; }
.data-table--bulk th:nth-child(5),
.data-table--bulk td:nth-child(5) { min-width: 80px; width: 80px; }
.data-table--bulk th:nth-child(6),
.data-table--bulk td:nth-child(6) { min-width: 80px; width: 80px; }
.data-table--bulk th:nth-child(7),
.data-table--bulk td:nth-child(7) { min-width: 90px; width: 90px; }
.data-table--bulk th:nth-child(8),
.data-table--bulk td:nth-child(8) { min-width: 100px; width: 100px; }
.data-table--bulk th:nth-child(9),
.data-table--bulk td:nth-child(9) { min-width: 72px; width: 72px; }

.data-table--bulk td select,
.data-table--bulk td input[type="text"],
.data-table--bulk td input[type="number"] {
  min-height: 38px;
  padding: 0.4rem 0.5rem;
  font-size: 0.875rem;
  margin: 0;
  width: 100%;
  box-sizing: border-box;
}

.data-table--bulk td input[type="number"].bulk-row-oth,
.data-table--bulk td input[type="number"].bulk-row-rate {
  min-width: 4.5em;
  max-width: 100%;
}

.data-table--bulk td input.bulk-row-total {
  background: var(--bg-muted);
  min-width: 5.5em;
}

.data-table--bulk .btn-remove-bulk-row {
  min-height: 36px;
  padding: 0.35rem 0.5rem;
  font-size: 0.8125rem;
  white-space: nowrap;
}

.required-asterisk {
  color: var(--error);
}

@media (max-width: 768px) {
  .bulk-table-scroll-hint {
    display: block;
  }
  .table-wrapper--bulk {
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    padding-bottom: 0.25rem;
  }
  .data-table--bulk td select,
  .data-table--bulk td input[type="text"],
  .data-table--bulk td input[type="number"] {
    min-height: 44px;
    font-size: 16px;
  }
  .data-table--bulk .btn-remove-bulk-row {
    min-height: 44px;
    min-width: 44px;
  }
  .bulk-worker-list {
    max-height: 180px;
  }
}

/* Attendance page */
.attendance-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.attendance-actions .btn-primary {
  flex: 1;
  min-width: 140px;
}

.attendance-actions .btn-secondary {
  flex: 0 0 auto;
}

/* Analytics */
.container--wide {
  max-width: 960px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.nav-link,
.nav-link--active {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.75rem;
  color: var(--accent-blue);
  text-decoration: none;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: var(--radius);
  touch-action: manipulation;
}

.nav-link:hover {
  color: var(--accent-blue-light);
  text-decoration: underline;
}

.nav-link--active {
  color: var(--brand-primary);
  font-weight: 600;
  cursor: default;
  text-decoration: none;
}

.nav-links .btn {
  min-height: 40px;
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
}

.analytics-filters .filters-row,
.reports-filters .filters-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.reports-filters .filter-group--presets .preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.reports-filters .btn-preset {
  font-size: 0.8125rem;
  padding: 0.4rem 0.75rem;
}

.filter-group label {
  margin-bottom: 0.25rem;
}

.filters-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow-card);
}

.summary-card:nth-child(odd) .summary-card__value {
  color: var(--brand-primary);
}

.summary-card:nth-child(even) .summary-card__value {
  color: var(--accent-blue);
}

.summary-card__value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.summary-card__label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

.data-table th,
.data-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-weight: 600;
  color: #ffffff;
  background: var(--accent-blue);
  border-bottom: 2px solid var(--accent-blue-light);
}

.data-table tbody tr:hover {
  background: var(--accent-blue-bg);
}

.data-table tbody tr:nth-child(even) {
  background: #f8fafc;
}

.data-table tbody tr:nth-child(even):hover {
  background: var(--accent-blue-bg);
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Reports card – single table of all records */
.reports-card h2 {
  margin-bottom: 0.25rem;
}

.reports-intro {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.table-wrapper--records {
  max-height: 60vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -1rem;
  padding: 0 1rem;
}

.data-table--records {
  font-size: 0.8125rem;
  min-width: 640px;
}

.data-table--records th,
.data-table--records td {
  padding: 0.5rem 0.5rem;
  white-space: nowrap;
}

.data-table--records td:nth-child(3) {
  white-space: normal;
  max-width: 180px;
}

.reports-card .table-wrapper {
  margin-top: 0;
}

/* ========== Mobile & small screens ========== */
@media (max-width: 768px) {
  .container {
    padding: 0.875rem 1rem 1.5rem;
  }

  .container--wide {
    max-width: 100%;
    padding: 0.875rem 1rem 1.5rem;
  }

  .app-header {
    margin-bottom: 1rem;
  }

  .app-header img {
    max-height: 40px;
  }

  .app-title {
    font-size: 1rem;
  }

  .card {
    padding: 1rem;
    margin-bottom: 1rem;
  }

  .card h2 {
    font-size: 0.9375rem;
    margin-bottom: 0.625rem;
  }

  .top-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    margin-bottom: 1rem;
  }

  .user-info {
    font-size: 0.8125rem;
  }

  .nav-links {
    justify-content: flex-start;
    gap: 0.375rem;
  }

  .nav-link,
  .nav-link--active {
    min-height: 44px;
    padding: 0 0.625rem;
    font-size: 0.875rem;
  }

  .attendance-actions {
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1.25rem;
  }

  .attendance-actions .btn {
    width: 100%;
    min-height: 48px;
  }

  .work-entry {
    padding: 0.875rem;
  }

  .analytics-filters .filters-row,
  .reports-filters .filters-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .analytics-filters .filter-group label,
  .reports-filters .filter-group label {
    font-size: 0.8125rem;
  }

  .filters-actions {
    flex-direction: column;
    gap: 0.5rem;
  }

  .filters-actions .btn {
    width: 100%;
    min-height: 44px;
  }

  .summary-cards {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
  }

  .summary-card {
    padding: 0.75rem;
  }

  .summary-card__value {
    font-size: 1.25rem;
  }

  .summary-card__label {
    font-size: 0.6875rem;
  }

  .reports-card h2 {
    font-size: 0.9375rem;
  }

.reports-intro {
  font-size: 0.8125rem;
  margin-bottom: 0.75rem;
}

.reports-empty-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  padding: 0.5rem 0;
}

  .table-wrapper--records {
    max-height: 55vh;
    margin: 0 -0.5rem;
    padding: 0 0.5rem;
  }

  .data-table--records {
    font-size: 0.75rem;
    min-width: 560px;
  }

  .data-table--records th,
  .data-table--records td {
    padding: 0.375rem 0.4rem;
  }

  .data-table--records td:nth-child(3) {
    max-width: 140px;
  }

  .message {
    padding: 0.625rem 0.875rem;
    font-size: 0.8125rem;
  }
}

/* Extra small – single column, max touch targets */
@media (max-width: 480px) {
  .container,
  .container--wide {
    padding: 0.75rem 0.875rem 1.25rem;
  }

  .analytics-filters .filters-row,
  .reports-filters .filters-row {
    grid-template-columns: 1fr;
  }

  .summary-cards {
    grid-template-columns: 1fr;
  }

  .btn-block-add {
    width: 100%;
    min-height: 44px;
  }

  .login-wrapper {
    padding: 1rem 0.875rem;
  }

  .login-box .card {
    padding: 1rem;
  }

  .login-box .btn-primary {
    min-height: 48px;
  }
}

/* Safe area for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .container,
  .container--wide {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* Success dialog (modal) */
.success-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.success-dialog-overlay[hidden] {
  display: none;
}

.success-dialog {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  padding: 1.5rem;
  max-width: 360px;
  width: 100%;
}

.success-dialog__title {
  font-size: 1.25rem;
  color: var(--success);
  margin-bottom: 0.75rem;
}

.success-dialog__message {
  margin-bottom: 1.25rem;
  color: var(--text-primary);
  line-height: 1.5;
}

.success-dialog .btn-primary {
  width: 100%;
  min-height: 44px;
}
