/* Modern Reset & Base Setup */
:root {
  --font-brand: 'Outfit', sans-serif;
  --font-body: 'Inter', sans-serif;
  
  /* Color Palette (Dynamic variables based on Active Tenant) */
  --color-primary: #0284c7; /* Fallback to norte_piscinas sky blue */
  --color-primary-glow: rgba(2, 132, 199, 0.2);
  --color-accent: #f59e0b; /* Amber */
  --color-success: #10b981; /* Emerald green */
  --color-danger: #ef4444;
  
  /* Dark Sleek Base Theme */
  --bg-app: radial-gradient(circle at top left, #0d1527, #070a13);
  --bg-panel: rgba(17, 24, 39, 0.7);
  --bg-panel-hover: rgba(26, 36, 57, 0.75);
  --border-glow: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(2, 132, 199, 0.5);
  
  /* Typography Scale */
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dark: #0f172a;
}

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

body {
  background: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Scrollbars */
.scrollable::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.scrollable::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
}
.scrollable::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}
.scrollable::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.24);
}

/* App Container Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header Topbar Styling */
.topbar {
  align-items: center;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-glow);
  display: flex;
  height: 70px;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
}

.logo-orb {
  background: linear-gradient(135deg, var(--color-primary), #38bdf8);
  border-radius: 50%;
  box-shadow: 0 0 16px var(--color-primary-glow);
  height: 32px;
  width: 32px;
  animation: pulse 4s infinite alternate;
}

@keyframes pulse {
  0% { box-shadow: 0 0 8px var(--color-primary-glow); }
  100% { box-shadow: 0 0 20px rgba(56, 189, 248, 0.5); }
}

.brand h1 {
  font-family: var(--font-brand);
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tenant-name {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.top-actions {
  display: flex;
  gap: 12px;
}

/* Buttons System */
.btn {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  font-family: var(--font-brand);
  font-size: 0.9rem;
  font-weight: 600;
  gap: 8px;
  justify-content: center;
  padding: 8px 16px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), #0284c7);
  color: white;
  box-shadow: 0 4px 12px var(--color-primary-glow);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(2, 132, 199, 0.4);
}

.btn-secondary {
  background: linear-gradient(135deg, #4f46e5, #4338ca);
  color: white;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}
.btn-secondary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

.btn-success {
  background: linear-gradient(135deg, var(--color-success), #059669);
  color: white;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}
.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.btn-muted {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}
.btn-muted:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-text {
  background: none;
  border: none;
  color: var(--color-primary);
  cursor: pointer;
  font-weight: 600;
  transition: opacity 0.2s;
}
.btn-text:hover {
  opacity: 0.8;
}

.btn:active {
  transform: translateY(0);
}

.indicator-dot {
  border-radius: 50%;
  display: inline-block;
  height: 8px;
  width: 8px;
}
.indicator-dot.green {
  background: var(--color-success);
  box-shadow: 0 0 8px var(--color-success);
}

/* Badges styling */
.badge {
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 6px;
  text-transform: uppercase;
}
.badge-accent {
  background: rgba(245, 158, 11, 0.15);
  color: var(--color-accent);
}
.badge-neutral {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}
.badge-success {
  background: rgba(16, 185, 129, 0.15);
  color: var(--color-success);
}

.count-badge {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
}

/* Core Main Grid Layout */
.workspace {
  display: grid;
  flex: 1;
  grid-template-columns: 320px 1fr 460px;
  overflow: hidden;
}

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

.section-header h2 {
  font-family: var(--font-brand);
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

/* Left Sidebar Column */
.workspace-sidebar {
  background: rgba(10, 15, 26, 0.4);
  border-right: 1px solid var(--border-glow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 16px;
}

.sidebar-section.border-top {
  border-top: 1px solid var(--border-glow);
}

.list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding-right: 4px;
}

/* Sidebar List Cards */
.list-item-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-glow);
  border-radius: 8px;
  cursor: pointer;
  padding: 12px;
  transition: all 0.2s ease;
}
.list-item-card:hover {
  background: var(--bg-panel-hover);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateX(2px);
}
.list-item-card.active {
  background: rgba(2, 132, 199, 0.12);
  border-color: var(--color-primary);
  box-shadow: 0 0 12px rgba(2, 132, 199, 0.15);
}

.list-item-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.list-item-title {
  font-family: var(--font-brand);
  font-size: 0.95rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-meta {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.list-item-preview {
  color: var(--text-muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-footer {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
}

/* Middle Column Layout */
.workspace-detail {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px;
  position: relative;
}

.detail-wrapper {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Universal Cards Grid */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--border-glow);
  border-radius: 12px;
  overflow: hidden;
}

.card-header {
  align-items: center;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-glow);
  display: flex;
  justify-content: space-between;
  padding: 16px 20px;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-info h3 {
  font-family: var(--font-brand);
  font-size: 1.1rem;
  font-weight: 700;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.chat-timestamp {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Chat Messages Bubble Layout */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 280px;
  overflow-y: auto;
  padding: 20px;
}

.chat-bubble {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px 16px 16px 16px;
  max-width: 80%;
  padding: 12px 16px;
  align-self: flex-start;
  white-space: pre-wrap;
}

.chat-bubble.outbound {
  background: var(--color-primary);
  color: white;
  border-radius: 16px 16px 8px 16px;
  align-self: flex-end;
}

/* AI Extraction details */
.card-body {
  padding: 20px;
}

.grid-2col {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, 1fr);
}

.info-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-block strong {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.spacing-top {
  margin-top: 16px;
}

.measurements-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
}

.measure-pill {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glow);
  border-radius: 8px;
  padding: 8px 12px;
  text-align: center;
}

.measure-pill .val {
  display: block;
  font-family: var(--font-brand);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-primary);
}

.measure-pill .lbl {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.missing-tag {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 4px;
  color: #f87171;
  font-size: 0.8rem;
  padding: 4px 10px;
}

.confidence-gauge {
  text-align: right;
}
.confidence-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.confidence-value {
  font-family: var(--font-brand);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-success);
}

.card-footer {
  background: rgba(255, 255, 255, 0.01);
  border-top: 1px solid var(--border-glow);
  padding: 16px 20px;
  text-align: right;
}

/* Right Column Quote Editor */
.workspace-editor {
  background: rgba(15, 23, 42, 0.4);
  border-left: 1px solid var(--border-glow);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px;
}

.editor-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}

.editor-header h2 {
  font-family: var(--font-brand);
  font-size: 1.1rem;
  font-weight: 700;
}

.quote-id-badge {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.8rem;
  padding: 4px 8px;
}

.editor-section {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-glow);
  border-radius: 10px;
  margin-bottom: 20px;
  padding: 16px;
}

.section-title {
  font-family: var(--font-brand);
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

/* Inputs & Form Controls */
.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, 1fr);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group.full-width {
  grid-column: span 2;
}

label {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}

input,
textarea,
select {
  background: rgba(10, 15, 26, 0.6);
  border: 1px solid var(--border-glow);
  border-radius: 6px;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 0.9rem;
  outline: none;
  padding: 8px 12px;
  transition: all 0.2s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 6px var(--color-primary-glow);
}

/* Line Item Editor Styles */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-editor-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glow);
  border-radius: 8px;
  padding: 12px;
  position: relative;
}

