/* ====================================
   Kairos Portal — CSS
   ==================================== */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- NAV ---- */
.top-nav {
  background: var(--gray-900);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 56px;
  gap: 32px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
}

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: white;
  font-weight: 700;
  font-size: 18px;
  border-radius: 6px;
}

.logo-lg {
  width: 56px;
  height: 56px;
  font-size: 28px;
  border-radius: 12px;
}

.brand-text { color: white; }

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-links a {
  color: var(--gray-300);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
  transition: background 0.15s;
}

.nav-links a:hover {
  background: rgba(255,255,255,0.1);
  color: white;
  text-decoration: none;
}

.nav-links a.active {
  background: rgba(255,255,255,0.15);
  color: white;
}

.nav-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
  color: var(--gray-300);
}

.nav-user a {
  color: var(--gray-300);
  font-size: 13px;
}

.nav-user a:hover { color: white; }

/* ---- CONTAINER ---- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ---- LOGIN ---- */
.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--gray-900) 0%, #1e3a5f 100%);
}

.login-box {
  background: white;
  border-radius: 12px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-brand h1 {
  margin-top: 16px;
  font-size: 24px;
}

.login-brand .subtitle {
  color: var(--gray-500);
  font-size: 14px;
}

/* ---- FORMS ---- */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  font-size: 14px;
  color: var(--gray-700);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 15px;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ---- BUTTONS ---- */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  text-align: center;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  text-decoration: none;
  color: white;
}

.btn-full { width: 100%; }

.btn-disabled {
  background: var(--gray-200);
  color: var(--gray-500);
  cursor: not-allowed;
}

/* ---- ALERTS ---- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 14px;
}

.alert-error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.alert-success {
  background: #f0fdf4;
  color: var(--success);
  border: 1px solid #bbf7d0;
}

/* ---- STATS ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  border: 1px solid var(--gray-200);
}

.stat-number {
  font-size: 36px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 14px;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ---- CARDS ---- */
.card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  padding: 24px;
  margin-bottom: 24px;
}

.card h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

/* ---- TABLES ---- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
  font-weight: 600;
  font-size: 13px;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
}

tbody tr:hover {
  background: var(--gray-50);
}

/* ---- PROGRESS BARS ---- */
.progress-bar-inline {
  display: inline-block;
  width: 100px;
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 8px;
}

.progress-bar-lg {
  width: 100%;
  height: 12px;
  background: var(--gray-200);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: inherit;
  transition: width 0.3s;
}

.progress-pct {
  font-size: 13px;
  color: var(--gray-500);
  vertical-align: middle;
}

/* ---- BADGES ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-progress {
  background: #dbeafe;
  color: var(--primary);
}

.badge-responses {
  background: #f0fdf4;
  color: var(--success);
}

/* ---- COURSES GRID ---- */
.courses-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.course-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 24px;
}

.course-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.course-card h3 {
  font-size: 18px;
}

.course-size {
  color: var(--gray-500);
  font-size: 14px;
  margin-bottom: 16px;
}

/* ---- FILE UPLOAD ---- */
.file-drop-zone {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}

.file-drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* ---- RESPONSES ---- */
.response-item {
  padding: 16px 0;
  border-bottom: 1px solid var(--gray-100);
}

.response-item:last-child {
  border-bottom: none;
}

.response-header {
  margin-bottom: 8px;
}

.response-text {
  background: var(--gray-50);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  white-space: pre-wrap;
  line-height: 1.7;
}

/* ---- UTILITIES ---- */
.subtitle {
  color: var(--gray-500);
  font-size: 14px;
  margin-bottom: 24px;
}

.text-muted { color: var(--gray-500); }

.empty-state {
  color: var(--gray-500);
  font-style: italic;
  padding: 20px 0;
}

.error-page {
  text-align: center;
  padding: 80px 0;
}

.error-page h2 {
  font-size: 32px;
  margin-bottom: 12px;
}

.error-page p {
  color: var(--gray-500);
  margin-bottom: 24px;
}

h2 {
  margin-bottom: 8px;
}

h2 a {
  font-size: 14px;
  font-weight: 400;
}

.progress-summary {
  max-width: 500px;
  margin-bottom: 24px;
}

/* ---- FOOTER ---- */
.site-footer {
  text-align: center;
  padding: 24px;
  color: var(--gray-500);
  font-size: 13px;
}

.login-page .site-footer {
  color: rgba(255,255,255,0.4);
}

/* ---- PAGE HEADER ---- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
}

.page-header h2 { margin-bottom: 0; }

/* ---- DEVICE STATUS BADGES ---- */
.badge-active {
  background: #f0fdf4;
  color: var(--success);
}

.badge-provisioning {
  background: #dbeafe;
  color: var(--primary);
}

.badge-maintenance {
  background: #fef3c7;
  color: var(--warning);
}

.badge-retired {
  background: var(--gray-100);
  color: var(--gray-500);
}

.badge-lost {
  background: #fef2f2;
  color: var(--danger);
}

/* ---- API KEY ---- */
.api-key-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
}

.api-key-display code {
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  word-break: break-all;
  flex: 1;
}

.api-key-display .btn-sm {
  flex-shrink: 0;
}

/* ---- DETAIL GRID ---- */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.detail-item {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
}

.detail-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-500);
  margin-bottom: 4px;
}

.detail-value {
  font-size: 16px;
  font-weight: 500;
}

/* ---- FORM EXTRAS ---- */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
}

.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.btn-secondary {
  display: inline-block;
  padding: 10px 20px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: white;
  color: var(--gray-700);
  text-align: center;
}

.btn-secondary:hover {
  background: var(--gray-50);
  text-decoration: none;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-form select {
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
}

/* ---- WARNINGS ---- */
.text-warning { color: var(--warning); font-weight: 500; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .top-nav {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 16px;
    gap: 12px;
  }

  .nav-links { width: 100%; }
  .nav-user { width: 100%; justify-content: flex-end; }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  table { font-size: 13px; }

  .container { padding: 20px 16px; }

  .login-box { margin: 20px; padding: 32px 24px; }
}
