/* Relay — Team inbox
   Flat design, teal palette, DM Sans + Space Grotesk + IBM Plex Mono */

@font-face {
  font-family: "DM Sans";
  src: url("assets/dm-sans.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("assets/space-grotesk.ttf") format("truetype");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("assets/ibm-plex-mono.ttf") format("truetype");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Palette from design system */
  --color-primary: #0d9488;
  --color-primary-strong: #0b7d72;
  --color-on-primary: #ffffff;
  --color-secondary: #14b8a6;
  --color-accent: #ea580c;
  --color-on-accent: #ffffff;

  --color-background: #f0fdfa;
  --color-foreground: #134e4a;
  --color-card: #ffffff;
  --color-card-foreground: #0f2f2d;
  --color-muted: #e8f1f4;
  --color-muted-foreground: #475569;
  --color-border: #cfe9e3;
  --color-border-strong: #b7d8d1;
  --color-destructive: #dc2626;

  /* Status semantics */
  --status-todo: #64748b;
  --status-todo-bg: #eef2f6;
  --status-todo-fg: #334155;
  --status-progress: #2563eb;
  --status-progress-bg: #e6effe;
  --status-progress-fg: #1d4ed8;
  --status-blocked: #dc2626;
  --status-blocked-bg: #fdecec;
  --status-blocked-fg: #b42318;
  --status-done: #16a34a;
  --status-done-bg: #e7f7ed;
  --status-done-fg: #15803d;

  /* Priority */
  --prio-high: #dc2626;
  --prio-medium: #d97706;
  --prio-low: #64748b;

  --ring: #0d9488;

  /* Type */
  --font-sans: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Space Grotesk", "DM Sans", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;

  --shadow-1: 0 1px 2px rgba(15, 47, 45, 0.06), 0 1px 3px rgba(15, 47, 45, 0.04);
  --shadow-2: 0 4px 16px rgba(15, 47, 45, 0.08), 0 2px 6px rgba(15, 47, 45, 0.05);
  --shadow-3: 0 18px 48px rgba(15, 47, 45, 0.16), 0 6px 18px rgba(15, 47, 45, 0.08);

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--color-card-foreground);
  background:
    radial-gradient(1200px 600px at 100% -10%, #d8f5ef 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 0%, #e3f7f2 0%, transparent 55%),
    var(--color-background);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.01em; }

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

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

.skip-link {
  position: absolute;
  left: 12px; top: -48px;
  z-index: 100;
  background: var(--color-primary);
  color: var(--color-on-primary);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  transition: top 160ms var(--ease);
}
.skip-link:focus { top: 12px; }

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 32px) var(--space-7);
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) 0 var(--space-4);
  margin-bottom: var(--space-2);
  background: linear-gradient(to bottom, var(--color-background) 70%, rgba(240, 253, 250, 0));
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { display: inline-flex; align-self: center; }
.brand-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-foreground);
}
.brand-sub {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-primary);
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(13, 148, 136, 0.1);
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-muted-foreground);
  font-variant-numeric: tabular-nums;
}
.header-stat.sep::before {
  content: "·";
  margin-right: 6px;
  color: var(--color-border-strong);
}
.header-stat strong { color: var(--color-foreground); font-weight: 600; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  gap: var(--space-3);
  align-items: flex-end;
  flex-wrap: wrap;
  padding: var(--space-3) 0 var(--space-4);
}
.search-field {
  position: relative;
  flex: 1 1 280px;
  min-width: 0;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-muted-foreground);
  pointer-events: none;
}
#search {
  width: 100%;
  height: 46px;
  padding: 0 40px 0 42px;
  font: inherit;
  font-size: 15px;
  color: var(--color-card-foreground);
  background: var(--color-card);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
#search::placeholder { color: #94a3b8; }
#search:hover { border-color: var(--color-border-strong); }
#search:focus-visible { border-color: var(--color-primary); outline: none; box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.16); }

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px; height: 30px;
  border: none;
  background: var(--color-muted);
  color: var(--color-muted-foreground);
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.search-clear:hover { background: var(--color-border); color: var(--color-foreground); }

.filter-field { display: flex; flex-direction: column; gap: 6px; }
.filter-label, .sort-label, .control-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-muted-foreground);
  text-transform: uppercase;
}
.select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.select-wrap.grow { display: flex; width: 100%; }
#filter {
  height: 46px;
  min-width: 168px;
  padding: 0 38px 0 14px;
  font: inherit;
  font-size: 15px;
  color: var(--color-card-foreground);
  background: var(--color-card);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  appearance: none;
  cursor: pointer;
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
#filter:hover { border-color: var(--color-border-strong); }
#filter:focus-visible { border-color: var(--color-primary); outline: none; box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.16); }

