:root {
    --aubergine: #241a2c;
    --aubergine-hover: #35273f;
    --paper: #f5f6f8;
    --surface: #ffffff;
    --surface-soft: #f8f9fb;
    --selected: #edf3ff;
    --line: #dde1e8;
    --line-strong: #c8ced8;
    --ink: #171a22;
    --muted: #5f6673;
    --faint: #68717e;
    --blue: #246bfd;
    --blue-strong: #1455d9;
    --blue-soft: #e8f0ff;
    --coral: #b93649;
    --coral-soft: #fff0f1;
    --teal: #087e6c;
    --teal-soft: #e7f6f2;
    --focus: #7aa7ff;
    --radius: 8px;
    --font: "Segoe UI Variable", "Aptos", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    color: var(--ink);
    background: var(--paper);
    font-family: var(--font);
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

body,
button,
input,
select,
textarea { font: inherit; }

button,
input,
select,
textarea { color: inherit; }

button { -webkit-tap-highlight-color: transparent; }

button:disabled,
input:disabled,
select:disabled,
textarea:disabled { cursor: not-allowed; opacity: .58; }

::selection { color: #fff; background: var(--blue); }

* {
    scrollbar-width: thin;
    scrollbar-color: #adb5c1 transparent;
}

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 999px; background: #adb5c1; background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip-link {
    position: fixed;
    z-index: 100;
    top: 8px;
    left: 8px;
    padding: 9px 12px;
    border-radius: var(--radius);
    color: #fff;
    background: var(--blue-strong);
    transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.icon-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.app-shell { display: grid; grid-template-rows: 64px minmax(0, 1fr); width: 100%; height: 100dvh; }

.app-header {
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 18px;
    color: #fff;
    background: var(--aubergine);
}

.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; color: var(--aubergine); background: #fff; font-size: 18px; font-weight: 800; }
.brand strong,
.brand small { display: block; }
.brand strong { font-size: 16px; line-height: 1.2; }
.brand small { margin-top: 2px; color: #cbbfd2; font-size: 11px; }

.header-actions { display: flex; align-items: center; gap: 9px; }

.new-task-button,
.primary-action,
.primary-button,
.comment-form button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 40px;
    padding: 8px 13px;
    border: 1px solid var(--blue);
    border-radius: var(--radius);
    color: #fff;
    background: var(--blue);
    font-size: 13px;
    font-weight: 750;
    cursor: pointer;
    transition: background-color 150ms ease-out, border-color 150ms ease-out;
}

.new-task-button:hover,
.primary-action:hover,
.primary-button:hover,
.comment-form button:hover { border-color: var(--blue-strong); background: var(--blue-strong); }

.account-menu { position: relative; }
.account-menu summary {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 40px;
    padding: 3px 8px 3px 4px;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: var(--radius);
    cursor: pointer;
    list-style: none;
}
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu summary:hover { background: var(--aubergine-hover); }
.account-menu[open] summary { background: var(--aubergine-hover); }
.account-menu summary > svg { width: 14px; height: 14px; color: #cbbfd2; transition: transform 150ms ease-out; }
.account-menu[open] summary > svg { transform: rotate(180deg); }
.account-avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--teal); font-size: 11px; font-weight: 800; }
.account-name { font-size: 12px; font-weight: 700; }

.account-popover {
    position: absolute;
    z-index: 30;
    top: calc(100% + 8px);
    right: 0;
    width: 230px;
    padding: 7px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    color: var(--ink);
    background: var(--surface);
    box-shadow: 0 16px 40px rgba(21, 16, 27, .2);
}
.account-popover p { margin: 4px 7px 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.account-popover button { display: block; width: 100%; padding: 8px 9px; border: 0; border-radius: 6px; background: transparent; text-align: left; cursor: pointer; }
.account-popover button:hover,
.account-popover button[aria-pressed="true"] { background: var(--selected); }
.account-popover strong,
.account-popover span { display: block; }
.account-popover strong { font-size: 12px; }
.account-popover span { margin-top: 2px; color: var(--muted); font-size: 11px; }

.main-content {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    width: min(1320px, 100%);
    min-width: 0;
    min-height: 0;
    margin: 0 auto;
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
    background: var(--surface);
}

.overview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 22px 14px;
}
.overview h1 { margin: 0; font-size: 22px; line-height: 1.2; letter-spacing: -.025em; }
.overview p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(380px, 42vw);
    min-height: 40px;
    padding: 0 11px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface-soft);
}
.search-box svg { color: var(--faint); }
.search-box input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; font-size: 13px; }
.search-box input::placeholder,
.comment-form textarea::placeholder { color: #67707c; }
.search-box:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }

