:root {
  --ink: #17231d;
  --muted: #64736b;
  --line: #dfe7e1;
  --soft: #f5f8f5;
  --paper: #ffffff;
  --green: #245c43;
  --green-dark: #184631;
  --green-soft: #e7f2eb;
  --amber: #a85e09;
  --amber-soft: #fff3d8;
  --red: #a53c35;
  --red-soft: #fce9e7;
  --violet: #6750a4;
  --violet-soft: #f0ecff;
  --shadow: 0 10px 32px rgba(23, 35, 29, .07);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--soft); }
body { margin: 0; min-height: 100vh; }
a { color: var(--green); text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.topbar { height: 66px; background: var(--paper); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; gap: 10px; align-items: center; color: var(--ink); font-weight: 720; font-size: 17px; }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; color: white; background: linear-gradient(145deg, #2f7757, #173f2d); font-family: Georgia, serif; font-size: 25px; box-shadow: 0 8px 22px rgba(36, 92, 67, .22); }
.brand-mark-small { width: 34px; height: 34px; border-radius: 10px; font-size: 19px; box-shadow: none; }
.topbar-actions { display: flex; align-items: center; gap: 16px; font-size: 14px; }
.topbar-actions form { margin: 0; }
.preview-pill { background: var(--amber-soft); color: #814800; padding: 7px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.user-name { color: var(--muted); }
.link-button { background: none; border: 0; color: var(--green); padding: 0; }

.app-shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 66px); }
.sidebar { background: #edf3ee; border-right: 1px solid var(--line); padding: 22px 14px; position: sticky; top: 66px; height: calc(100vh - 66px); }
.nav-link { display: flex; align-items: center; gap: 12px; color: #44534b; padding: 10px 13px; margin: 3px 0; border-radius: 9px; font-size: 14px; }
.nav-link span { width: 18px; text-align: center; }
.nav-link:hover { background: rgba(255,255,255,.65); }
.nav-link.active { background: var(--paper); color: var(--green-dark); box-shadow: 0 2px 9px rgba(23,35,29,.05); font-weight: 700; }
.nav-separator { height: 1px; background: #d9e3db; margin: 15px 8px; }
.content { padding: 30px; min-width: 0; }
.page-heading { margin-bottom: 23px; }
.page-heading h1, .ticket-detail-heading h1 { margin: 2px 0 6px; letter-spacing: -.035em; font-size: 31px; line-height: 1.2; }
.heading-row, .ticket-detail-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.eyebrow { margin: 0 0 5px; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.muted { color: var(--muted); }
.page-heading > p:last-child { margin: 0; }

.button { border: 1px solid transparent; border-radius: 9px; padding: 9px 14px; font-weight: 680; font-size: 13px; transition: .15s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { opacity: .48; cursor: not-allowed; }
.button-primary { background: var(--green); color: white; }
.button-primary:hover:not(:disabled) { background: var(--green-dark); }
.button-secondary { background: white; color: var(--ink); border-color: #cfd9d1; }
.button-ai { color: #4d3788; border-color: #d8cff5; background: var(--violet-soft); }
.button-wide { width: 100%; padding: 11px; margin-top: 7px; }
.button-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.flash-stack { margin-bottom: 18px; display: grid; gap: 8px; }
.alert { border-radius: 10px; padding: 11px 14px; font-size: 13px; border: 1px solid transparent; }
.alert-error { color: #7f2a25; background: var(--red-soft); border-color: #f4cbc7; }
.alert-success { color: var(--green-dark); background: var(--green-soft); border-color: #c7dfcf; }
.alert-neutral { color: #635331; background: #fbf5e8; border-color: #eadcb9; }

.metric-strip { display: flex; gap: 9px; margin-bottom: 17px; }
.mini-metric { min-width: 120px; display: flex; gap: 8px; align-items: baseline; padding: 9px 13px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: rgba(255,255,255,.55); }
.mini-metric strong { font-size: 19px; }
.mini-metric span { color: var(--muted); font-size: 12px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 13px; }
.search-input, .toolbar select, .stack-form input, .settings-form input, .settings-form select, .draft-form input, .draft-form textarea { width: 100%; border: 1px solid #ccd7cf; border-radius: 9px; background: white; padding: 10px 12px; color: var(--ink); outline: none; }
.search-input:focus, input:focus, textarea:focus, select:focus { border-color: #6c9a81; box-shadow: 0 0 0 3px rgba(36,92,67,.1); }
.toolbar .search-input { max-width: 540px; }
.toolbar select { width: 210px; }

.ticket-table-card { border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.ticket-row { display: grid; grid-template-columns: minmax(220px, .75fr) minmax(320px, 1.7fr) 145px; gap: 20px; align-items: center; padding: 15px 17px; border-bottom: 1px solid #edf1ee; color: var(--ink); position: relative; }
.ticket-row:last-child { border-bottom: 0; }
.ticket-row:hover { background: #f8fbf8; }
.ticket-row.urgent:before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--red); }
.sender-cell { display: flex; gap: 11px; align-items: center; min-width: 0; }
.sender-cell > div, .subject-cell { min-width: 0; }
.sender-cell strong, .sender-cell small, .subject-cell strong, .subject-cell > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.sender-cell small, .owner-cell small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.avatar { flex: 0 0 auto; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green); font-weight: 800; }
.subject-cell > span { color: var(--muted); font-size: 13px; margin-top: 3px; }
.owner-cell { text-align: right; font-size: 12px; display: flex; flex-direction: column; }
.row-tags { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tag { display: inline-flex; align-items: center; border-radius: 999px; background: #edf1ee; color: #536159; padding: 4px 8px; font-size: 10px; font-weight: 750; line-height: 1; }
.tag-product, .status-auto_approved { color: var(--green-dark); background: var(--green-soft); }
.tag-demo { color: #385276; background: #e7f0fb; }
.tag-warning, .status-needs_owner, .status-needs_current_source { color: #86500d; background: var(--amber-soft); }
.tag-danger { color: #8f302a; background: var(--red-soft); }
.status-product_unresolved, .status-evidence_only { color: #4e4d78; background: #eeedfb; }
.status-blocked_for_drafting, .status-failed { color: #8f302a; background: var(--red-soft); }
.status-completed, .status-claimed, .status-running { color: var(--green-dark); background: var(--green-soft); }

.empty-state { padding: 70px 25px; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--ink); margin-bottom: 8px; }
.empty-state p { max-width: 520px; margin: 0 auto; }
.empty-icon { font-size: 32px; }

.back-link { color: var(--muted); font-size: 13px; }
.ticket-detail-heading { margin-bottom: 18px; }
.ticket-detail-heading h1 { margin-top: 8px; }
.heading-actions { padding-top: 25px; }
.assignment-pill { padding: 9px 12px; border-radius: 9px; background: #edf1ee; color: var(--muted); font-size: 12px; }
.review-banner { margin-bottom: 17px; color: #814800; background: var(--amber-soft); border: 1px solid #ecd29a; border-radius: 10px; padding: 11px 14px; font-size: 13px; }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(280px, .72fr); gap: 20px; align-items: start; }
.conversation-column { min-width: 0; display: grid; gap: 12px; }
.message-card, .composer-card, .side-card, .panel, .knowledge-card, .report-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 5px 18px rgba(23,35,29,.035); }
.message-card { padding: 17px 19px; }
.message-outbound { border-left: 3px solid #8db69e; }
.message-card header { display: flex; justify-content: space-between; gap: 15px; align-items: flex-start; border-bottom: 1px solid #eef2ef; padding-bottom: 11px; margin-bottom: 13px; }
.message-card header small { display: block; color: var(--muted); margin-top: 3px; font-size: 11px; }
.message-card time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.message-body { font-size: 14px; line-height: 1.65; word-break: break-word; }
.composer-card { padding: 18px; margin-top: 4px; }
.composer-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 13px; }
.composer-heading h2 { margin: 0; font-size: 20px; }
.draft-form { display: grid; gap: 7px; }
.draft-form label, .stack-form label, .form-field label { font-size: 12px; color: #4a5a51; font-weight: 680; }
.draft-form textarea { resize: vertical; line-height: 1.55; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-top: 5px; font-size: 12px; }

.product-panel { display: grid; gap: 12px; position: sticky; top: 82px; }
.side-card { padding: 17px; overflow: hidden; }
.side-card h2 { font-size: 18px; margin: 8px 0; }
.side-card > a { font-size: 12px; font-weight: 650; }
.product-image { display: block; width: 155px; height: 155px; object-fit: contain; margin: 4px auto 10px; }
.label-image { display: block; width: 100%; max-height: 310px; object-fit: contain; border: 1px solid #edf1ee; border-radius: 9px; margin: 8px 0 11px; }
.product-identifiers { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; padding: 10px 0; border-top: 1px solid #edf1ee; border-bottom: 1px solid #edf1ee; margin: 10px 0; font-size: 12px; }
.product-identifiers span { color: var(--muted); }
details { border-top: 1px solid #edf1ee; padding: 10px 0 0; margin-top: 10px; }
summary { cursor: pointer; font-weight: 700; font-size: 12px; }
details p { color: #48564e; font-size: 12px; line-height: 1.55; }

.knowledge-metrics { flex-wrap: wrap; }
.knowledge-list { display: grid; gap: 10px; }
.knowledge-card { padding: 17px 19px; }
.knowledge-card-head { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.knowledge-card-head > div { display: flex; gap: 6px; flex-wrap: wrap; }
.knowledge-card h2 { font-size: 16px; margin: 12px 0 6px; }
.knowledge-card p { margin: 0; color: #45534b; font-size: 13px; line-height: 1.55; }
.confidence { color: var(--muted); font-size: 11px; }
.review-note { display: block; color: var(--amber); margin-top: 9px; }
.conflict-card { display: grid; gap: 12px; }
.conflict-options { display: grid; gap: 10px; }
.conflict-option { display: grid; grid-template-columns: auto 1fr; gap: 11px; padding: 13px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft); cursor: pointer; }
.conflict-option input { margin-top: 4px; }
.conflict-option span { display: grid; gap: 5px; }
.conflict-option small { color: var(--muted); line-height: 1.4; }

.report-grid { display: grid; grid-template-columns: repeat(3, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.report-card { padding: 18px; display: flex; flex-direction: column; gap: 9px; }
.report-card span { color: var(--muted); font-size: 12px; }
.report-card strong { font-size: 28px; }
.two-column-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.panel { padding: 20px; margin-bottom: 15px; }
.panel h2 { margin: 0 0 14px; font-size: 18px; }
.bar-row, .sync-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; border-top: 1px solid #edf1ee; padding: 10px 0; font-size: 13px; }
.bar-row:first-of-type { border-top: 0; }

.integration-status-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 10px; margin-bottom: 15px; }
.status-card { background: var(--paper); border: 1px solid var(--line); border-radius: 11px; padding: 14px; display: flex; align-items: center; gap: 11px; }
.status-card div { display: flex; flex-direction: column; gap: 3px; }
.status-card small { color: var(--muted); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #cbd4ce; box-shadow: 0 0 0 4px #edf1ee; }
.status-dot.ok { background: #2b8a5b; box-shadow: 0 0 0 4px #e0f3e8; }
.status-dot.warn { background: #d89027; box-shadow: 0 0 0 4px #fff1d5; }
.settings-form section { padding-bottom: 19px; margin-bottom: 19px; border-bottom: 1px solid #edf1ee; }
.settings-form section:last-of-type { border-bottom: 0; }
.narrow-form { max-width: 560px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.form-field small { color: var(--muted); font-size: 11px; }
.form-field ul.errorlist { color: var(--red); margin: 0; padding-left: 17px; font-size: 11px; }
.checkbox-field { flex-direction: row; align-items: flex-start; flex-wrap: wrap; padding: 10px; border-radius: 9px; background: var(--soft); }
.checkbox-field input { width: auto; margin-top: 2px; }
.checkbox-field label { order: 1; flex: 1; }
.checkbox-field input { order: 0; }
.checkbox-field small { order: 2; width: 100%; margin-left: 23px; }
.action-panel { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.action-panel h2, .action-panel p { margin-bottom: 4px; }
.sync-row > span:first-child { display: flex; flex-direction: column; }
.sync-row small { color: var(--muted); margin-top: 2px; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 20% 10%, #e3f0e7, transparent 36%), var(--soft); }
.login-card { width: min(420px, 100%); padding: 38px; background: white; border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); }
.login-card .brand-mark { margin-bottom: 20px; }
.login-card h1 { font-size: 28px; margin: 3px 0 7px; }
.login-card > .muted { margin: 0 0 23px; }
.stack-form { display: grid; gap: 8px; }
.stack-form input { margin-bottom: 8px; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 74px minmax(0, 1fr); }
  .sidebar { padding: 20px 9px; }
  .nav-link { justify-content: center; padding: 12px; font-size: 0; }
  .nav-link span { font-size: 16px; }
  .ticket-layout { grid-template-columns: minmax(0, 1fr) 300px; }
  .ticket-row { grid-template-columns: 210px 1fr 120px; }
}

@media (max-width: 800px) {
  .topbar { padding: 0 14px; }
  .user-name { display: none; }
  .app-shell { display: block; }
  .sidebar { height: auto; position: static; display: flex; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 7px; }
  .nav-link { flex: 0 0 auto; font-size: 12px; padding: 9px 11px; }
  .nav-link span { font-size: 12px; }
  .nav-separator { width: 1px; height: 28px; margin: 2px 5px; }
  .content { padding: 18px 13px; }
  .ticket-row { grid-template-columns: 1fr; gap: 9px; }
  .owner-cell { text-align: left; flex-direction: row; justify-content: space-between; }
  .ticket-layout { grid-template-columns: 1fr; }
  .product-panel { position: static; }
  .report-grid, .integration-status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-column-cards, .form-grid { grid-template-columns: 1fr; }
  .action-panel, .composer-footer, .heading-row, .ticket-detail-heading { align-items: stretch; flex-direction: column; }
  .heading-actions { padding-top: 0; }
}

@media (max-width: 520px) {
  .brand > span:last-child, .preview-pill { display: none; }
  .page-heading h1, .ticket-detail-heading h1 { font-size: 25px; }
  .metric-strip { overflow-x: auto; }
  .mini-metric { min-width: 105px; }
  .report-grid, .integration-status-grid { grid-template-columns: 1fr; }
  .toolbar { flex-wrap: wrap; }
  .toolbar .search-input, .toolbar select { max-width: none; width: 100%; }
  .composer-heading { align-items: flex-start; flex-direction: column; }
  .button-group { width: 100%; }
  .button-group .button { flex: 1; }
}
