@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&display=swap');

/* Material Design 3 Tokens */

:root {
  --md-primary: #0b57d0;
  --md-primary-hover: #0842a0;
  --md-primary-container: #d3e3fd;
  --md-on-primary: #ffffff;
  --md-on-primary-container: #041e49;
  
  --md-secondary: #00639b;
  --md-secondary-container: #cce5ff;
  
  --md-surface: #f8f9fa;
  --md-surface-card: #ffffff;
  --md-surface-container: #f1f3f4;
  --md-surface-variant: #e1e2e4;
  --md-on-surface: #1f1f1f;
  --md-on-surface-variant: #444746;
  
  --md-outline: #747775;
  --md-outline-variant: #c4c7c5;
  
  --md-error: #b3261e;
  --md-error-container: #f9dedc;
  --md-on-error: #ffffff;
  --md-on-error-container: #410e0b;

  --md-success: #137333;
  --md-success-container: #e6f4ea;
  --md-on-success: #ffffff;
  --md-on-success-container: #137333;
  
  --md-warning: #b06000;
  --md-warning-container: #ffe0b2;

  --shadow-1: 0 1px 2px 0 rgba(60,64,67,0.3), 0 1px 3px 1px rgba(60,64,67,0.15);
  --shadow-2: 0 1px 3px 0 rgba(60,64,67,0.3), 0 4px 8px 3px rgba(60,64,67,0.15);
  --shadow-3: 0 4px 4px 0 rgba(0,0,0,0.07), 0 8px 12px 6px rgba(0,0,0,0.05);
  
  --radius-xs: 4px;
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 16px;
  --radius-xl: 28px;
  
  --font-title: 'Outfit', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-body);
  background-color: var(--md-surface);
  color: var(--md-on-surface);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  padding-bottom: 80px; /* Leave space for floating dev console drawer */
}

/* Master Header Layout */

.app-header {
  background-color: var(--md-surface-card);
  border-bottom: 1px solid var(--md-surface-variant);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 2px 0 rgba(0,0,0,0.05);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo-container {
  width: 48px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-logo-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.brand-logo {
  display: none;
}

.brand-title {
  font-family: var(--font-title);
  font-size: 20px;
  font-weight: 600;
  color: var(--md-primary);
}

.brand-subtitle {
  font-size: 11px;
  color: var(--md-on-surface-variant);
  background-color: var(--md-surface-container);
  padding: 2px 8px;
  border-radius: 20px;
  margin-left: 6px;
  font-weight: 500;
}

/* Portal Navigation Tabs */

.portal-nav {
  display: flex;
  gap: 8px;
  background-color: var(--md-surface-container);
  padding: 4px;
  border-radius: var(--radius-xl);
}

.nav-tab {
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 20px;
  color: var(--md-on-surface-variant);
  border-radius: var(--radius-xl);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-tab:hover {
  background-color: rgba(11, 87, 208, 0.08);
  color: var(--md-primary);
}

.nav-tab.active {
  background-color: var(--md-primary-container);
  color: var(--md-on-primary-container);
  font-weight: 600;
}

/* Connection Badge */

.connection-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  background-color: #e8f0fe;
  color: #1a73e8;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  transition: background-color 0.2s;
  border: 1px solid rgba(26,115,232,0.15);
}

.connection-badge:hover {
  background-color: #d2e3fc;
}

.connection-badge.live {
  background-color: #e6f4ea;
  color: #137333;
  border-color: rgba(19,115,51,0.15);
}

.connection-badge.live::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #137333;
  animation: pulse-green 1.5s infinite;
}

.connection-badge.simulated::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #1a73e8;
  animation: pulse-blue 1.5s infinite;
}

@keyframes pulse-green {
  0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(19,115,51,0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 5px rgba(19,115,51,0); }
  100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(19,115,51,0); }
}

@keyframes pulse-blue {
  0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(26,115,232,0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 5px rgba(26,115,232,0); }
  100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(26,115,232,0); }
}

/* Base Portal Layout */

.portal-container {
  max-width: 1200px;
  margin: 32px auto;
  padding: 0 24px;
}

.portal-view {
  display: none;
  animation: fadeIn 0.25s ease-out;
}

.portal-view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Common UI Elements: Cards, Buttons, Form Inputs */

.m3-card {
  background-color: var(--md-surface-card);
  border-radius: var(--radius-l);
  border: 1px solid var(--md-surface-variant);
  padding: 24px;
  box-shadow: 0 1px 3px 0 rgba(0,0,0,0.02);
  transition: box-shadow 0.2s, border-color 0.2s;
}

.m3-card.elevated {
  box-shadow: var(--shadow-1);
}

.m3-card.elevated:hover {
  box-shadow: var(--shadow-2);
}

.m3-btn {
  background-color: var(--md-primary);
  color: var(--md-on-primary);
  border: none;
  padding: 10px 24px;
  border-radius: var(--radius-xl);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-1);
}

.m3-btn:hover {
  background-color: var(--md-primary-hover);
  box-shadow: var(--shadow-2);
}

.m3-btn:disabled {
  background-color: var(--md-outline-variant);
  color: var(--md-on-surface-variant);
  cursor: not-allowed;
  box-shadow: none;
}

.m3-btn.secondary {
  background-color: transparent;
  color: var(--md-primary);
  border: 1px solid var(--md-outline-variant);
  box-shadow: none;
}

.m3-btn.secondary:hover {
  background-color: rgba(11, 87, 208, 0.05);
  border-color: var(--md-primary);
}

.m3-btn.tonal {
  background-color: var(--md-primary-container);
  color: var(--md-on-primary-container);
  box-shadow: none;
}

