/* ============================================================================
   Martial Sync — Tablet Mode Styles
   Touch-optimized for iPad / tablet use at the dojang
   ============================================================================ */

/* --- Design tokens (same as admin.css) --- */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #ca8a04;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --white: #ffffff;
  --tab-bar-height: 64px;
  --header-height: 56px;
}

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

body {
  font-family: var(--font-family);
  font-size: var(--font-body-1);
  line-height: 1.5;
  background: var(--gray-50);
  color: var(--gray-800);
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior: none;
  zoom: 1.25;
}

/* --- Login --- */
.login-container {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--gray-100);
}

.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 3rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-header h1 {
  font-size: var(--font-h4);
  line-height: var(--lh-h4);
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.login-header p {
  color: var(--gray-500);
  font-size: var(--font-body-1);
  line-height: var(--lh-body-1);
}

/* --- Form Elements --- */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  font-size: var(--font-body-1);
  color: var(--gray-700);
}

.form-input, .form-select {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: var(--font-body-1);
  line-height: 1.5;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-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='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 3rem;
}

.form-input:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-size: var(--font-body-1);
  font-weight: 500;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
  touch-action: manipulation;
}

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

.btn-primary { background: var(--primary); color: var(--white); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); }
.btn-success { background: var(--success); color: var(--white); }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-sm { padding: 0.75rem 1rem; font-size: var(--font-body-1); min-height: 48px; }
.btn-lg { padding: 1rem 1.5rem; font-size: var(--font-body-1); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Alerts --- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: var(--font-body-1);
}

.alert-error { background: var(--danger-light); color: var(--danger); }
.alert-success { background: var(--success-light); color: var(--success); }

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  font-size: var(--font-body-3);
  font-weight: 600;
  border-radius: 12px;
  text-transform: capitalize;
}

.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* ============================================================================
   Tablet Layout
   ============================================================================ */

.tablet-layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* --- Top Header --- */
.tablet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 1rem;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
  z-index: 10;
}

.tablet-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.tablet-logo {
  font-size: var(--font-body-1);
  font-weight: 700;
  color: var(--gray-900);
}

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

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-body-3);
  font-weight: 600;
}

/* --- Main Content --- */
.tablet-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  padding-bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + 16px);
}

/* --- Bottom Tab Bar --- */
.tablet-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-bar-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  align-items: stretch;
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  z-index: 20;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  border: none;
  background: none;
  color: var(--gray-400);
  font-size: var(--font-body-3);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 48px;
  transition: color 0.15s;
}

.tab-item:active {
  transform: scale(0.95);
}

.tab-item.active {
  color: var(--primary);
}

.tab-icon {
  font-size: var(--font-h4);
  line-height: 1;
}

.tab-label {
  font-size: var(--font-body-3);
  line-height: 1;
}

/* ============================================================================
   Shared Card Components
   ============================================================================ */

.card {
  background: var(--white);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  font-weight: 600;
  font-size: var(--font-body-1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-body {
  padding: 1rem;
}

/* ============================================================================
   Date Toolbar
   ============================================================================ */

.date-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0;
  margin-bottom: 0.75rem;
}

.date-toolbar .btn {
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  font-size: var(--font-h5);
}

.date-toolbar .date-display {
  flex: 1;
  text-align: center;
  font-size: var(--font-body-1);
  font-weight: 600;
}

.date-toolbar .date-display .date-weekday {
  font-size: var(--font-body-3);
  font-weight: 400;
  color: var(--gray-500);
}

.date-toolbar input[type="date"] {
  padding: 0.75rem 0.75rem;
  font-size: var(--font-body-1);
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  min-height: 48px;
  -webkit-appearance: none;
}

/* ============================================================================
   Attendance Tab — Split View
   ============================================================================ */

.attendance-layout {
  display: flex;
  gap: 1rem;
  min-height: 0;
}

.attendance-class-list {
  width: 300px;
  flex-shrink: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.attendance-roster {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Portrait: stacked */
@media (max-width: 900px) {
  .attendance-layout {
    flex-direction: column;
  }

  .attendance-class-list {
    width: 100%;
    max-height: 200px;
    overflow-x: auto;
    display: flex;
    gap: 0.75rem;
    flex-shrink: 0;
  }

  .attendance-class-list .class-card {
    min-width: 200px;
    flex-shrink: 0;
  }
}

/* --- Class Cards (Attendance left panel) --- */
.class-card {
  background: var(--white);
  border: 2px solid var(--gray-200);
  border-radius: 12px;
  padding: 1rem 1rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: border-color 0.15s, background 0.15s;
}

.class-card:active {
  transform: scale(0.98);
}

.class-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.class-card-name {
  font-weight: 600;
  font-size: var(--font-body-1);
  margin-bottom: 0.25rem;
}

.class-card-time {
  font-size: var(--font-body-1);
  color: var(--gray-500);
}

.class-card-count {
  font-size: var(--font-body-3);
  color: var(--gray-400);
  margin-top: 0.25rem;
}

/* --- Roster Search --- */
.roster-search {
  position: relative;
  margin-bottom: 0.75rem;
}

.roster-search input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: var(--font-body-1);
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  outline: none;
  min-height: 48px;
}

.roster-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-results-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  max-height: 280px;
  overflow-y: auto;
  z-index: 15;
  display: none;
}

.search-results-dropdown.show {
  display: block;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  border-bottom: 1px solid var(--gray-100);
  min-height: 48px;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:active {
  background: var(--gray-50);
}

.search-result-item .member-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-body-3);
  font-weight: 600;
  background: var(--gray-200);
  color: var(--gray-600);
  overflow: hidden;
}

