* { box-sizing: border-box; }

/* ===== THEME VARIABLES ===== */
:root[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --shadow: 0 20px 25px -5px rgba(15,23,42,.05), 0 8px 10px -6px rgba(15,23,42,.04);
  --terminal-bg: #0f172a;
  --terminal-text: #e2e8f0;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #dc2626;
}

:root[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 20px 25px -5px rgba(0,0,0,.3), 0 8px 10px -6px rgba(0,0,0,.2);
  --terminal-bg: #020617;
  --terminal-text: #e2e8f0;
  --error-bg: #7f1d1d;
  --error-border: #991b1b;
  --error-text: #fca5a5;
}

body {
  margin: 0;
  font-family: 'Montserrat', system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s, color 0.3s;
}

.page { max-width: 1200px; margin: 0 auto; padding: 2rem 1.25rem 3.5rem; display: flex; flex-direction: column; gap: 1.5rem; }
.card { background: var(--bg-secondary); border-radius: 1.5rem; box-shadow: var(--shadow); padding: 1.5rem; transition: background-color 0.3s; }

/* ===== HEADER ===== */
header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; }
.header-title { display: flex; align-items: center; gap: 1rem; }
.header-logo { height: 50px; width: auto; }
header h1 { font-size: 1.9rem; font-weight: 600; margin: 0; }
header p { margin: 0.35rem 0 0; color: var(--text-secondary); font-size: 0.9rem; }
.header-actions { display: flex; align-items: center; gap: 0.75rem; }

/* ===== THEME TOGGLE ===== */
.theme-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 1.25rem;
  line-height: 1;
}
.theme-toggle:hover {
  transform: scale(1.1);
  background: var(--border);
}
.theme-icon {
  display: inline-block;
  transition: transform 0.3s;
}
.theme-toggle:hover .theme-icon {
  transform: rotate(20deg);
}

/* ===== TOAST NOTIFICATIONS ===== */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}
.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 300px;
  max-width: 400px;
  pointer-events: auto;
  animation: slideIn 0.3s ease-out;
  border-left: 4px solid #173592;
}
.toast.success { border-left-color: #00b4df; }
.toast.error { border-left-color: #ef4444; }
.toast.warning { border-left-color: #ff713b; }
.toast-icon { flex-shrink: 0; width: 20px; height: 20px; }
.toast-content { flex: 1; font-size: 0.875rem; }
.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  opacity: 0.5;
  transition: opacity 0.2s;
}
.toast-close:hover { opacity: 1; }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== FORMS ===== */
.form-field { margin-bottom: 1.5rem; }
label {
  font-size: 0.875rem;
  font-weight: 600;
  display: block;
  margin-bottom: 0.625rem;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}
input[type="date"], input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  border-radius: 0.9rem;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  font-size: 0.9375rem;
  transition: all 0.2s;
  line-height: 1.5;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #173592;
  box-shadow: 0 0 0 3px rgba(23,53,146,0.15);
}
textarea { min-height: 120px; resize: vertical; font-family: inherit; }
.form-grid { display: grid; gap: 1.5rem; }
@media (min-width: 720px) { .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

button {
  border: none;
  background: #173592;
  color: #fff;
  padding: 0.55rem 1.2rem;
  border-radius: 0.9rem;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
button:hover { background: #0f2670; transform: translateY(-1px); }
button:disabled { background: #94a3b8; cursor: not-allowed; transform: none; }

.logout-btn { background: #ef4444; padding: 0.4rem 0.8rem; font-size: 0.75rem; }
.logout-btn:hover { background: #dc2626; }

.muted { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.375rem; display: block; line-height: 1.5; }
.cred-box { background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: 1rem; padding: 1.5rem; display: grid; gap: 1.5rem; }
.actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-top: 2rem; }

/* ===== LOGIN PAGE ===== */
.login-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.login-card { background: var(--bg-secondary); border-radius: 1.5rem; box-shadow: var(--shadow); padding: 2.5rem; max-width: 400px; width: 100%; }
.login-logo { height: 80px; width: auto; display: block; margin: 0 auto 1.5rem; }
.login-card h1 { font-size: 1.8rem; margin: 0 0 0.5rem 0; text-align: center; }
.login-card p { color: var(--text-secondary); text-align: center; margin: 0 0 2rem 0; font-size: 0.9rem; }
.login-error { background: var(--error-bg); border: 1px solid var(--error-border); color: var(--error-text); padding: 0.75rem; border-radius: 0.75rem; font-size: 0.8rem; margin-bottom: 1rem; }

/* ===== OUTPUT LOG ===== */
#out {
  background: var(--terminal-bg);
  color: var(--terminal-text);
  border-radius: 1rem;
  padding: 1.25rem 1.5rem;
  font-size: 0.75rem;
  line-height: 1.6;
  white-space: pre-wrap;
  min-height: 150px;
  max-height: 600px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Courier New", monospace;
  border: 1px solid var(--border);
}

.log-info { color: #00b4df; }
.log-success { color: #10b981; }
.log-error { color: #ef4444; }
.log-warn { color: #ff713b; }
.log-phase { color: #ff713b; font-weight: 600; }
.log-summary { color: #00b4df; }

/* ===== PROGRESS BAR ===== */
.progress-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; margin-bottom: 1rem; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #173592, #00b4df); transition: width 0.3s; width: 0%; }

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
.scroll-indicator {
  position: sticky;
  bottom: 0;
  background: rgba(15,23,42,0.9);
  padding: 0.5rem;
  text-align: center;
  font-size: 0.7rem;
  color: #00b4df;
  border-top: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
}
