:root {
  --ink: #18201d;
  --muted: #69736f;
  --line: #dfe4e1;
  --canvas: #f5f6f4;
  --card: #ffffff;
  --green: #1f694f;
  --green-dark: #15513d;
  --green-soft: #e6f2ec;
  --amber: #9a6400;
  --amber-soft: #fff2d6;
  --red: #a23b32;
  --red-soft: #fde9e6;
  --blue: #315f8d;
  --blue-soft: #e8f0f8;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 8px 24px rgba(20, 30, 25, .04);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); color: var(--ink); }
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button, .button { cursor: pointer; }

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  gap: 26px;
  padding: 0 34px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { color: var(--ink); font-size: 20px; font-weight: 800; letter-spacing: -.02em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; align-self: stretch; gap: 22px; }
.topbar nav a { display: flex; align-items: center; color: var(--muted); font-weight: 650; border-bottom: 3px solid transparent; }
.topbar nav a.active { color: var(--green); border-bottom-color: var(--green); }
.topbar nav a:hover { text-decoration: none; color: var(--ink); }
.header-search { margin-left: auto; width: min(360px, 30vw); }
.header-search input { width: 100%; }
.link-button { border: 0; background: none; color: var(--muted); padding: 8px; }

.area-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px max(24px, calc((100vw - 1420px) / 2));
  overflow-x: auto;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.area-bar a { display: inline-flex; gap: 7px; align-items: center; white-space: nowrap; color: var(--muted); padding: 7px 11px; border-radius: 8px; font-size: 14px; font-weight: 650; }
.area-bar a:hover, .area-bar a.active { color: var(--green-dark); background: var(--green-soft); text-decoration: none; }
.area-bar a span { min-width: 20px; text-align: center; padding: 1px 5px; border-radius: 999px; background: rgba(255,255,255,.8); font-size: 12px; }

.page { width: min(1420px, calc(100% - 48px)); margin: 0 auto; padding: 34px 0 70px; }
.page-heading, .ticket-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 24px; }
.page-heading h1, .ticket-header h1 { margin: 2px 0 4px; font-size: clamp(28px, 3vw, 40px); letter-spacing: -.035em; line-height: 1.1; }
.eyebrow { margin: 0; color: var(--green); font-weight: 800; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.subtle { color: var(--muted); margin: 5px 0 0; line-height: 1.5; }
.heading-badges { display: flex; gap: 7px; margin-top: 10px; }
.heading-actions { display: flex; gap: 9px; }

.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid #cfd6d2;
  border-radius: 9px;
  color: var(--ink);
  background: #fff;
  font-weight: 700;
  text-decoration: none;
}
.button:hover { background: #f9faf9; text-decoration: none; }
.button.primary { background: var(--green); border-color: var(--green); color: #fff; }
.button.primary:hover { background: var(--green-dark); }
.button.compact { min-height: 38px; padding: 7px 13px; }
.button.full { width: 100%; margin-top: 12px; }
.text-link { padding: 9px 4px; font-weight: 650; }
.back-link { display: inline-block; margin-bottom: 18px; color: var(--muted); font-weight: 650; }

input, select, textarea {
  border: 1px solid #cbd3cf;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(31,105,79,.12); }
textarea { resize: vertical; line-height: 1.5; }
label > span { display: block; margin-bottom: 7px; font-size: 13px; color: #49544f; font-weight: 750; }

.status-tabs { display: flex; gap: 5px; margin-bottom: 14px; overflow-x: auto; }
.status-tabs a { color: var(--muted); padding: 9px 14px; border-radius: 8px; font-weight: 700; white-space: nowrap; }
.status-tabs a.active, .status-tabs a:hover { color: var(--green-dark); background: var(--green-soft); text-decoration: none; }
.filter-row { display: flex; gap: 10px; margin-bottom: 18px; align-items: center; }
.filter-row .grow { flex: 1; }
.filter-row .grow input { width: 100%; }

.list-panel, .panel, .side-card, .composer, .form-shell, .project-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.ticket-list { overflow: hidden; border-radius: inherit; }
.ticket-row {
  display: grid;
  grid-template-columns: 86px minmax(220px, 1.35fr) 120px 60px minmax(230px, 1fr) 70px;
  align-items: center;
  gap: 16px;
  min-height: 78px;
  padding: 13px 18px;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.ticket-row:last-child { border-bottom: 0; }
.ticket-row:hover { background: #fafcfb; text-decoration: none; }
.ticket-identity, .ticket-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ticket-identity strong { font-size: 13px; color: var(--muted); }
.ticket-identity small, .ticket-main small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-main strong { font-size: 16px; line-height: 1.3; }
.ticket-next { color: #4d5853; font-size: 14px; line-height: 1.4; }
.ticket-date { color: var(--muted); font-size: 13px; text-align: right; }

.badge { display: inline-flex; align-items: center; width: fit-content; white-space: nowrap; border-radius: 999px; padding: 4px 9px; background: #edf0ee; color: #4a5550; font-size: 12px; font-weight: 750; }
.badge-needs-action, .badge-waiting, .badge-p2 { background: var(--amber-soft); color: var(--amber); }
.badge-active, .badge-progress { background: var(--green-soft); color: var(--green-dark); }
.badge-p1 { background: var(--red-soft); color: var(--red); }
.badge-decision, .badge-linked-resource { background: var(--blue-soft); color: var(--blue); }
.badge-completed, .badge-archived, .badge-parked { background: #eceeed; color: #69716d; }

.project-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.project-card { padding: 20px; color: var(--ink); min-height: 210px; display: flex; flex-direction: column; }
.project-card:hover { border-color: #b6c5bd; transform: translateY(-1px); text-decoration: none; }
.project-card h2 { font-size: 21px; margin: 16px 0 8px; }
.project-card p { color: var(--muted); margin: 0 0 18px; line-height: 1.5; }
.card-top, .card-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.card-meta { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.project-heading { align-items: center; }
.project-summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.panel { padding: 20px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 10px; font-size: 18px; }
.panel p { line-height: 1.6; margin: 0; color: #46504c; }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-heading h2 { margin: 0; }
.section-heading span { color: var(--muted); font-size: 13px; }
.compact-list { border: 1px solid var(--line); }

.ticket-header { align-items: center; }
.ticket-header h1 { max-width: 900px; }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(310px, .72fr); gap: 18px; align-items: start; }
.conversation-column { min-width: 0; }
.composer { padding: 20px; margin-bottom: 24px; }
.composer > label { display: block; font-size: 18px; font-weight: 800; margin-bottom: 12px; }
.composer textarea { width: 100%; min-height: 132px; border: 1px solid #bdc8c2; font-size: 16px; }
.composer-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.timeline-heading { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 12px; }
.timeline-heading h2 { margin: 0; font-size: 20px; }
.timeline-heading span { color: var(--muted); font-size: 13px; }
.conversation { display: flex; flex-direction: column; gap: 12px; }
.message { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.message header { display: flex; align-items: center; gap: 9px; padding: 12px 16px; background: #fafbf9; border-bottom: 1px solid var(--line); }
.message header time { margin-left: auto; color: var(--muted); font-size: 12px; }
.message-body { padding: 17px 18px 20px; line-height: 1.65; white-space: normal; overflow-wrap: anywhere; }
.ticket-sidebar { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 92px; }
.side-card { padding: 18px; }
.side-card h2 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 7px; }
.side-card h2:not(:first-child) { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.side-card p { margin: 0; line-height: 1.55; }
.details-list { display: grid; gap: 0; }
.details-list div { display: grid; grid-template-columns: 90px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.details-list div:last-child { border: 0; }
.details-list span { color: var(--muted); font-size: 13px; }
.details-list strong, .details-list a { font-size: 14px; text-align: right; overflow-wrap: anywhere; }
.source-card summary, .form-details summary { cursor: pointer; font-weight: 800; }
.source-card dl { display: grid; grid-template-columns: 78px 1fr; gap: 8px; margin: 16px 0 0; }
.source-card dt { color: var(--muted); font-size: 13px; }
.source-card dd { margin: 0; overflow-wrap: anywhere; }

.form-shell { max-width: 960px; margin: 0 auto; padding: 26px; }
.form-shell.wide-form { max-width: 1100px; }
.form-shell .page-heading { margin-bottom: 22px; }
.record-form, .stacked-form { display: flex; flex-direction: column; gap: 18px; }
.record-form label input, .record-form label select, .record-form label textarea, .stacked-form input { width: 100%; }
.form-grid { display: grid; gap: 16px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
.form-grid.tight { gap: 10px; }
.form-details { border: 1px solid var(--line); border-radius: 9px; padding: 15px; }
.form-details[open] summary { margin-bottom: 16px; }
.form-details > label, .form-details > .form-grid { margin-top: 14px; }
.form-details > .form-grid:first-of-type { margin-top: 0; }
.form-actions { display: flex; gap: 10px; padding-top: 5px; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 30px 0; }
.login-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 34px; box-shadow: var(--shadow); }
.login-card h1 { margin: 14px 0 4px; font-size: 30px; }
.login-card > p { color: var(--muted); margin: 0 0 26px; }
.login-card .eyebrow { color: var(--green); margin: 18px 0 0; }
.login-card label small { display: block; color: var(--muted); margin-top: 6px; }
.login-mark { width: 48px; height: 48px; border-radius: 13px; display: grid; place-items: center; background: var(--green); color: #fff; font-weight: 900; }
.flash { border-radius: 9px; margin-bottom: 18px; padding: 13px 15px; background: var(--blue-soft); color: var(--blue); }
.flash.success { background: var(--green-soft); color: var(--green-dark); }
.flash.error { background: var(--red-soft); color: var(--red); }
.flash ul { margin: 8px 0 0; padding-left: 20px; }
.empty-state { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty-state h1, .empty-state h2 { color: var(--ink); }
.empty-state.compact { padding: 24px; }
.empty-state.standalone { background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
code { padding: 2px 5px; border-radius: 5px; background: #eef1ef; }

@media (max-width: 1050px) {
  .topbar { gap: 16px; padding: 0 20px; }
  .header-search { display: none; }
  .topbar .button { margin-left: auto; }
  .project-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ticket-row { grid-template-columns: 76px minmax(180px, 1fr) 110px 55px 70px; }
  .ticket-next { display: none; }
  .ticket-layout { grid-template-columns: minmax(0, 1fr) 320px; }
}

@media (max-width: 760px) {
  .topbar { min-height: 60px; padding: 0 14px; gap: 12px; }
  .brand { font-size: 17px; }
  .topbar nav { gap: 12px; }
  .topbar nav a { font-size: 14px; }
  .topbar .button { font-size: 0; width: 38px; padding: 0; }
  .topbar .button::after { content: '+'; font-size: 24px; font-weight: 500; }
  .area-bar { padding-left: 12px; padding-right: 12px; }
  .page { width: min(100% - 24px, 1420px); padding-top: 24px; }
  .page-heading, .ticket-header { align-items: flex-start; }
  .page-heading h1, .ticket-header h1 { font-size: 29px; }
  .page-heading > .button { display: none; }
  .filter-row { flex-wrap: wrap; }
  .filter-row label { flex: 1 1 150px; }
  .filter-row select { width: 100%; }
  .filter-row .grow { flex-basis: 100%; order: -1; }
  .ticket-row { grid-template-columns: 66px minmax(0, 1fr) auto; gap: 10px; padding: 13px; }
  .ticket-state { grid-column: 3; grid-row: 1; }
  .ticket-priority { grid-column: 1; grid-row: 2; }
  .ticket-date { grid-column: 3; grid-row: 2; }
  .ticket-next { display: block; grid-column: 2 / 4; grid-row: 2; padding-right: 70px; }
  .project-grid, .project-summary-grid, .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .project-card { min-height: 180px; }
  .ticket-layout { display: flex; flex-direction: column; }
  .conversation-column { width: 100%; }
  .ticket-sidebar { position: static; width: 100%; order: -1; }
  .composer { padding: 15px; }
  .composer-actions { justify-content: stretch; }
  .composer-actions select { flex: 1; min-width: 0; }
  .message header { flex-wrap: wrap; }
  .message header time { width: 100%; margin: 0; }
  .form-shell { padding: 18px; }
}

@media (max-width: 480px) {
  .topbar nav a:last-child { display: none; }
  .ticket-header { flex-direction: column; }
  .ticket-header .button { width: 100%; }
  .heading-actions { width: 100%; flex-direction: column; }
  .ticket-next { display: none; }
  .composer-actions { flex-direction: column; }
}
