/* ═══════════════════════════════════════════════════════════
   LineSpec App — Dark theme, mobile-first for factory floor
   ═══════════════════════════════════════════════════════════ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #07080c;
  --bg-elevated: #0e1017;
  --bg-input: #141620;
  --accent: #ff6b35;
  --accent-glow: rgba(255, 107, 53, 0.15);
  --accent-hover: #ff8555;
  --text: #e4e4e7;
  --text-dim: #8b8b96;
  --text-muted: #555;
  --border: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(255, 107, 53, 0.4);
  --success: #28c840;
  --warning: #febc2e;
  --danger: #ff5f57;
  --info: #5b9aff;
  --radius: 12px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: 'DM Sans', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4 { font-family: 'Space Grotesk', sans-serif; }

/* ─── App Header ─────────────────────────────────────────── */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.25rem;
  background: rgba(7, 8, 12, 0.9);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.app-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.5px;
}
.app-logo span { color: var(--accent); }

.shift-indicator {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-dim);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.3rem 0.8rem;
  border-radius: 100px;
}

.shift-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}
.shift-dot.active {
  background: var(--success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ─── Bottom Navigation ──────────────────────────────────── */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  background: rgba(7, 8, 12, 0.95);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.65rem 0.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.68rem;
  font-weight: 500;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

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

.nav-item svg {
  width: 22px;
  height: 22px;
}

/* ─── Main Content ───────────────────────────────────────── */

.app-content {
  padding: 4.2rem 1rem 5rem;
  min-height: 100vh;
  max-width: 800px;
  margin: 0 auto;
}

/* ─── Cards ──────────────────────────────────────────────── */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 0.75rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.3px;
}

/* ─── Stats Grid ─────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.stat-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--accent);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

/* ─── Section Headers ────────────────────────────────────── */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.section-label {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

/* ─── Buttons ────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

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

.btn-danger {
  background: rgba(255, 95, 87, 0.12);
  color: var(--danger);
  border: 1px solid rgba(255, 95, 87, 0.2);
}

.btn-sm {
  padding: 0.45rem 0.8rem;
  font-size: 0.78rem;
  min-height: 36px;
}

.btn-block {
  width: 100%;
}

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

/* ─── Forms ──────────────────────────────────────────────── */

.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
  letter-spacing: 0.3px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  transition: border-color 0.2s;
  min-height: 44px;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.5;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%238b8b96' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  padding-right: 2.5rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* ─── Severity Selector (touch-friendly buttons) ─────────── */

.severity-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.severity-btn {
  padding: 0.6rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.severity-btn[data-severity="critical"].active {
  background: rgba(255, 95, 87, 0.15);
  border-color: var(--danger);
  color: var(--danger);
}
.severity-btn[data-severity="major"].active {
  background: rgba(254, 188, 46, 0.15);
  border-color: var(--warning);
  color: var(--warning);
}
.severity-btn[data-severity="minor"].active {
  background: rgba(91, 154, 255, 0.15);
  border-color: var(--info);
  color: var(--info);
}
.severity-btn[data-severity="observation"].active {
  background: rgba(139, 139, 150, 0.15);
  border-color: var(--text-dim);
  color: var(--text-dim);
}

/* ─── Severity Badges ────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 100px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-critical {
  background: rgba(255, 95, 87, 0.15);
  color: var(--danger);
  border: 1px solid rgba(255, 95, 87, 0.25);
}
.badge-major {
  background: rgba(254, 188, 46, 0.15);
  color: var(--warning);
  border: 1px solid rgba(254, 188, 46, 0.25);
}
.badge-minor {
  background: rgba(91, 154, 255, 0.15);
  color: var(--info);
  border: 1px solid rgba(91, 154, 255, 0.25);
}
.badge-observation {
  background: rgba(139, 139, 150, 0.1);
  color: var(--text-dim);
  border: 1px solid rgba(139, 139, 150, 0.2);
}
.badge-open {
  background: rgba(40, 200, 64, 0.12);
  color: var(--success);
  border: 1px solid rgba(40, 200, 64, 0.2);
}

/* ─── Inspection List Items ──────────────────────────────── */

.inspection-item {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 1rem 1.1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
  cursor: pointer;
  transition: border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.inspection-item:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.inspection-severity-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 0.35rem;
  flex-shrink: 0;
}
.inspection-severity-dot.critical { background: var(--danger); }
.inspection-severity-dot.major { background: var(--warning); }
.inspection-severity-dot.minor { background: var(--info); }
.inspection-severity-dot.observation { background: var(--text-muted); }

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

.inspection-type {
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 0.2rem;
  letter-spacing: -0.2px;
}

.inspection-meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.inspection-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-top: 0.1rem;
}

/* ─── AI Analysis Card ───────────────────────────────────── */

.ai-card {
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 107, 53, 0.2);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-top: 0.75rem;
}

.ai-card-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.6rem;
}

