﻿/* ============================================
   CSS Variables & Reset
   ============================================ */
:root {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #eff6ff;
  --success:        #10b981;
  --success-light:  #d1fae5;
  --danger:         #ef4444;
  --danger-light:   #fee2e2;
  --warning:        #f59e0b;

  --bg:             #f1f5f9;
  --surface:        #ffffff;
  --border:         #e2e8f0;
  --border-strong:  #cbd5e1;

  --text:           #0f172a;
  --text-muted:     #64748b;
  --text-light:     #94a3b8;

  --header-bg:      #0f172a;
  --header-text:    #f8fafc;

  --c1-bg: #e2e8f0; --c1-text: #475569;
  --c2-bg: #dbeafe; --c2-text: #1d4ed8;
  --c3-bg: #ede9fe; --c3-text: #7c3aed;
  --c4-bg: #fef3c7; --c4-text: #b45309;
  --c5-bg: #fee2e2; --c5-text: #b91c1c;

  --win-bg:   #bbf7d0;
  --win-text: #15803d;
  --loss-bg:  #fef9c3;
  --loss-text:#854d0e;

  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);
}

*, *::before, *::after { 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);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ============================================
   Header
   ============================================ */
.app-header {
  background: var(--header-bg);
  color: var(--header-text);
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--header-text);
}

/* ============================================
   Tab Navigation
   ============================================ */
.tabs-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 56px;
  z-index: 90;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.tabs-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 2px;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 18px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}

.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ============================================
   Main Content
   ============================================ */
.app-main {
  max-width: 1200px;
  margin: 28px auto;
  padding: 0 20px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow);
}

.panel-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
}

.panel-title-row { margin-bottom: 20px; }
.panel-subtitle { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ============================================
   Forms
   ============================================ */
.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 6px;
}

.form-hint { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}

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

.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: "Cascadia Code", "Consolas", monospace;
  color: var(--text);
  background: #fafafa;
  resize: vertical;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  line-height: 1.6;
}

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

/* ============================================
   Buttons
   ============================================ */
.button-row { display: flex; gap: 10px; margin-bottom: 20px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s, box-shadow .15s;
  white-space: nowrap;
}

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

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--primary-dark); box-shadow: 0 2px 8px rgba(37,99,235,.35); }

.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: #e8edf3; }

.btn-danger { background: var(--danger-light); color: var(--danger); border: 1px solid #fca5a5; }
.btn-danger:hover { background: #fecaca; }

.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ============================================
   Alerts & Badges
   ============================================ */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; }
.alert-error { background: var(--danger-light); color: #991b1b; border: 1px solid #fca5a5; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
}

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); font-size: 15px; }
.table-note { margin-top: 12px; font-size: 12px; color: var(--text-light); text-align: right; }

/* ============================================
   Tables
   ============================================ */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-top: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.data-table thead { background: #f8fafc; border-bottom: 2px solid var(--border-strong); }

.data-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-align: center;
}

.data-table td:first-child, .data-table th:first-child { text-align: left; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--primary-light); }

.data-table td.win { background: var(--win-bg); color: var(--win-text); font-weight: 700; }
.data-table td.loss { background: var(--loss-bg); color: var(--loss-text); }

.player-name { font-weight: 600; color: var(--text); text-align: left !important; white-space: nowrap; }
.score-cell { font-weight: 600; font-variant-numeric: tabular-nums; }
.score-cell.highlight { color: var(--primary); font-size: 14px; }
.court-cell { text-align: center !important; }

.data-table tr.not-counted { opacity: .5; }
.counted-yes { color: var(--success); font-weight: 700; }
.counted-no  { color: var(--text-light); }

/* ============================================
   Court Badges
   ============================================ */
.court-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
}

.court-1 { background: var(--c1-bg); color: var(--c1-text); }
.court-2 { background: var(--c2-bg); color: var(--c2-text); }
.court-3 { background: var(--c3-bg); color: var(--c3-text); }
.court-4 { background: var(--c4-bg); color: var(--c4-text); }
.court-5 { background: var(--c5-bg); color: var(--c5-text); }

/* ============================================
   Rankings Table
   ============================================ */
.rank-cell { font-weight: 800; font-size: 15px; text-align: center !important; width: 48px; }
.rank-gold   { color: #d97706; }
.rank-silver { color: #6b7280; }
.rank-bronze { color: #b45309; }

/* ============================================
   Preview Section
   ============================================ */
.preview-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  margin-bottom: 4px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.preview-title { font-size: 16px; font-weight: 700; }

/* ============================================
   History / Session Cards
   ============================================ */
.session-card { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }

.session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: #fafafa;
}

.session-info h3 { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.session-meta { font-size: 12px; color: var(--text-muted); }
.session-actions { display: flex; gap: 8px; }

.session-detail {
  padding: 0 18px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ============================================
   Player Summary in Modal
   ============================================ */
.player-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius);
}

.summary-stat { display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.stat-value { font-size: 22px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-value.highlight { color: var(--primary); }
.modal-section-title { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 4px; }

/* ============================================
   Modal
   ============================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}

.modal.hidden { display: none; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(2px); }

.modal-dialog {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 1100px;
  z-index: 1;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 20px; font-weight: 700; }

.modal-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}

.modal-close-btn:hover { background: var(--border); color: var(--text); }
.modal-body { padding: 24px; overflow-x: auto; }

/* ============================================
   Toast Notifications
   ============================================ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  transform: translateY(16px);
  opacity: 0;
  transition: transform .25s ease, opacity .25s ease;
  max-width: 360px;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }

/* ============================================
   Utilities
   ============================================ */
.hidden { display: none !important; }

/* ============================================
   Password Modal
   ============================================ */
.pw-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(3px);
}

.pw-dialog {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
  z-index: 1;
  padding: 28px;
  margin: auto;
}

.pw-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

.pw-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
  min-height: 18px;
}

.pw-error {
  font-size: 12px;
  color: var(--danger);
  font-weight: 600;
  margin-top: 8px;
}

.pw-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}

#pw-modal {
  align-items: center;
}