.select-caret {
  position: absolute;
  right: 12px;
  pointer-events: none;
  color: var(--color-muted-foreground);
}

/* ---------- Status chips ---------- */
.status-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding-bottom: var(--space-4);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--color-border);
  background: var(--color-card);
  color: var(--color-muted-foreground);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease), transform 120ms var(--ease);
}
.chip:hover { border-color: var(--color-border-strong); color: var(--color-foreground); }
.chip:active { transform: translateY(1px); }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--color-muted-foreground); }
.chip .count {
  font-variant-numeric: tabular-nums;
  background: var(--color-muted);
  color: var(--color-muted-foreground);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
}
.chip[aria-current="true"] {
  background: var(--color-foreground);
  border-color: var(--color-foreground);
  color: #fff;
}
.chip[aria-current="true"] .count { background: rgba(255,255,255,0.22); color: #fff; }
.chip[aria-current="true"] .dot { box-shadow: 0 0 0 3px rgba(255,255,255,0.35); }

/* ---------- List meta / sort ---------- */
.list-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.result-count { margin: 0; font-size: 13px; color: var(--color-muted-foreground); }
.result-count strong { color: var(--color-foreground); }
.sort-field { display: flex; align-items: center; gap: 8px; }
.select-wrap.sm select {
  height: 36px;
  font-size: 14px;
  padding: 0 30px 0 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-card);
  color: var(--color-card-foreground);
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
}
.select-wrap.sm select:hover { border-color: var(--color-border-strong); }
.select-wrap.sm select:focus-visible { border-color: var(--color-primary); outline: none; box-shadow: 0 0 0 4px rgba(13,148,136,0.16); }

/* ---------- Task list ---------- */
.task-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-3);
}

.task-item {
  background: var(--color-card);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow-1);
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease), transform 120ms var(--ease);
  position: relative;
}
.task-item:hover { border-color: var(--color-border-strong); box-shadow: var(--shadow-2); }
.task-item.is-open { box-shadow: 0 0 0 2px var(--color-primary), var(--shadow-2); border-color: var(--color-primary); }

.task-item-top {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}
.task-main { flex: 1; min-width: 0; }

.open-item {
  display: block;
  text-align: left;
  width: 100%;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.open-item:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }

.task-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-card-foreground);
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.open-item:hover .task-title { color: var(--color-primary-strong); }

.task-summary {
  margin: 0;
  color: var(--color-muted-foreground);
  font-size: 14px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.status-badge .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

.s-todo { background: var(--status-todo-bg); color: var(--status-todo-fg); border-color: #dde3ea; }
.s-todo .dot { background: var(--status-todo); }
.s-in-progress { background: var(--status-progress-bg); color: var(--status-progress-fg); border-color: #cfe0fd; }
.s-in-progress .dot { background: var(--status-progress); }
.s-blocked { background: var(--status-blocked-bg); color: var(--status-blocked-fg); border-color: #f7d3d0; }
.s-blocked .dot { background: var(--status-blocked); }
.s-done { background: var(--status-done-bg); color: var(--status-done-fg); border-color: #c8ecd5; }
.s-done .dot { background: var(--status-done); }

.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  margin-top: var(--space-3);
  font-size: 13px;
  color: var(--color-muted-foreground);
}
.meta-cell { display: inline-flex; align-items: center; gap: 6px; }
.meta-cell svg { color: var(--color-muted-foreground); flex: 0 0 auto; }
.assignee-avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  flex: 0 0 auto;
  border: 1.5px solid var(--color-card);
}
.prio {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
}
.prio::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.prio.high { color: var(--prio-high); }
.prio.medium { color: var(--prio-medium); }
.prio.low { color: var(--prio-low); }

.tag-list { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--color-muted);
  color: var(--color-muted-foreground);
}
.due { font-variant-numeric: tabular-nums; }
.due.overdue { color: var(--status-blocked-fg); font-weight: 600; }

.open-chevron {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--color-muted);
  color: var(--color-muted-foreground);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 160ms var(--ease), color 160ms var(--ease);
  align-self: center;
}
.open-chevron:hover { background: var(--color-primary); color: var(--color-on-primary); }
.open-chevron:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  background: var(--color-card);
  border: 1.5px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  color: var(--color-muted-foreground);
}
.empty-state svg { color: var(--color-border-strong); margin-bottom: var(--space-3); }
.empty-state h2 {
  margin: 0 0 6px;
  font-size: 19px;
  color: var(--color-foreground);
}
.empty-state p { margin: 0 0 var(--space-4); }
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1.5px solid transparent;
  padding: 10px 18px;
  transition: background 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease), transform 120ms var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover { background: var(--color-primary-strong); }
