/* Knowledge Factory Control Room — Deep Black & ISA-101 HMI Stylesheet */
:root {
  --bg-deep: #09090b;
  --bg-card: #18181b;
  --bg-card-hover: #222226;
  --border-color: #27272a;
  --border-focus: #3f3f46;
  --text-main: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-subtle: #71717a;
  --accent-normal: #71717a; /* ISA-101: Grey is normal */
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --accent-blue: #3b82f6;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: 84px; /* Space for bottom navigation */
  min-height: 100vh;
}

/* Demo Data Banner (Yellow - Shown on every screen in --fake-hub mode) */
.demo-alert-banner {
  background-color: var(--accent-amber);
  color: #18181b;
  padding: 10px 16px;
  font-weight: 800;
  text-align: center;
  font-size: 14px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 102;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}

.demo-alert-banner.hidden {
  display: none;
}

/* Database Error Alert Header Banner (Red) */
.db-error-alert-banner {
  background-color: var(--accent-red);
  color: #fff;
  padding: 12px 16px;
  font-weight: 700;
  text-align: center;
  font-size: 14px;
  position: sticky;
  top: 0;
  z-index: 101;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.db-error-alert-banner.hidden {
  display: none;
}

/* Stale Hub Header Alert */
.hub-alert-banner {
  background-color: var(--accent-red);
  color: #fff;
  padding: 12px 16px;
  font-weight: 700;
  text-align: center;
  font-size: 15px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.hub-alert-banner.hidden {
  display: none;
}

/* Top App Header */
.top-header {
  padding: 16px 20px;
  background-color: rgba(9, 9, 11, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background-color: #27272a;
  color: var(--text-muted);
}

.header-meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Status Lamp */
.lamp {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: var(--accent-normal);
}
.lamp.green { background-color: var(--accent-green); box-shadow: 0 0 8px rgba(16, 185, 129, 0.6); }
.lamp.amber { background-color: var(--accent-amber); box-shadow: 0 0 8px rgba(245, 158, 11, 0.6); }
.lamp.red { background-color: var(--accent-red); box-shadow: 0 0 8px rgba(239, 68, 68, 0.8); }

/* Main Container */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

/* Tab Screens */
.tab-screen {
  display: none;
}
.tab-screen.active {
  display: block;
}

/* Needs You Card */
.needs-you-card {
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.needs-you-card.empty {
  border-color: #27272a;
  color: var(--text-muted);
}

.needs-you-card.action-required {
  border-color: var(--accent-amber);
  background-color: #1f1b13;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.15);
}

.needs-you-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.needs-you-card.empty .needs-you-title {
  color: var(--accent-green);
}
.needs-you-card.action-required .needs-you-title {
  color: var(--accent-amber);
}

.needs-you-sentence {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-main);
}

/* Section Header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 24px 0 12px 0;
}

.section-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Mimic Diagram (Plant View Level 1) */
.plant-mimic-wrapper {
  background-color: #101014;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 24px;
  overflow-x: auto;
}

.plant-svg {
  width: 100%;
  min-width: 700px;
  height: auto;
  display: block;
}

/* Plant summary metrics sentence */
.plant-sentence-box {
  margin-top: 12px;
  padding: 10px 14px;
  background-color: #141418;
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.4;
}
.plant-sentence-box strong {
  color: var(--text-main);
}

/* Card Lists & Grids */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  transition: border-color 0.15s;
}

.card:hover {
  border-color: var(--border-focus);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-subtext {
  font-size: 13px;
  color: var(--text-subtle);
  margin-top: 2px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background-color: #27272a;
  color: var(--text-muted);
}
.badge.green { background-color: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge.amber { background-color: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge.red { background-color: rgba(239, 68, 68, 0.15); color: #f87171; }

.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  padding: 6px 0;
  border-bottom: 1px solid #1f1f23;
}
.metric-row:last-child {
  border-bottom: none;
}
.metric-label {
  color: var(--text-muted);
}
.metric-value {
  font-weight: 600;
  color: var(--text-main);
}

/* Touch-First Buttons */
.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px; /* Large touch target */
  min-width: 48px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: #27272a;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

button:hover, .btn:hover {
  background-color: #3f3f46;
  border-color: #52525b;
}

button:active, .btn:active {
  transform: scale(0.98);
}

button.primary {
  background-color: #f4f4f5;
  color: #09090b;
  border-color: #f4f4f5;
}
button.primary:hover {
  background-color: #e4e4e7;
}

button.danger {
  background-color: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}
button.danger:hover {
  background-color: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
}

button.warning {
  background-color: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.3);
}

button.sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
}

/* E-STOP Button */
.e-stop-btn {
  background-color: var(--accent-red);
  color: #fff;
  border: 2px solid #b91c1c;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 14px 24px;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4);
  width: 100%;
  margin-top: 10px;
}
.e-stop-btn:hover {
  background-color: #dc2626;
}

.resume-btn {
  background-color: var(--accent-green);
  color: #fff;
  border: 2px solid #059669;
  font-size: 16px;
  font-weight: 800;
  padding: 14px 24px;
  border-radius: var(--radius-lg);
  width: 100%;
  margin-top: 10px;
}

/* Bottom Bar Navigation (Phone-First) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 68px;
  background-color: rgba(18, 18, 20, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  min-height: 48px;
  color: var(--text-subtle);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease;
  user-select: none;
}

.nav-item svg {
  width: 22px;
  height: 22px;
  margin-bottom: 3px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.nav-item.active {
  color: #ffffff;
}

.nav-item.active svg {
  stroke: #ffffff;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
}
.modal-overlay.hidden {
  display: none;
}

.modal-content {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}

.modal-body {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Form inputs inside modals */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  min-height: 48px;
  background-color: #101014;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 15px;
  font-family: inherit;
}
.form-textarea {
  min-height: 100px;
  resize: vertical;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: #52525b;
}

/* Toast Notifications */
.toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #27272a;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  font-weight: 500;
  z-index: 3000;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90%;
  text-align: center;
}
.toast.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
}

