/* Variables */
:root {
  --primary-color: #4A90D9;
  --primary-hover: #357ABD;
  --success-color: #50C878;
  --warning-color: #FF9F43;
  --danger-color: #FF6B6B;
  --text-color: #333;
  --text-muted: #666;
  --border-color: #e0e0e0;
  --bg-color: #f5f7fa;
  --card-bg: #ffffff;
  --nav-bg: #1a1a2e;
  --nav-text: #ffffff;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
  --radius: 8px;
  --radius-lg: 12px;
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  min-height: 100vh;
}

/* Navbar */
.navbar {
  background: var(--nav-bg);
  color: var(--nav-text);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow);
}

.nav-brand a {
  color: var(--nav-text);
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 600;
}

.nav-links {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}

.nav-links a {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  transition: all 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--nav-text);
  background: rgba(255, 255, 255, 0.1);
}

.nav-logout {
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
}

/* Container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.card-body {
  padding: 1.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-success {
  background: var(--success-color);
  color: white;
}

.btn-success:hover {
  background: #45b868;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-color);
}

.btn-outline:hover {
  background: var(--bg-color);
}

.btn-danger {
  background: var(--danger-color);
  color: white;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

.btn-group {
  display: flex;
  gap: 0.5rem;
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.1);
}

/* Alerts */
.alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
}

.alert-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.alert-success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* Login Page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--nav-bg) 0%, #16213e 100%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 1rem;
}