.ai-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.ai-row:last-child { border: none; }

.ai-label {
  color: var(--text-dim);
  font-size: 0.75rem;
  flex-shrink: 0;
  margin-right: 0.75rem;
}

.ai-value {
  text-align: right;
  font-weight: 500;
}

/* ─── Handoff View ───────────────────────────────────────── */

.handoff-content {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  font-size: 0.88rem;
  line-height: 1.7;
}

.handoff-content h1,
.handoff-content h2,
.handoff-content h3 {
  color: var(--accent);
  margin: 1rem 0 0.5rem;
}
.handoff-content h1:first-child,
.handoff-content h2:first-child {
  margin-top: 0;
}
.handoff-content h1 { font-size: 1.2rem; }
.handoff-content h2 { font-size: 1.05rem; }
.handoff-content h3 { font-size: 0.95rem; }

.handoff-content ul, .handoff-content ol {
  padding-left: 1.25rem;
  margin: 0.5rem 0;
}
.handoff-content li {
  margin-bottom: 0.3rem;
}
.handoff-content strong {
  color: var(--text);
}
.handoff-content p {
  margin-bottom: 0.5rem;
}

/* ─── Shift Cards ────────────────────────────────────────── */

.shift-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 0.6rem;
}

.shift-card.active-shift {
  border-color: rgba(40, 200, 64, 0.3);
}

.shift-name {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.shift-meta {
  font-size: 0.78rem;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* ─── Empty State ────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 0.4rem;
}

.empty-state p {
  font-size: 0.85rem;
  max-width: 300px;
  margin: 0 auto 1rem;
  line-height: 1.5;
}

/* ─── Detail View ────────────────────────────────────────── */

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

.back-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.3rem;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.detail-row:last-child { border: none; }

.detail-label {
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ─── Loading / Spinner ──────────────────────────────────── */

.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 0.5rem;
}

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

/* ─── Toast / Notification ───────────────────────────────── */

.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 0.7rem 1.2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  z-index: 100;
  transition: transform 0.3s ease;
  max-width: 90%;
  text-align: center;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
}
.toast.success { border-color: rgba(40, 200, 64, 0.4); }
.toast.error { border-color: rgba(255, 95, 87, 0.4); }

/* ─── Quick Actions ──────────────────────────────────────── */

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}

/* ─── Defect Type Quick Select ───────────────────────────── */

.defect-types {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.defect-chip {
  padding: 0.4rem 0.75rem;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.defect-chip.active {
  background: var(--accent-glow);
  border-color: rgba(255, 107, 53, 0.4);
  color: var(--accent);
}

/* ─── Responsive ─────────────────────────────────────────── */

@media (min-width: 600px) {
  .app-content {
    padding: 4.5rem 1.5rem 5rem;
  }
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .form-row {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

@media (min-width: 900px) {
  .bottom-nav {
    top: 0;
    bottom: auto;
    left: 0;
    width: 70px;
    right: auto;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--border);
    padding-top: 4rem;
    padding-bottom: 0;
  }
  .nav-item {
    padding: 0.85rem 0.5rem;
  }
  .nav-item span {
    display: none;
  }
  .app-content {
    margin-left: 70px;
    padding: 4.5rem 2rem 2rem;
    max-width: 900px;
  }
}