.btn-primary:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

/* ---------- Detail dialog ---------- */
dialog.detail {
  border: none;
  padding: 0;
  background: transparent;
  margin: 0;
  inset: 0;
  max-width: 100vw;
  max-height: 100vh;
  width: 100vw;
  height: 100vh;
  color: var(--color-card-foreground);
}
dialog.detail::backdrop {
  background: rgba(8, 39, 36, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.detail-panel {
  margin-left: auto;
  width: min(520px, 100%);
  height: 100%;
  background: var(--color-card);
  box-shadow: var(--shadow-3);
  padding: clamp(20px, 5vw, 32px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  animation: slide-in 260ms var(--ease);
}
@keyframes slide-in {
  from { transform: translateX(28px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.detail-id-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-id {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-muted-foreground);
  background: var(--color-muted);
  padding: 3px 8px;
  border-radius: 6px;
}
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--color-border);
  background: var(--color-card);
  color: var(--color-foreground);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  transition: background 160ms var(--ease), border-color 160ms var(--ease);
}
.icon-btn:hover { background: var(--color-muted); border-color: var(--color-border-strong); }
.icon-btn:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

.detail-title {
  font-family: var(--font-display);
  font-size: clamp(22px, 5vw, 26px);
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
  letter-spacing: -0.02em;
}
.detail-summary {
  margin: 0;
  color: var(--color-muted-foreground);
  font-size: 15px;
}

.detail-status-control {
  background: var(--color-muted);
  border-radius: var(--radius);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.status-control-row { display: flex; gap: var(--space-2); }
#status-control {
  flex: 1;
  height: 46px;
  padding: 0 38px 0 14px;
  font: inherit;
  font-size: 15px;
  color: var(--color-card-foreground);
  background: var(--color-card);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  appearance: none;
  cursor: pointer;
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
#status-control:hover { border-color: var(--color-border-strong); }
#status-control:focus-visible { border-color: var(--color-primary); outline: none; box-shadow: 0 0 0 4px rgba(13,148,136,0.16); }

.status-feedback {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary-strong);
  min-height: 1.2em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-feedback::before {
  content: "";
  width: 0; height: 0;
}
.status-feedback.show::before {
  content: "";
  width: 16px; height: 16px;
  background: var(--color-primary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M4 10.5l3.5 3.5L16 6' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M4 10.5l3.5 3.5L16 6' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/contain no-repeat;
  animation: pop 200ms var(--ease);
}
@keyframes pop {
  from { transform: scale(0.5); }
  to { transform: scale(1); }
}

.detail-body {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-4);
}
.detail-body h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted-foreground);
  margin: 0 0 var(--space-2);
  font-family: var(--font-sans);
  font-weight: 600;
}
.detail-body p { margin: 0 0 var(--space-3); white-space: pre-line; font-size: 15px; line-height: 1.6; }
.detail-body .outcome {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  background: rgba(13, 148, 136, 0.06);
  border-left: 3px solid var(--color-primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 14px;
}

.detail-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3) var(--space-4);
  margin: 0;
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-4);
}
.detail-meta div { display: flex; flex-direction: column; gap: 2px; }
.detail-meta dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted-foreground);
  font-weight: 600;
}
.detail-meta dd { margin: 0; font-size: 14px; font-weight: 500; color: var(--color-card-foreground); }
.detail-meta .assignee-cell dd { display: flex; align-items: center; gap: 8px; }
.detail-meta .full { grid-column: 1 / -1; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  body { font-size: 15px; }
  .app { padding: 0 16px var(--space-6); }
  .header-meta { display: none; }
  .toolbar { gap: var(--space-2); }
  .filter-field { flex: 1 1 100%; }
  #filter { width: 100%; min-width: 0; }
  .search-field { flex: 1 1 100%; }
  .list-meta { flex-direction: column; align-items: stretch; gap: 10px; }
  .sort-field { justify-content: flex-end; }
  .task-item { padding: var(--space-3); }
  .task-title { font-size: 16px; }
  .open-chevron { display: none; }
  .detail-meta { grid-template-columns: 1fr; }
  .detail-panel { padding: 18px; }
  .status-chips { padding-bottom: var(--space-3); }
  .chip { font-size: 12px; padding: 7px 12px; }
}

@media (min-width: 1024px) {
  .detail-panel { width: 520px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .detail-panel { animation: none; }
}