.item-editor-card .remove-btn {
  color: var(--color-danger);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  position: absolute;
  right: 12px;
  top: 12px;
  transition: opacity 0.2s;
}
.item-editor-card .remove-btn:hover {
  opacity: 0.7;
}

.item-editor-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.item-editor-grid .full-col {
  grid-column: span 2;
}

/* Autocomplete Suggestion Wrapper */
.autocomplete-wrapper {
  position: relative;
}

.autocomplete-dropdown {
  background: #111827;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  left: 0;
  max-height: 200px;
  overflow-y: auto;
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 100;
  margin-top: 4px;
}

.autocomplete-item {
  cursor: pointer;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.autocomplete-item:hover {
  background: rgba(2, 132, 199, 0.2);
}
.autocomplete-item strong {
  display: block;
  font-size: 0.85rem;
  color: var(--text-main);
}
.autocomplete-item span {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.autocomplete-item .price {
  font-weight: 700;
  color: var(--color-accent);
}

.warnings-box {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.2);
  border-radius: 6px;
  color: #fbbf24;
  font-size: 0.8rem;
  margin-bottom: 12px;
  padding: 10px;
}

/* Pricing Summary Styling */
.pricing-summary-card {
  background: linear-gradient(135deg, rgba(2, 132, 199, 0.1), rgba(15, 23, 42, 0.4));
  border: 1px solid var(--border-focus);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.summary-row.total-highlight {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 0;
  margin-top: 12px;
  padding-top: 12px;
  font-size: 1.15rem;
}
.summary-row.total-highlight strong {
  color: var(--text-main);
  text-shadow: 0 0 10px var(--color-primary-glow);
}

/* Action Center Controls */
.action-center {
  display: flex;
  flex-direction: column;
}

.btn-group-row {
  display: flex;
  gap: 12px;
}

.btn-group-row .btn {
  flex: 1;
}

.action-status-box {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  color: var(--text-muted);
  font-family: monospace;
  font-size: 0.8rem;
  margin-top: 12px;
  min-height: 48px;
  overflow-y: auto;
  padding: 8px 12px;
  white-space: pre-wrap;
}

/* Empty State / Standby view */
.empty-state-card {
  align-items: center;
  border: 2px dashed rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  padding: 40px;
  text-align: center;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-card h3 {
  font-family: var(--font-brand);
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state-card p {
  color: var(--text-muted);
  max-width: 320px;
}

/* Modal Backdrops & Overlays */
.modal-backdrop {
  align-items: center;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  height: 100%;
  justify-content: center;
  left: 0;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 200;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.modal-content {
  background: #0f172a;
  border: 1px solid var(--border-glow);
  border-radius: 12px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  max-width: 500px;
  width: 90%;
  overflow: hidden;
  transform: translateY(0);
  transition: transform 0.25s ease;
}

.modal-header {
  align-items: center;
  border-bottom: 1px solid var(--border-glow);
  display: flex;
  justify-content: space-between;
  padding: 16px 20px;
}

.modal-header h3 {
  font-family: var(--font-brand);
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.5rem;
}
.btn-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 20px;
}

.modal-instruction {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.modal-body textarea {
  min-height: 160px;
  resize: vertical;
  width: 100%;
}

.modal-footer {
  background: rgba(255, 255, 255, 0.01);
  border-top: 1px solid var(--border-glow);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 16px 20px;
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Loading animations */
.loading-indicator {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  border-top-color: var(--color-primary);
  animation: spin 1s ease-in-out infinite;
}

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

.loading-state {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 24px 0;
  text-align: center;
}

/* Responsive Overrides */
@media (max-width: 1200px) {
  .workspace {
    grid-template-columns: 280px 1fr;
  }
  .workspace-editor {
    grid-column: span 2;
    border-left: none;
    border-top: 1px solid var(--border-glow);
  }
}

@media (max-width: 768px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .workspace-sidebar {
    height: 300px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .form-group.full-width {
    grid-column: span 1;
  }
}
