:root {
  color-scheme: light;
  --paper: #fff8e8;
  --paper-raised: #fffdf5;
  --panel: #ffedbd;
  --panel-soft: #fff5d8;
  --ink: #291f23;
  --muted: #5c4d4a;
  --line: #9b8868;
  --line-soft: #d6c7a4;
  --deep-ocean: #1c576f;
  --ocean: #338ca6;
  --shallow: #61b3b3;
  --leaf: #2f7847;
  --leaf-soft: #def1d4;
  --berry: #ad1738;
  --amber: #a86900;
  --amber-soft: #fff0bd;
  --blue-soft: #deeff7;
  --shadow: #785042;
  --border: 2px;
  --radius: 6px;
  --font-ui: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, sans-serif;
  --font-display: "Avenir Next", ui-rounded, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(41, 31, 35, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(41, 31, 35, 0.012) 1px, transparent 1px),
    var(--paper);
  background-size: 4px 4px;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
}

button, input, textarea { font: inherit; color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

button:focus-visible, a:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 3px solid var(--shallow);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  min-height: 86px;
  padding: 14px clamp(18px, 3vw, 42px);
  border-bottom: var(--border) solid var(--line);
  background: rgba(255, 253, 245, 0.94);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand__mark, .team-mark { image-rendering: pixelated; object-fit: contain; }
.brand__mark { width: 54px; height: 54px; }
.brand__name {
  font-family: var(--font-display);
  color: var(--deep-ocean);
  font-size: clamp(21px, 2vw, 29px);
  font-weight: 800;
  letter-spacing: -0.025em;
  white-space: nowrap;
}
.brand__divider { width: 1px; height: 36px; background: var(--line-soft); }
.brand__section { font-size: 20px; font-weight: 650; white-space: nowrap; }

.header-actions, .list-toolbar, .dialog-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.button, .scope-tabs button, .icon-button {
  border: var(--border) solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-raised);
  cursor: pointer;
  font-weight: 700;
}

.button {
  min-height: 46px;
  padding: 0 18px;
  box-shadow: 3px 3px 0 rgba(120, 80, 66, 0.28);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  white-space: nowrap;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translate(2px, 2px); box-shadow: none; }
