:root {
  --bg: #1a1c1e;
  --bg-panel: #232628;
  --bg-elevated: #2c3033;
  --ink: #e8ebe6;
  --muted: #9aa39a;
  --line: #3a403c;
  --accent: #c4a35a;
  --accent-dark: #8a763f;
  --accent-ink: #1a1c1e;
  --ok: #6f9f7a;
  --ok-dark: #4a6b52;
  --warn: #c48a4a;
  --err: #c45a5a;
  --tag-prompt: #4a6f8a;
  --tag-plex: #6a7a4a;
  --tag-edit: #8a6a4a;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #2a3228 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #2a2830 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(26, 28, 30, 0.85);
  backdrop-filter: blur(8px);
}

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

.brand-mark {
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}

.brand h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.subtitle {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-links {
  display: flex;
  gap: 0.35rem;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid transparent;
}

.nav-link:hover {
  color: var(--ink);
  border-color: var(--line);
}

.nav-link.active {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}

.status {
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--mono);
}
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(420px, 1.35fr);
  gap: 0;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-panel) 92%, transparent);
}

.panel.right { border-right: none; }

.customer {
  margin: 0.75rem 1rem 0;
  border: 1px solid var(--line);
  background: var(--bg-elevated);
}

.customer summary {
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  user-select: none;
}

.customer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  padding: 0 0.75rem 0.75rem;
}

.customer-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.customer-grid label:first-child,
.customer-grid label:nth-child(2) {
  grid-column: 1 / -1;
}

input, textarea, select, button {
  font: inherit;
  color: var(--ink);
}

input, textarea, select {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 0.4rem 0.5rem;
  border-radius: 0;
}

input:focus, textarea:focus, select:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

.chat {
  flex: 1;
  overflow: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.bubble {
  max-width: 92%;
  padding: 0.65rem 0.8rem;
  line-height: 1.45;
  font-size: 0.92rem;
  white-space: pre-wrap;
}

.bubble.thinking {
  opacity: 0.55;
  font-style: italic;
  border-left-color: var(--line);
}

.bubble.user {
  align-self: flex-end;
  background: #2f3840;
  border-left: 3px solid var(--accent);
}

.bubble.user.llm {
  border-left-color: var(--accent-dark);
  background: #33291a;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bg-elevated);
  border-left: 3px solid var(--ok);
}

.bubble.assistant.llm {
  border-left-color: var(--ok-dark);
  background: #1d2b21;
}

.composer {
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--line);
}

.composer textarea {
  resize: vertical;
  min-height: 4.5rem;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
}

.composer-actions .primary {
  flex: 1;
  max-width: 12rem;
}

.mic-btn {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mic-btn svg {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.mic-btn .icon-stop {
  display: none;
}

.mic-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.mic-btn.recording {
  background: var(--err);
  border-color: var(--err);
  color: #fff;
  box-shadow: 0 0 0 0 rgba(196, 90, 90, 0.45);
  animation: mic-pulse 1.2s ease-out infinite;
}

.mic-btn.recording .icon-mic {
  display: none;
}

.mic-btn.recording .icon-stop {
  display: block;
}

@keyframes mic-pulse {
  0% { box-shadow: 0 0 0 0 rgba(196, 90, 90, 0.45); }
  70% { box-shadow: 0 0 0 10px rgba(196, 90, 90, 0); }
  100% { box-shadow: 0 0 0 0 rgba(196, 90, 90, 0); }
}

button {
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  padding: 0.45rem 0.85rem;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

button.ghost {
  background: transparent;
}

a.download {
  color: var(--accent);
  font-size: 0.85rem;
  font-family: var(--mono);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
}

.panel-header h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.deal-badge {
  font-size: 0.78rem;
  color: var(--muted);
  border: 1px dashed var(--warn);
  padding: 0.25rem 0.5rem;
  font-family: var(--mono);
}

.deal-badge em { font-style: normal; color: var(--warn); }

.ai-offline-banner {
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--err);
  background: rgba(196, 90, 90, 0.15);
  color: #f0c0c0;
  font-size: 0.85rem;
  line-height: 1.35;
}

.empty {
  padding: 2rem 1.25rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

#worksheet-wrap {
  overflow: auto;
  padding: 0.75rem 1rem 1.25rem;
}

table.ws {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

table.ws th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.4rem 0.35rem;
  border-bottom: 1px solid var(--line);
}

table.ws td {
  padding: 0.3rem 0.25rem;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  vertical-align: middle;
}

table.ws input, table.ws select {
  width: 100%;
  min-width: 0;
  padding: 0.28rem 0.3rem;
  font-size: 0.82rem;
  font-family: var(--mono);
}

table.ws td.num input { text-align: right; }

table.ws tfoot td {
  border-bottom: none;
  padding-top: 0.65rem;
  font-family: var(--mono);
  font-weight: 500;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--ink);
  opacity: 0.9;
  white-space: nowrap;
}

.tag.prompt { color: #9ec0d8; }
.tag.plex { color: #b6c98a; }
.tag.edit { color: #d4b48a; }
.tag.nodata { color: var(--err); }

.suggestion-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.suggestion-section-label {
  font-size: 0.72rem;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink);
  opacity: 0.65;
  margin-bottom: 6px;
}

.suggestion-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.suggestion-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
}

.suggestion-check input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent, #c9a227);
  cursor: pointer;
}

.suggestion-block.readonly .suggestion-check {
  opacity: 0.55;
  cursor: default;
}

.suggestion-empty {
  font-size: 0.78rem;
  opacity: 0.6;
  font-style: italic;
}

.suggestion-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

button.suggestion-use {
  font-size: 0.85rem;
  padding: 0.35rem 0.85rem;
}

button.suggestion-type {
  font-size: 0.85rem;
}

.hour-form {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.hour-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
  margin-bottom: 10px;
}

.hour-form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
}