.login-card {
  background: var(--card-bg);
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-card h1 {
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.login-card .form-group {
  text-align: left;
}

/* Dashboard */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: 1.75rem;
}

.search-box {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.search-box input {
  padding: 0.625rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  width: 300px;
}

/* Customer Grid */
.customer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}

.customer-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.customer-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.customer-card-image {
  height: 180px;
  background: var(--bg-color);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.customer-card-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.customer-card-image .no-diagram {
  color: var(--text-muted);
  font-style: italic;
}

.customer-card-body {
  padding: 1.25rem;
}

.customer-card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.customer-card-meta {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.customer-card-actions {
  display: flex;
  gap: 0.5rem;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 999px;
}

.badge-warning {
  background: #fef3cd;
  color: #856404;
}

.badge-info {
  background: #d1ecf1;
  color: #0c5460;
}

/* Customer Detail */
.customer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
}

.customer-info h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.customer-info .meta {
  color: var(--text-muted);
}

.diagram-viewer {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.5rem;
}

.diagram-main {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.diagram-display {
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.diagram-display img {
  max-width: 100%;
  height: auto;
}

.diagram-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.version-list {
  list-style: none;
}

.version-item {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 0.2s;
}

.version-item:hover {
  background: var(--bg-color);
}

.version-item.active {
  background: rgba(74, 144, 217, 0.1);
  border-left: 3px solid var(--primary-color);
}

.version-item-title {
  font-weight: 500;
}

.version-item-date {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.btn-delete-version {
  background: none;
  border: none;
  color: #ccc;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0 0.5rem;
  line-height: 1;
  border-radius: 4px;
}

.btn-delete-version:hover {
  background: var(--danger-color);
  color: white;
}

/* Editor */
.editor-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  height: calc(100vh - 200px);
  min-height: 500px;
}

.editor-pane,
.preview-pane {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pane-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pane-content {
  flex: 1;
  overflow: auto;
}

.editor-textarea {
  width: 100%;
  height: 100%;
  border: none;
  padding: 1rem;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.9375rem;
  line-height: 1.5;
  resize: none;
}

.editor-textarea:focus {
  outline: none;
}

.preview-content {
  padding: 1rem;
  height: 100%;
  overflow: scroll !important;
  background: #fafafa;
}

.preview-content img {
  display: block;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Zoom controls */
.zoom-controls {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.zoom-controls button {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--border-color);
  background: white;
  border-radius: 4px;
  cursor: pointer;
}

.zoom-controls button:hover {
  background: var(--bg-color);
}

.zoom-controls button.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.zoom-controls span {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0.5rem;
}

.preview-error {
  color: var(--danger-color);
  padding: 1rem;
}

.editor-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.editor-footer .form-group {
  flex: 1;
  margin: 0;
}

.editor-footer input {
  padding: 0.5rem 0.75rem;
}

/* Sessions list */
.sessions-list {
  list-style: none;
  font-size: 0.875rem;
}

.sessions-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-color);
}

.sessions-list li:last-child {
  border-bottom: none;
}

/* Unknown customers */
.unknown-table {
  width: 100%;
  border-collapse: collapse;
}

.unknown-table th,
.unknown-table td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.unknown-table th {
  font-weight: 600;
  background: var(--bg-color);
}

.unknown-table tr:hover {
  background: var(--bg-color);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

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

/* Responsive */
@media (max-width: 1024px) {
  .diagram-viewer {
    grid-template-columns: 1fr;
  }

  .editor-container {
    grid-template-columns: 1fr;
    height: auto;
  }

  .editor-pane,
  .preview-pane {
    min-height: 400px;
  }
}

@media (max-width: 768px) {
  .navbar {
    flex-direction: column;
    gap: 1rem;
  }

  .nav-links {
    width: 100%;
    justify-content: center;
  }

  .page-header {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }

  .search-box input {
    width: 100%;
  }

  .customer-grid {
    grid-template-columns: 1fr;
  }
}

/* Session Notes Section */
.session-notes-section {
  margin-top: 2rem;
}

.session-notes-section h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: var(--text-color);
}

.session-note-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.note-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.note-title {
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-date {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.note-summary {
  margin-bottom: 1rem;
}

.note-summary p {
  color: var(--text-color);
  line-height: 1.6;
}

.note-actions h4,
.note-gaps h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.action-items-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.action-items-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.action-items-list li:last-child {
  border-bottom: none;
}

.owner-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  flex-shrink: 0;
}

.owner-stephen .owner-badge {
  background: #dbeafe;
  color: #1e40af;
}

.owner-customer .owner-badge {
  background: #fef3c7;
  color: #92400e;
}

.owner-vendor .owner-badge {
  background: #e0e7ff;
  color: #4338ca;
}

.note-gaps {
  margin-top: 1rem;
  padding: 0.75rem;
  background: #fef3c7;
  border-radius: var(--radius);
}

.gaps-list {
  margin: 0.5rem 0 0 1.5rem;
  padding: 0;
}

.gaps-list li {
  padding: 0.25rem 0;
  color: #92400e;
}

/* Customer type badges for dashboard */
.customer-badges {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.type-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 500;
  border-radius: 4px;
}

.type-diagram {
  background: #d1fae5;
  color: #065f46;
}

.type-notes {
  background: #dbeafe;
  color: #1e40af;
}

.type-actions {
  background: #fef3c7;
  color: #92400e;
}

/* Nav Badge for Queue Count */
.nav-badge {
  display: inline-block;
  background: #ef4444;
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  margin-left: 0.4rem;
  min-width: 1.1rem;
  text-align: center;
  vertical-align: middle;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0.875rem 2.5rem 0.875rem 1rem;
  max-width: 350px;
  position: relative;
  pointer-events: auto;
  animation: slideIn 0.3s ease-out;
  border-left: 4px solid #6b7280;
}

.toast a {
  color: inherit;
  text-decoration: none;
  display: block;
}

.toast a:hover {
  text-decoration: underline;
}

.toast-completed {
  border-left-color: var(--success-color);
  background: #f0fdf4;
}

.toast-failed {
  border-left-color: var(--danger-color);
  background: #fef2f2;
}

.toast-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  font-size: 1.25rem;
  color: #9ca3af;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}

.toast-close:hover {
  color: #374151;
}

.toast-fade {
  animation: fadeOut 0.3s ease-out forwards;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}