.view-tabs { display: flex; gap: 4px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.view-tab { min-height: 42px; padding: 8px 11px; border: 0; border-bottom: 2px solid transparent; color: var(--muted); background: transparent; font-size: 13px; font-weight: 700; cursor: pointer; }
.view-tab:hover { color: var(--ink); background: var(--surface-soft); }
.view-tab.is-active { border-bottom-color: var(--blue); color: var(--blue-strong); }
.view-tab span { min-width: 22px; margin-left: 4px; padding: 1px 6px; border-radius: 999px; color: var(--muted); background: #eef0f4; font-size: 11px; }
.view-tab.is-active span { color: var(--blue-strong); background: var(--blue-soft); }

.work-area { display: grid; grid-template-columns: 360px minmax(0, 1fr); min-width: 0; min-height: 0; overflow: hidden; }
.work-area.is-empty { grid-template-columns: minmax(0, 1fr); }
.work-area.is-empty .task-pane { grid-column: 1 / -1; border-right: 0; }
.task-pane { display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; min-height: 0; border-right: 1px solid var(--line); }
.list-header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 13px 15px 10px; border-bottom: 1px solid var(--line); }
.list-header h2 { margin: 0; font-size: 14px; }
.list-header span { color: var(--muted); font-size: 11px; }

.task-list { margin: 0; padding: 0; overflow: auto; list-style: none; }
.task-list,
.empty-state { grid-row: 2; }
.task-list li { border-bottom: 1px solid var(--line); }
.task-row { display: block; width: 100%; padding: 14px 15px; border: 0; color: var(--ink); background: var(--surface); text-align: left; cursor: pointer; transition: background-color 150ms ease-out, box-shadow 150ms ease-out; }
.task-row:hover { background: var(--surface-soft); }
.task-row.is-selected { background: var(--selected); box-shadow: inset 0 0 0 1px #b9ccf8; }
.task-row-head,
.task-row-foot { display: flex; align-items: center; gap: 7px; min-width: 0; }
.task-row-key { color: var(--muted); font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; }
.task-row-due { margin-left: auto; color: var(--faint); font-size: 11px; font-weight: 650; white-space: nowrap; }
.task-row-due.is-soon,
.task-due.is-soon { color: var(--blue-strong); }
.task-row-due.is-overdue,
.task-due.is-overdue { color: var(--coral); font-weight: 800; }
.task-row-due.is-done,
.task-due.is-done { color: var(--teal); }
.unread-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--blue); }
.task-row-title { display: -webkit-box; margin: 6px 0 7px; overflow: hidden; font-size: 14px; font-weight: 750; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.task-client { overflow: hidden; flex: 1; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.task-next { margin-left: auto; color: var(--blue-strong); font-size: 11px; font-weight: 700; white-space: nowrap; }
.task-next.is-done { color: var(--teal); }
.task-next.is-urgent { color: var(--coral); }

.empty-state { display: grid; place-content: center; min-height: 100%; padding: 30px; text-align: center; }
.empty-state[hidden] { display: none; }
.empty-state h3 { margin: 0; font-size: 16px; }
.empty-state p { max-width: 30ch; margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.empty-state button { margin-top: 12px; border: 0; color: var(--blue-strong); background: transparent; font-weight: 700; cursor: pointer; }

.task-thread { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; overflow: hidden; }
.task-thread[hidden] { display: none; }
.task-header { display: flex; align-items: center; gap: 13px; min-height: 96px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.task-header .back-button { display: none; }
.task-heading { min-width: 0; flex: 1; }
.task-heading > div { display: flex; align-items: center; gap: 8px; }
#task-key { color: var(--muted); font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; }
.status-text { padding: 3px 7px; border-radius: 999px; color: var(--blue-strong); background: var(--blue-soft); font-size: 11px; font-weight: 700; }
.task-heading h2 { margin: 5px 0 0; overflow: hidden; font-size: 18px; line-height: 1.25; letter-spacing: -.02em; text-overflow: ellipsis; white-space: nowrap; }
.task-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.task-due { font-weight: 700; white-space: nowrap; }
.task-due::before { content: " · "; color: var(--faint); font-weight: 400; }
.primary-action { flex: 0 0 auto; max-width: 190px; }

.icon-button { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 1px solid transparent; border-radius: var(--radius); color: var(--muted); background: transparent; cursor: pointer; }
.icon-button:hover { border-color: var(--line); color: var(--ink); background: var(--surface-soft); }

.task-facts { border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.task-facts > summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 9px 20px; cursor: pointer; list-style: none; }
.task-facts > summary::-webkit-details-marker { display: none; }
.task-facts > summary:hover { background: #f1f3f6; }
.task-facts > summary span,
.task-facts > summary strong,
.task-facts > summary small { display: block; }
.task-facts > summary strong { font-size: 12px; }
.task-facts > summary small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.task-facts > summary svg { color: var(--muted); transition: transform 150ms ease-out; }
.task-facts[open] > summary svg { transform: rotate(180deg); }
.facts-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 20px; padding: 5px 20px 17px; }
.fact { margin: 0; }
.fact dt { margin-bottom: 3px; color: var(--faint); font-size: 11px; }
.fact dd { margin: 0; overflow-wrap: anywhere; font-size: 12px; font-weight: 650; }
.more-actions { display: flex; gap: 12px; padding: 0 20px 16px; }
.text-action { padding: 0; border: 0; color: var(--coral); background: transparent; font-size: 12px; font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

.activity-scroll { min-width: 0; min-height: 0; overflow: auto; }
.activity-list { max-width: 760px; margin: 0 auto; padding: 20px 24px 28px; list-style: none; }
.activity-item { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 11px; margin-bottom: 18px; }
.activity-avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; color: #fff; background: var(--aubergine); font-size: 11px; font-weight: 800; }
.activity-avatar.role-support { background: #765080; }
.activity-avatar.role-development { background: var(--blue-strong); }
.activity-avatar.role-qa { background: var(--teal); }
.activity-avatar.role-signal { color: var(--coral); background: var(--coral-soft); }
.activity-avatar.role-system { color: var(--muted); background: #e6e9ee; }
.activity-content { min-width: 0; padding-top: 1px; }
.activity-meta { display: flex; align-items: baseline; gap: 7px; }
.activity-meta strong { font-size: 13px; }
.activity-meta span { color: var(--faint); font-size: 11px; }
.activity-text { max-width: 70ch; margin: 5px 0 0; color: #323641; font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.activity-item.type-event .activity-content,
.activity-item.type-signal .activity-content { padding: 10px 12px; border-radius: var(--radius); background: var(--surface-soft); }
.activity-item.type-signal .activity-content { color: #762330; background: var(--coral-soft); }
.activity-item.type-signal .activity-meta strong { color: var(--coral); }
.activity-item.is-new .activity-content { animation: handoff-arrive 420ms cubic-bezier(.2, .8, .2, 1); }

@keyframes handoff-arrive {
    from { background: var(--blue-soft); box-shadow: 0 8px 24px rgba(36, 107, 253, .14); }
    to { box-shadow: none; }
}

.comment-form { margin: 0 20px 16px; padding: 10px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); }
.comment-form:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.comment-form > label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.comment-form textarea { display: block; width: 100%; min-height: 62px; padding: 3px 4px; resize: vertical; border: 0; outline: 0; background: transparent; font-size: 14px; line-height: 1.45; }
.comment-form > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 7px; }
.comment-form > div > span { color: var(--faint); font-size: 11px; }
.comment-form kbd { padding: 1px 5px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-soft); font-family: var(--font); font-size: 11px; }
.comment-form button { min-height: 34px; padding: 5px 10px; font-size: 12px; }

.form-dialog { width: min(520px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); padding: 0; overflow: auto; border: 1px solid var(--line-strong); border-radius: 12px; color: var(--ink); background: var(--surface); box-shadow: 0 18px 50px rgba(21, 16, 27, .2); }
.form-dialog::backdrop { background: rgba(21, 16, 27, .58); }
.form-dialog header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.form-dialog h2 { margin: 0; font-size: 19px; }
.form-dialog header p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.dialog-body { display: grid; gap: 14px; padding: 18px 20px; }
.dialog-body label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.dialog-body input,
.dialog-body select,
.dialog-body textarea { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); font-weight: 400; }
.dialog-body textarea { resize: vertical; line-height: 1.45; }
.dialog-body input:focus,
.dialog-body select:focus,
.dialog-body textarea:focus { border-color: var(--blue); outline: 3px solid var(--blue-soft); }
.form-dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 20px; border-top: 1px solid var(--line); background: var(--surface-soft); }
.secondary-button { min-height: 40px; padding: 8px 13px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); font-size: 13px; font-weight: 700; cursor: pointer; }
.secondary-button:hover { border-color: var(--ink); background: var(--surface-soft); }

.toast-region { position: fixed; z-index: 80; right: 18px; bottom: 18px; width: min(360px, calc(100vw - 36px)); pointer-events: none; }
.toast { display: flex; align-items: flex-start; gap: 9px; padding: 11px 13px; border: 1px solid #a7d9cd; border-radius: var(--radius); color: #075d50; background: var(--teal-soft); box-shadow: 0 10px 30px rgba(21, 16, 27, .14); animation: toast-in 200ms ease-out; }
.toast svg { margin-top: 1px; }
.toast strong,
.toast span { display: block; }
.toast strong { font-size: 12px; }
.toast span { margin-top: 2px; font-size: 11px; }
@keyframes toast-in { from { transform: translateY(7px); opacity: .35; } }

@media (max-width: 760px) {
    .app-shell { grid-template-rows: 64px minmax(0, 1fr); }
    .app-header { padding: 8px 10px; }
    .main-content { border: 0; }
    .overview { align-items: stretch; flex-direction: column; gap: 11px; padding: 14px 12px 12px; }
    .overview h1 { font-size: 19px; }
    .overview p { font-size: 12px; }
    .search-box { width: 100%; }
    .view-tabs { padding: 0 8px; }
    .view-tab { flex: 1; padding: 8px 5px; }
    .work-area { position: relative; display: block; min-height: 0; }
    .task-pane,
    .task-thread { position: absolute; inset: 0; }
    .app-shell[data-mobile-view="thread"] .main-content { grid-template-rows: minmax(0, 1fr); }
    .app-shell[data-mobile-view="thread"] .overview,
    .app-shell[data-mobile-view="thread"] .view-tabs { display: none; }
    .app-shell[data-mobile-view="list"] .task-thread { display: none; }
    .app-shell[data-mobile-view="thread"] .task-pane { display: none; }
    .task-pane { border-right: 0; }
    .task-header .back-button { display: inline-grid; }
    .task-header { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: start; gap: 8px 10px; min-height: 0; padding: 10px; }
    .task-heading { grid-column: 2; }
    .task-heading h2 { max-width: none; overflow: visible; font-size: 15px; text-overflow: clip; white-space: normal; }
    .task-heading p { max-width: none; overflow: visible; white-space: normal; }
    .primary-action { grid-column: 1 / -1; width: 100%; max-width: none; min-height: 40px; padding: 7px 10px; font-size: 12px; }
    .task-facts > summary { padding-right: 12px; padding-left: 12px; }
    .facts-grid { grid-template-columns: 1fr 1fr; padding-right: 12px; padding-left: 12px; }
    .more-actions { padding-right: 12px; padding-left: 12px; }
    .activity-list { padding: 16px 12px 22px; }
    .comment-form { margin: 0 9px 9px; }
    .comment-form > div > span { display: none; }
    .comment-form > div { justify-content: flex-end; }
}

@media (max-width: 760px) and (max-height: 520px) {
    .task-header { grid-template-columns: 36px minmax(0, 1fr); gap: 5px 8px; padding: 7px 9px; }
    .task-header .back-button { width: 36px; height: 36px; }
    .task-heading h2 { font-size: 14px; line-height: 1.2; }
    .task-heading p { margin-top: 2px; font-size: 11px; }
    .primary-action { min-height: 36px; padding: 5px 8px; }
    .comment-form { margin: 0 7px 7px; padding: 7px; }
    .comment-form textarea { min-height: 38px; max-height: 58px; resize: none; }
    .comment-form > div { margin-top: 4px; }
}

@media (max-width: 520px) {
    .new-task-button { width: 40px; padding: 0; }
    .new-task-button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
    .account-menu summary { width: 40px; padding: 4px; }
    .account-name,
    .account-menu summary > svg { display: none; }
    .brand { gap: 8px; }
    .brand-mark { width: 34px; height: 34px; }
    .brand strong { font-size: 14px; }
    .brand small { font-size: 11px; }
}

@media (max-width: 380px) {
    .brand-mark { display: none; }
    .view-tab { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
