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

:root {
  --bg-primary: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --text-primary: #eaeaea;
  --text-secondary: #a0a0b0;
  --accent: #4fc3f7;
  --green: #4CAF50;
  --amber: #FF9800;
  --red: #F44336;
  --dark-red: #B71C1C;
  --purple: #7B1FA2;
  --danger: #e53935;
  --nav-height: 70px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

/* Auth Screen */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
}

.auth-container {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.auth-container h1 {
  font-size: 28px;
  margin-bottom: 12px;
  color: var(--accent);
}

.auth-container p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 16px;
}

.auth-container input {
  width: 100%;
  padding: 16px;
  font-size: 16px;
  border: 2px solid var(--bg-input);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-container input:focus {
  border-color: var(--accent);
}

/* Buttons */
.btn-primary {
  width: 100%;
  padding: 16px;
  font-size: 18px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #000;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.btn-primary:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-large {
  height: 60px;
  font-size: 20px;
}

.btn-save {
  height: 60px;
  font-size: 22px;
  font-weight: 700;
  margin-top: 16px;
  letter-spacing: 1px;
}

.btn-secondary {
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  border: 2px solid var(--text-secondary);
  border-radius: 12px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
}

.btn-danger {
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
}

.btn-export {
  margin-top: 20px;
  height: 50px;
}

/* App Shell */
#app-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#screens-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.screen.active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.screen-content {
  padding: 20px 16px;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
}

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

/* Severity Grid (Quick Entry) */
.severity-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.severity-btn {
  height: 80px;
  font-size: 28px;
  font-weight: 700;
  border: 3px solid transparent;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.2s;
  color: #fff;
}

.severity-btn:active {
  transform: scale(0.95);
}

.severity-btn.selected {
  border-color: #fff;
  box-shadow: 0 0 20px rgba(255,255,255,0.3);
}

.severity-btn:nth-child(5) {
  grid-column: 1 / -1;
  max-width: 50%;
  justify-self: center;
  width: 100%;
}

.severity-1, .severity-btn-sm.severity-1 { background: var(--green); }
.severity-2, .severity-btn-sm.severity-2 { background: var(--amber); }
.severity-3, .severity-btn-sm.severity-3 { background: var(--red); }
.severity-4, .severity-btn-sm.severity-4 { background: var(--dark-red); }
.severity-aura, .severity-btn-sm.severity-aura { background: var(--purple); }

/* Severity Row (Backfill/Edit) */
.severity-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.severity-btn-sm {
  flex: 1;
  height: 48px;
  font-size: 16px;
  font-weight: 700;
  border: 3px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  color: #fff;
  transition: transform 0.1s, border-color 0.2s;
}

.severity-btn-sm:active {
  transform: scale(0.95);
}

.severity-btn-sm.selected {
  border-color: #fff;
  box-shadow: 0 0 12px rgba(255,255,255,0.3);
}

/* Form Groups */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  border: 2px solid var(--bg-input);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
}

.form-group textarea {
  resize: vertical;
  min-height: 50px;
}

/* Toggle Switch */
.toggle-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-group label:first-child {
  font-size: 16px;
  color: var(--text-primary);
  margin-bottom: 0;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 56px;
  height: 32px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #444;
  border-radius: 32px;
  transition: background 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 26px;
  height: 26px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(24px);
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}

.filter-btn {
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  border: 2px solid var(--bg-input);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(79, 195, 247, 0.1);
}

.refresh-btn {
  margin-left: auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Attacks List */
.attacks-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.attack-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: transform 0.1s;
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.attack-severity-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

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

.attack-date {
  font-size: 16px;
  font-weight: 700;
}

.attack-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attack-tags {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.tag {
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.tag-prostrating {
  background: rgba(244, 67, 54, 0.2);
  color: var(--red);
}

.tag-aura {
  background: rgba(123, 31, 162, 0.2);
  color: #ce93d8;
}

/* Stats */
.stats-rating-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  margin-bottom: 20px;
}

.rating-label {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.rating-value {
  font-size: 48px;
  font-weight: 800;
  color: var(--accent);
}

.stats-table-container {
  overflow-x: auto;
  border-radius: 12px;
  background: var(--bg-card);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.stats-table th {
  padding: 12px 10px;
  text-align: left;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--bg-input);
}

.stats-table td {
  padding: 12px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.stats-table tr:last-child td {
  border-bottom: none;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
}

.modal-content {
  position: relative;
  background: var(--bg-primary);
  border-radius: 20px 20px 0 0;
  padding: 24px 16px;
  padding-bottom: calc(24px + var(--safe-bottom));
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-content h2 {
  font-size: 22px;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions button {
  flex: 1;
}

/* Toast */
.toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 14px 24px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  z-index: 2000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transition: opacity 0.3s, transform 0.3s;
  opacity: 0;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  pointer-events: auto;
}

.toast.success {
  border-left: 4px solid var(--green);
}

.toast.error {
  border-left: 4px solid var(--danger);
}

/* Bottom Navigation */
.bottom-nav {
  display: flex;
  height: var(--nav-height);
  padding-bottom: var(--safe-bottom);
  background: var(--bg-card);
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  padding: 8px 4px;
  transition: color 0.2s;
  min-height: 60px;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-btn svg {
  width: 24px;
  height: 24px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 16px;
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Responsive tweaks */
@media (min-width: 500px) {
  .screen-content {
    max-width: 460px;
    margin: 0 auto;
  }
}