.search-result-item .member-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --- Checked-in Member Cards --- */
.roster-members {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.roster-member-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  min-height: 60px;
}

.roster-member-card .member-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--font-body-1);
  background: var(--gray-200);
  color: var(--gray-600);
  overflow: hidden;
}

.roster-member-card .member-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.roster-member-info {
  flex: 1;
  min-width: 0;
}

.roster-member-name {
  font-weight: 600;
  font-size: var(--font-body-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.roster-member-meta {
  font-size: var(--font-body-3);
  color: var(--gray-500);
}

.roster-remove-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--danger-light);
  color: var(--danger);
  font-size: var(--font-h5);
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.roster-remove-btn:active {
  transform: scale(0.9);
  background: var(--danger);
  color: var(--white);
}

/* ============================================================================
   Classes Tab — Schedule Cards
   ============================================================================ */

.schedule-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.schedule-card:active {
  transform: scale(0.98);
  background: var(--gray-50);
}

.schedule-card-name {
  font-weight: 600;
  font-size: var(--font-body-1);
  margin-bottom: 0.5rem;
}

.schedule-card-details {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: var(--font-body-1);
  color: var(--gray-500);
}

/* ============================================================================
   Members Tab — Card List
   ============================================================================ */

.member-search-bar {
  margin-bottom: 0.75rem;
}

.member-search-bar input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: var(--font-body-1);
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  outline: none;
  min-height: 48px;
}

.member-search-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.member-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  padding: 1rem 1rem;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 64px;
}

.member-card:active {
  transform: scale(0.98);
  background: var(--gray-50);
}

.member-card .member-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--font-body-1);
  background: var(--gray-200);
  color: var(--gray-600);
  overflow: hidden;
}

.member-card .member-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.member-card-info {
  flex: 1;
  min-width: 0;
}

.member-card-name {
  font-weight: 600;
  font-size: var(--font-body-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-card-rank {
  font-size: var(--font-body-3);
  color: var(--gray-500);
}

/* ============================================================================
   Member Detail — Progress-First Stacked Layout
   ============================================================================ */

.member-detail-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.member-detail-photo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--font-h3);
  background: var(--gray-200);
  color: var(--gray-600);
  overflow: hidden;
}

.member-detail-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.member-detail-name {
  font-size: var(--font-h4);
  font-weight: 700;
}

.member-detail-rank {
  font-size: var(--font-body-1);
  color: var(--gray-500);
  margin-top: 0.25rem;
}

/* Photo Upload Actions */
.photo-upload-section {
  text-align: center;
  margin-bottom: 1.5rem;
}

.photo-upload-section .member-detail-photo {
  width: 160px;
  height: 160px;
  margin: 0 auto 1rem;
  font-size: var(--font-h1);
}

.photo-upload-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.photo-upload-actions .btn {
  font-size: var(--font-body-1);
  min-height: 48px;
}

/* --- Progress Section --- */
.progress-section {
  margin-bottom: 1.5rem;
}

.progress-bar-container {
  background: var(--gray-100);
  border-radius: 8px;
  height: 12px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 8px;
  transition: width 0.3s ease;
}

.progress-bar-label {
  font-size: var(--font-body-1);
  color: var(--gray-500);
  text-align: right;
}

/* --- Requirement Toggles --- */
.requirement-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.requirement-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--gray-50);
  border-radius: 8px;
  min-height: 48px;
  cursor: pointer;
  user-select: none;
}

.requirement-item label {
  flex: 1;
  font-size: var(--font-body-1);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.toggle-switch {
  appearance: none;
  -webkit-appearance: none;
  width: 48px;
  height: 26px;
  background: var(--gray-300);
  border-radius: 26px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-switch::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch:checked {
  background: var(--primary);
}

.toggle-switch:checked::before {
  transform: translateX(22px);
}

.toggle-switch:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.requirement-type-header {
  font-weight: 600;
  font-size: var(--font-body-1);
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  padding-left: 0.25rem;
}

/* Promotion Eligibility Banner */
.promotion-banner {
  background: var(--success-light);
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
  margin-bottom: 1rem;
}

.promotion-banner-text {
  color: var(--success);
  font-weight: 600;
  font-size: var(--font-body-1);
}

.promotion-banner-sub {
  font-size: var(--font-body-3);
  color: var(--gray-600);
  margin-top: 0.25rem;
}

/* Back Button */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  font-size: var(--font-body-1);
  font-weight: 500;
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  margin-bottom: 0.75rem;
  min-height: 48px;
}

.back-btn:active {
  opacity: 0.7;
}

/* ============================================================================
   Modal
   ============================================================================ */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--white);
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}

.modal-title {
  font-size: var(--font-body-1);
  font-weight: 600;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ============================================================================
   Loading & Empty States
   ============================================================================ */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--gray-400);
  font-size: var(--font-body-1);
}

/* ============================================================================
   Toast Alerts (fixed position)
   ============================================================================ */

.toast-alert {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  min-width: 280px;
  padding: 1rem 1.5rem;
  border-radius: 10px;
  font-size: var(--font-body-1);
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: toastSlideIn 0.3s ease;
}

.toast-alert.success { background: var(--success-light); color: var(--success); }
.toast-alert.error { background: var(--danger-light); color: var(--danger); }

@keyframes toastSlideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============================================================================
   Responsive — Portrait Tablets (< 900px)
   ============================================================================ */

@media (max-width: 900px) {
  .member-detail-header {
    flex-direction: column;
    text-align: center;
  }

  .photo-upload-actions {
    flex-direction: column;
    align-items: center;
  }
}

/* Generic member avatar — fallback for contexts without a scoped parent */
.member-avatar {
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  background: var(--gray-200);
  color: var(--gray-600);
  overflow: hidden;
}

.member-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
