/* Reset + typography + generic, screen-agnostic component styles. */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { overflow-x: hidden; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75em; }
ul, ol { margin: 0; padding-left: 1.25em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--font-mono); font-size: 0.9em; }
pre {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75em;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.5em 0.6em; border-bottom: 1px solid var(--border); font-size: 0.92em; }
th { color: var(--text-muted); font-weight: 600; }

img, svg { display: block; }

/* Focus visibility: always show a clear ring for keyboard users. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

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

/* --- Forms --- */
input, select, textarea, button {
  font: inherit;
  color: inherit;
}
input[type='text'], input[type='email'], input[type='password'], input[type='search'],
input[type='number'], input[type='date'], select, textarea {
  width: 100%;
  padding: 0.5em 0.65em;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}
textarea { resize: vertical; min-height: 2.4em; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.6; }

.field { margin-bottom: 0.9em; display: flex; flex-direction: column; gap: 0.3em; }
.field label { font-size: 0.88em; font-weight: 600; color: var(--text-muted); }
.field .required { color: var(--danger); }
.field-hint { margin: 0; font-size: 0.8em; color: var(--text-muted); }
.field-error-msg { margin: 0; font-size: 0.82em; color: var(--danger); }
.field-error input, .field-error select, .field-error textarea { border-color: var(--danger); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1em; }
.filter-checkbox { display: inline-flex; align-items: center; gap: 0.4em; font-size: 0.9em; }
.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  padding: 0.6em 0.8em;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
  margin-bottom: 0.75em;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.btn:disabled { cursor: not-allowed; opacity: 0.55; }
.btn-md { padding: 0.5em 0.9em; font-size: 0.92em; }
.btn-sm { padding: 0.35em 0.65em; font-size: 0.84em; }
.btn-default, .btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-default:hover:not(:disabled), .btn-ghost:hover:not(:disabled) { background: var(--bg-muted); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.06); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1em;
  height: 2.1em;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--bg-muted); }

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.15em 0.55em;
  border-radius: 999px;
  font-size: 0.76em;
  font-weight: 600;
  line-height: 1.6;
  background: var(--bg-muted);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: var(--bg-muted); color: var(--text-muted); }

.role-badge { background: transparent; border: 1px solid currentColor; }
.role-product_owner { color: var(--role-product_owner); }
.role-project_manager { color: var(--role-project_manager); }
.role-architect { color: var(--role-architect); }
.role-frontend { color: var(--role-frontend); }
.role-backend { color: var(--role-backend); }
.role-devops { color: var(--role-devops); }
.role-test { color: var(--role-test); }
.role-reviewer { color: var(--role-reviewer); }
.role-security { color: var(--role-security); }
.role-analyst { color: var(--role-analyst); }

.status-badge { font-weight: 700; }
.status-backlog { background: var(--status-backlog-soft); color: var(--status-backlog); }
.status-ready { background: var(--status-ready-soft); color: var(--status-ready); }
.status-in_progress { background: var(--status-in_progress-soft); color: var(--status-in_progress); }
.status-waiting_human { background: var(--status-waiting_human-soft); color: var(--status-waiting_human); }
.status-in_review { background: var(--status-in_review-soft); color: var(--status-in_review); }
.status-waiting_approval { background: var(--status-waiting_approval-soft); color: var(--status-waiting_approval); }
.status-blocked { background: var(--status-blocked-soft); color: var(--status-blocked); }
.status-done { background: var(--status-done-soft); color: var(--status-done); }
.status-cancelled { background: var(--status-cancelled-soft); color: var(--status-cancelled); }
.status-open { background: var(--info-soft); color: var(--info); }
.status-answered { background: var(--success-soft); color: var(--success); }

.priority-badge { text-transform: uppercase; letter-spacing: 0.03em; }
.priority-low { background: var(--bg-muted); color: var(--text-muted); }
.priority-normal { background: var(--info-soft); color: var(--info); }
.priority-high { background: var(--warning-soft); color: var(--warning); }
.priority-critical { background: var(--danger-soft); color: var(--danger); }

/* --- Presence / assignee --- */
.presence { display: inline-flex; align-items: center; gap: 0.35em; font-size: 0.82em; }
.presence-online { color: var(--success); }
.presence-busy { color: var(--warning); }
.presence-offline { color: var(--text-muted); }
.presence-label { font-weight: 600; }

.assignee-chip { display: inline-flex; align-items: center; gap: 0.4em; font-size: 0.88em; }
.assignee-empty { color: var(--text-muted); font-style: italic; }
.assignee-human .assignee-name::before { content: '👤 '; }

/* --- Spinner / empty state --- */
.spinner-row { display: flex; align-items: center; gap: 0.6em; color: var(--text-muted); padding: 1.5em 0; }
.spinner {
  width: 1.1em;
  height: 1.1em;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { padding: 2em 1em; text-align: center; color: var(--text-muted); }
.empty-title { font-weight: 600; color: var(--text); }
.empty-hint { color: var(--text-muted); font-size: 0.9em; }

/* --- Markdown output --- */
.markdown :is(h1, h2, h3, h4, h5, h6) { margin-top: 0.9em; }
.markdown p { margin: 0 0 0.7em; }
.markdown ul, .markdown ol { margin: 0 0 0.7em; padding-left: 1.4em; }
.markdown blockquote {
  margin: 0 0 0.7em;
  padding: 0.3em 0.9em;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}
.markdown code { background: var(--bg-muted); padding: 0.1em 0.3em; border-radius: 4px; }
.markdown-empty { color: var(--text-muted); font-style: italic; }

/* --- Modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1em;
  z-index: 100;
}
.modal-dialog {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.25em;
}
.modal-dialog.modal-wide { max-width: 680px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75em; }
.modal-header h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6em; margin-top: 0.75em; }

/* --- Toasts --- */
.toast-host {
  position: fixed;
  bottom: 1em;
  right: 1em;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  z-index: 200;
  max-width: min(360px, calc(100vw - 2em));
}
.toast {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75em;
  padding: 0.7em 0.9em;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 0.9em;
}
.toast-error { border-color: var(--danger); color: var(--danger); }
.toast-success { border-color: var(--success); color: var(--success); }
.toast-warning { border-color: var(--warning); color: var(--warning); }
.toast-close { background: none; border: none; cursor: pointer; font-size: 1.1em; line-height: 1; color: inherit; }

.denied { padding: 2em; color: var(--text-muted); }