/* Login Screen (Shown when no valid session) */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  padding: 24px;
  text-align: center;
}

.login-screen.hidden {
  display: none !important;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 40px 28px;
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
}

.login-sentence {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.login-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--accent-red);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  width: 100%;
}

.login-error.hidden {
  display: none !important;
}

.login-btn-container {
  min-height: 44px;
  margin-top: 8px;
  display: flex;
  justify-content: center;
}

.logout-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-subtle);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-right: 6px;
  transition: all 0.2s;
}

.logout-btn:hover {
  border-color: #ef4444;
  color: #ef4444;
}

.logout-btn.hidden {
  display: none !important;
}

/* ==============================================================
   PC LAYOUT (>=1024px) & RESPONSIVE RULES (Spec Round 6)
   ============================================================== */

/* Navigation Brand */
.nav-brand {
  display: none;
}

/* Home Layout on Mobile / Tablet (<1024px) */
.home-layout-grid {
  display: flex;
  flex-direction: column;
}

@media (max-width: 1023px) {
  .home-side-col {
    display: contents;
  }
  #needs-you-card {
    order: -1;
  }
  .home-main-col {
    order: 0;
  }
  .estop-card {
    order: 1;
    margin-top: 20px;
  }
}

/* PC Layout (>=1024px) */
@media (min-width: 1024px) {
  body {
    padding-bottom: 0;
    margin-left: 220px; /* Space for fixed left nav sidebar */
  }

  /* Left-side Navigation Sidebar */
  .bottom-nav {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: auto;
    width: 220px;
    height: 100vh;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 20px 12px;
    background-color: #121215;
    border-top: none;
    border-right: 1px solid var(--border-color);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.4);
    z-index: 1000;
  }

  .nav-brand {
    display: block;
    padding: 8px 12px 20px 12px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 12px;
  }

  .nav-item {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    height: auto;
    min-height: 44px;
    color: var(--text-muted);
    margin-bottom: 4px;
  }

  .nav-item svg {
    margin-bottom: 0;
    width: 20px;
    height: 20px;
  }

  .nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
  }

  .nav-item.active {
    background-color: #27272a;
    color: #ffffff;
  }

  /* Main container on Desktop */
  .container {
    max-width: 1600px;
    margin: 0;
    padding: 24px 32px;
  }

  /* Home Screen 2-Column Split: Plant View left/center, Needs You + Big Pause on right */
  .home-layout-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 20px;
    align-items: start;
  }

  .home-main-col {
    min-width: 0; /* Prevents grid blowout */
  }

  .home-side-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .home-side-col #needs-you-card {
    margin-bottom: 0;
  }

  .home-side-col .estop-card {
    margin-top: 0;
  }

  /* Plant SVG auto-scaling on desktop */
  .plant-mimic-wrapper {
    overflow: hidden;
    padding: 16px;
  }

  .plant-svg {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    height: auto;
    display: block;
  }

  /* Worker cards grid on desktop: 2-3 on 1366, 3-4 on 1920 */
  #workers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
  }

  /* Logs Panel: tall enough to see 25+ lines */
  #logs-container {
    height: calc(100vh - 220px) !important;
    min-height: 580px !important;
    max-height: none !important;
  }
}

/* Extra Large screens (1920x1080) */
@media (min-width: 1600px) {
  .home-layout-grid {
    grid-template-columns: 1fr 380px;
    gap: 28px;
  }

  #workers-grid {
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  }
}