.hour-form-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.7;
}

.hour-form-input {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--ink);
}

.hour-form.readonly .hour-form-input {
  opacity: 0.6;
}

button.hour-form-submit {
  font-size: 0.85rem;
  padding: 0.35rem 0.85rem;
}

.parts-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.parts-row label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.parts-row input {
  width: 7rem;
  font-family: var(--mono);
}

.totals-line {
  margin-left: auto;
  font-size: 1rem;
  font-family: var(--mono);
}

.btn-del {
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  color: var(--err);
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .panel.left {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 55vh;
  }
}

/* Historical review page */
.historical-layout {
  grid-template-columns: minmax(240px, 0.85fr) minmax(420px, 1.6fr) minmax(280px, 1fr);
}

.historical-layout .panel.center {
  border-right: 1px solid var(--line);
}

.quote-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  overflow: auto;
  flex: 1;
}

.quote-item {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 0.15rem;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.35rem;
  border: 1px solid var(--line);
  background: var(--bg-elevated);
}

.quote-item:hover,
.quote-item.active {
  border-color: var(--accent);
}

.quote-item-title {
  font-size: 0.88rem;
  font-weight: 600;
}

.quote-item-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.badge {
  justify-self: start;
  font-size: 0.68rem;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.35rem;
  border: 1px solid var(--line);
  margin-top: 0.2rem;
}

.badge.pending { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.badge.reviewed { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }

.filter-tabs {
  display: flex;
  gap: 0.25rem;
}

.filter-btn {
  font-size: 0.72rem;
  padding: 0.25rem 0.45rem;
}

.filter-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.editor-title-wrap h2 {
  margin: 0;
}

.save-meta {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  font-family: var(--mono);
  line-height: 1.35;
}

.editor-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.editor-form {
  overflow: auto;
  padding: 0.75rem 1rem 1.5rem;
}

.editor-form.hidden,
.hidden {
  display: none !important;
}

.form-section {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
}

.form-section h3 {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.55rem;
}

.field-grid label,
.num-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.field-grid label span,
.num-field span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.field-grid.nums input {
  font-family: var(--mono);
  text-align: right;
}

.full-width textarea {
  width: 100%;
  min-height: 5rem;
}

.line-item-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

table.ws tr.row-empty td:first-child input {
  color: color-mix(in srgb, var(--ink) 72%, var(--muted));
}

.source-header-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.source-view-tabs {
  display: flex;
  gap: 0.25rem;
}

.source-tab {
  font-size: 0.72rem;
  padding: 0.25rem 0.45rem;
}

.source-tab.active {
  border-color: var(--accent);
  color: var(--accent);
}

.source-pdf {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: none;
  background: #fff;
}

.panel.right {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel.right .empty {
  padding: 1rem;
}

.worksheet-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.worksheet-wrap .editor-form {
  flex: 1;
}

.parts-source-line {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
}

.source-grid {
  margin: 0;
  padding: 0.75rem 1rem 1rem;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.35;
  white-space: pre-wrap;
  color: color-mix(in srgb, var(--ink) 88%, var(--muted));
  background: transparent;
  border: none;
}

@media (max-width: 1100px) {
  .historical-layout {
    grid-template-columns: 1fr;
  }
  .historical-layout .panel.center {
    border-right: none;
  }
}