.m3-btn.tonal:hover {
  background-color: #c2d7f7;
  box-shadow: var(--shadow-1);
}

.m3-input {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-s);
  border: 1px solid var(--md-outline);
  background-color: var(--md-surface-card);
  color: var(--md-on-surface);
  font-family: var(--font-body);
  font-size: 15px;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.m3-input:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 2px var(--md-primary-container);
}

.m3-input-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.m3-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--md-on-surface-variant);
}

/* Modals */

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.32);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background-color: var(--md-surface-card);
  border-radius: var(--radius-xl);
  max-width: 500px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 32px;
  box-shadow: var(--shadow-3);
  transform: scale(0.9);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-backdrop.active .modal-content {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-title {
  font-family: var(--font-title);
  font-size: 24px;
  font-weight: 600;
  color: var(--md-on-surface);
}

.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--md-on-surface-variant);
}

/* Toast Notification Overlay */

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 9999;
  max-width: 360px;
  width: 100%;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-radius: var(--radius-m);
  color: var(--md-on-surface);
  background-color: var(--md-surface-card);
  box-shadow: var(--shadow-2);
  border-left: 5px solid var(--md-primary);
  font-size: 14px;
  font-weight: 500;
  transform: translateX(120%);
  animation: slideIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes slideIn {
  to { transform: translateX(0); }
}

.toast.removing {
  animation: slideOut 0.2s cubic-bezier(0.6, -0.28, 0.735, 0.045) forwards;
}

@keyframes slideOut {
  to { transform: translateX(120%); opacity: 0; }
}

.toast.success {
  border-left-color: var(--md-success);
}

.toast.error {
  border-left-color: var(--md-error);
  background-color: var(--md-error-container);
  color: var(--md-on-error-container);
}

.toast.warning {
  border-left-color: var(--md-warning);
}

.toast.info {
  border-left-color: var(--md-primary);
}

.toast-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.toast-message {
  flex-grow: 1;
}

/* Developer Floating Console styles */

.dev-console-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: #1e1e1e;
  color: #d4d4d4;
  font-family: 'Consolas', 'Courier New', Courier, monospace;
  font-size: 12px;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.3);
  z-index: 999;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateY(calc(100% - 44px)); /* Only show header */
}

.dev-console-drawer.expanded {
  transform: translateY(0);
}

.dev-console-header {
  background-color: #2d2d2d;
  height: 44px;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid #3c3c3c;
}

.dev-console-title {
  color: #569cd6;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dev-console-body {
  height: 350px;
  display: grid;
  grid-template-columns: 280px 1fr 1fr;
  border-top: 1px solid #3c3c3c;
}

.dev-tab-sidebar {
  background-color: #252526;
  border-right: 1px solid #3c3c3c;
  display: flex;
  flex-direction: column;
  padding: 12px 0;
}

.dev-sidebar-btn {
  background: none;
  border: none;
  color: #858585;
  padding: 8px 24px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.dev-sidebar-btn:hover {
  background-color: #2a2d2e;
  color: #cccccc;
}

.dev-sidebar-btn.active {
  background-color: #37373d;
  color: #ffffff;
  border-left: 3px solid var(--md-primary);
}

.dev-content-panel {
  padding: 16px;
  overflow-y: auto;
  border-right: 1px solid #3c3c3c;
  display: flex;
  flex-direction: column;
}

.dev-content-panel h4 {
  color: #4ec9b0;
  margin-bottom: 12px;
  font-weight: 500;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.db-doc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.db-doc {
  background-color: #1e1e1e;
  border: 1px solid #3c3c3c;
  border-radius: 4px;
  padding: 8px;
  position: relative;
}

.db-doc-header {
  font-weight: bold;
  color: #ce9178;
  margin-bottom: 4px;
  font-size: 11px;
}

.db-doc-body {
  white-space: pre-wrap;
  color: #9cdcfe;
  font-size: 11px;
}

.log-stream {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.log-entry {
  background-color: #1e1e1e;
  border: 1px solid #2d2d2d;
  border-left-width: 4px;
  padding: 8px;
  border-radius: 3px;
}

.log-entry.success { border-left-color: #4ec9b0; }

.log-entry.error { border-left-color: #f48771; }

.log-entry.warning { border-left-color: #cca700; }

.log-entry.info { border-left-color: #569cd6; }

.log-meta {
  display: flex;
  justify-content: space-between;
  color: #808080;
  font-size: 10px;
  margin-bottom: 4px;
}

.log-title {
  font-weight: 600;
  color: #dcdcdc;
  margin-bottom: 2px;
}

.log-body {
  color: #b5cea8;
  font-size: 11px;
  white-space: pre-wrap;
}

/* Responsive Overrides */

@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }
  .portal-nav {
    width: 100%;
    overflow-x: auto;
  }
  .nav-tab {
    flex: 1;
    text-align: center;
    padding: 8px 12px;
    font-size: 12px;
  }
  .dev-console-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr 1fr;
  }
  .dev-tab-sidebar {
    flex-direction: row;
    overflow-x: auto;
    padding: 6px;
    border-right: none;
    border-bottom: 1px solid #3c3c3c;
  }
}

/* Typography Overrides: Global bold headings */

h1, h2, h3, h4, h5, h6,
.brand-title,
.scanner-title,
.modal-title,
.stat-title,
.chapter-mgmt-title,
.manual-entry-header,
.card-title {
  font-weight: 700 !important;
}

/* Responsive Modal Overrides */

@media (max-width: 600px) {
  .modal-content {
    padding: 20px 16px !important;
    width: 95% !important;
    max-height: 90vh !important;
  }
  .modal-title {
    font-size: 20px !important;
  }
}