.button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.button--primary { color: white; background: #075b61; border-color: var(--ink); }
.button--quiet { color: var(--ink); background: var(--paper-raised); }

.board-shell {
  width: min(1520px, 100%);
  min-height: calc(100vh - 146px);
  margin: 0 auto;
  padding: clamp(22px, 3vw, 40px);
  display: grid;
  grid-template-columns: minmax(620px, 1.55fr) minmax(410px, 0.95fr);
  gap: clamp(24px, 2.5vw, 38px);
  align-items: stretch;
}

.ticket-region { min-width: 0; display: flex; flex-direction: column; }

.scope-tabs {
  display: flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}
.scope-tabs button {
  min-width: 150px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 4px;
  box-shadow: none;
  background: transparent;
  font-size: 14px;
}
.scope-tabs button[aria-selected="true"] { color: var(--deep-ocean); background: var(--paper-raised); box-shadow: 1px 1px 0 rgba(120, 80, 66, 0.2); }

.list-toolbar { justify-content: space-between; padding: 0 6px 14px; }

.ticket-frame, .ticket-detail {
  border: var(--border) solid var(--ink);
  border-radius: var(--radius);
  background: rgba(255, 253, 245, 0.82);
  box-shadow: 4px 4px 0 rgba(120, 80, 66, 0.2);
}
.ticket-frame { min-height: 0; overflow: hidden; display: flex; flex: 1; flex-direction: column; }
.ticket-head, .ticket-row {
  display: grid;
  grid-template-columns: minmax(245px, 1.8fr) minmax(145px, 1fr) minmax(130px, 0.9fr) minmax(155px, 1fr) minmax(100px, 0.7fr);
  align-items: center;
}
.ticket-head {
  min-height: 48px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
  font-size: 13px;
  font-weight: 750;
}
.ticket-head span { height: 100%; padding: 14px 16px; border-right: 1px solid var(--line-soft); }
.ticket-head span:last-child { border-right: 0; text-align: center; }
.ticket-list { flex: 1; }
.ticket-row {
  position: relative;
  width: 100%;
  min-height: 80px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}
.ticket-row:hover { background: rgba(97, 179, 179, 0.09); }
.ticket-row.is-selected {
  background: #edf9f5;
  box-shadow: inset 0 0 0 2px var(--deep-ocean);
}
.ticket-cell { min-width: 0; padding: 15px 16px; }
.ticket-title { position: relative; padding-left: 32px; font-size: 15px; font-weight: 800; }
.unread-dot {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 10px;
  height: 10px;
  border: 1px solid #6f1026;
  border-radius: 50%;
  background: var(--berry);
  transform: translateY(-50%);
}
.reporter { display: flex; align-items: center; gap: 8px; }
.avatar-chip {
  width: 28px;
  height: 28px;
  border: 1px solid var(--deep-ocean);
  border-radius: 4px;
  background: var(--panel);
  display: inline-grid;
  place-items: center;
  color: var(--deep-ocean);
  font-size: 12px;
  font-weight: 900;
}
.build-label, .status-label {
  width: fit-content;
  max-width: 100%;
  min-height: 30px;
  padding: 4px 9px;
  border: 1px solid currentColor;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
}
.build-label { color: var(--leaf); background: var(--leaf-soft); }
.status--arrived, .status--review { color: var(--amber); background: var(--amber-soft); }
.status--planned, .status--changed { color: var(--leaf); background: var(--leaf-soft); }
.status--duplicate { color: var(--deep-ocean); background: var(--blue-soft); }
.status--stays { color: var(--muted); background: #eeeae1; }
.ticket-footer { min-height: 48px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; }

.ticket-detail { min-width: 0; padding: clamp(22px, 2.4vw, 34px); }
.detail-back { display: none; padding: 0; border: 0; background: transparent; color: var(--deep-ocean); cursor: pointer; font-weight: 800; }
.detail-empty { min-height: 480px; display: grid; place-content: center; justify-items: center; color: var(--muted); text-align: center; }
.detail-empty img { image-rendering: pixelated; opacity: 0.72; }
.detail-empty h2 { margin: 16px 0 4px; color: var(--deep-ocean); }
.detail-empty p { margin: 0; }
.detail-title { display: flex; gap: 16px; align-items: flex-start; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.status-square { flex: 0 0 52px; height: 52px; border: var(--border) solid var(--leaf); border-radius: var(--radius); background: var(--leaf-soft); display: grid; place-items: center; color: var(--leaf); font-size: 28px; font-weight: 900; }
.detail-title h2 { margin: 0; color: var(--deep-ocean); font-family: var(--font-display); font-size: clamp(21px, 2vw, 28px); line-height: 1.2; }
.detail-meta { padding: 18px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.meta-item { min-width: 0; }
.meta-label { margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }
.meta-value { font-weight: 700; overflow-wrap: anywhere; }
.detail-copy { margin: 0; padding: 22px 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.response-section { padding-top: 24px; }
.response-section h3 { margin: 0 0 18px; color: var(--deep-ocean); font-size: 17px; }
.timeline { position: relative; display: grid; gap: 18px; }
.timeline::before { content: ""; position: absolute; left: 26px; top: 24px; bottom: 24px; width: 2px; background: var(--deep-ocean); }
.timeline-item { position: relative; display: grid; grid-template-columns: 54px 1fr; gap: 18px; align-items: start; }
.team-mark { position: relative; z-index: 1; width: 54px; height: 54px; padding: 5px; border: var(--border) solid var(--deep-ocean); border-radius: var(--radius); background: var(--paper-raised); }
.response-card { position: relative; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper-raised); box-shadow: 3px 3px 0 rgba(120, 80, 66, 0.18); }
.response-card::before { content: ""; position: absolute; left: -8px; top: 18px; width: 14px; height: 14px; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--paper-raised); transform: rotate(45deg); }
.response-author { display: flex; align-items: center; gap: 8px; color: var(--deep-ocean); font-weight: 850; }
.team-label { padding: 1px 5px; border: 1px solid var(--ocean); border-radius: 3px; background: #e7f7f7; font-size: 10px; }
.response-card p { margin: 10px 0 7px; }
.response-time { color: var(--muted); font-size: 12px; }
.resolution-note { margin-top: 20px; padding: 14px 16px; border: 1px solid var(--deep-ocean); border-radius: var(--radius); background: #eef8f7; color: var(--deep-ocean); font-weight: 750; }

.feedback-dialog { width: min(560px, calc(100% - 28px)); padding: 0; border: var(--border) solid var(--ink); border-radius: var(--radius); background: var(--paper); box-shadow: 7px 7px 0 rgba(41, 31, 35, 0.28); }
.feedback-dialog::backdrop { background: rgba(28, 55, 62, 0.42); }
.feedback-dialog form { padding: 24px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.dialog-heading h2 { margin: 0; color: var(--deep-ocean); font-size: 24px; }
.dialog-heading p { margin: 6px 0 20px; color: var(--muted); }
.icon-button { width: 40px; height: 40px; padding: 8px; display: grid; place-items: center; }
.icon-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.field { display: grid; gap: 7px; margin-top: 16px; font-size: 13px; font-weight: 800; }
.field textarea, .field input { width: 100%; border: var(--border) solid var(--line); border-radius: var(--radius); background: var(--paper-raised); padding: 12px; resize: vertical; font-size: 16px; font-weight: 600; }
.dialog-actions { justify-content: flex-end; margin-top: 22px; }
.form-message { min-height: 22px; margin: 12px 0 0; color: var(--deep-ocean); font-size: 13px; font-weight: 700; }
.toast { position: fixed; right: 22px; bottom: 22px; max-width: 360px; padding: 13px 16px; border: var(--border) solid var(--ink); border-radius: var(--radius); background: var(--paper-raised); box-shadow: 4px 4px 0 rgba(41, 31, 35, 0.24); font-weight: 750; opacity: 0; pointer-events: none; transform: translateY(8px); transition: 160ms ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.loading, .empty, .error { min-height: 300px; padding: 32px; display: grid; place-content: center; color: var(--muted); text-align: center; }
.app-footer { min-height: 60px; padding: 18px; border-top: 1px solid var(--line-soft); color: var(--deep-ocean); background: rgba(255, 253, 245, 0.72); text-align: center; font-weight: 750; }
.app-footer span { margin-right: 6px; color: var(--berry); }

@media (max-width: 1100px) {
  .header-actions .button span { display: none; }
  .header-actions .button { width: 48px; padding: 0; }
  .board-shell { grid-template-columns: 1fr; }
  .ticket-detail { display: none; min-height: 520px; }
  body.detail-open .ticket-region { display: none; }
  body.detail-open .ticket-detail { display: block; }
  .ticket-head, .ticket-row { grid-template-columns: minmax(260px, 1.8fr) minmax(145px, 1fr) minmax(130px, 0.8fr) minmax(145px, 0.9fr) 100px; }
  .detail-back { display: inline-flex; margin-bottom: 18px; }
}

@media (max-width: 760px) {
  body { font-size: 14px; }
  .app-header { min-height: 72px; padding: 10px 14px; }
  .brand { gap: 9px; }
  .brand__mark { width: 42px; height: 42px; }
  .brand__name { font-size: 18px; }
  .brand__divider, .brand__section { display: none; }
  .header-actions { gap: 8px; }
  .button { min-height: 42px; }
  .board-shell { min-height: calc(100vh - 72px); padding: 18px 12px; }
  .scope-tabs { width: 100%; }
  .scope-tabs button { min-width: 0; flex: 1; height: 40px; padding: 0 8px; font-size: 13px; }
  .list-toolbar { flex-wrap: wrap; align-items: stretch; gap: 10px; }
  .list-toolbar > .button--primary { width: 100%; }
  .button--primary span { font-size: 13px; }
  .ticket-head { display: none; }
  .ticket-row { grid-template-columns: 1fr auto; min-height: 112px; padding: 13px 12px; gap: 7px 12px; }
  .ticket-cell { padding: 0; }
  .ticket-title { grid-column: 1 / -1; grid-row: 1; padding-left: 20px; }
  .unread-dot { left: 1px; }
  .ticket-row > .ticket-cell:nth-child(2) { grid-column: 1; grid-row: 2; }
  .ticket-row .reporter { grid-column: 1 / -1; grid-row: 3; display: inline-flex; width: fit-content; color: var(--muted); font-size: 12px; font-weight: 750; }
  .ticket-row .reporter .avatar-chip { width: 23px; height: 23px; font-size: 9px; }
  .ticket-row .ticket-updated { display: none; }
  .ticket-row .build-cell { grid-column: 2; grid-row: 2; align-self: center; justify-self: end; }
  .ticket-footer { min-height: 44px; }
  .ticket-detail { padding: 20px 16px; }
  .detail-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .timeline-item { grid-template-columns: 44px 1fr; gap: 12px; }
  .timeline::before { left: 21px; }
  .team-mark { width: 44px; height: 44px; }
  .response-card { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
