/* Atomica UI System — tokens, componentes e padrões a11y */
:root {
  --bg: #1e1e1e;
  --surface: #252525;
  --surface-raised: #303030;
  --line: #3d3d3d;
  --text: #dcddde;
  --muted: #929292;
  --violet: #a78bfa;
  --done: #81c995;
  --pending: #f6ad55;
  --focus: #60a5fa;
  --danger: #e57373;
  --danger-bg: #3a2929;
  --success: #81c995;
  --warning: #f6ad55;
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font: 14px/1.5 Inter, ui-sans-serif, system-ui, sans-serif;
  --touch-min: 44px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--font);
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -48px;
  left: 12px;
  z-index: 1000;
  padding: 10px 16px;
  background: var(--focus);
  color: #0a1628;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: 12px;
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus visible — never remove outlines */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid #414141;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #ddd;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #373737; color: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  border-color: #7664ad;
  background: #493e68;
  color: #fff;
}
.btn.primary:hover:not(:disabled) { background: #5a4d7f; }
.btn.secondary {
  border-color: #4a4a4a;
  background: #333333;
  color: #e8e8e8;
}
.btn.secondary:hover:not(:disabled) { background: #424242; color: #fff; }
.btn.danger {
  border-color: #8b4545;
  background: #4a2a2a;
  color: #ffc9c9;
}
.btn.danger:hover:not(:disabled) { background: #5c3535; }
.btn.ghost { border-color: transparent; }
.btn.icon-btn {
  min-width: var(--touch-min);
  min-height: 36px;
  padding: 0 10px;
}

/* Form inputs */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.field-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}
.field-error {
  margin: 0;
  font-size: 12px;
  color: #ffaaa5;
}
.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid #414141;
  border-radius: var(--radius-sm);
  background: #1d1d1d;
  color: #eee;
  padding: 10px 12px;
  font: inherit;
  min-height: var(--touch-min);
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 2px rgba(167, 139, 250, 0.25);
}
.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
}
.input:disabled,
.select:disabled,
.textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.badge.neutral { background: #333; color: #ccc; border-color: #4a4a4a; }
.badge.success { background: #1a3d2a; color: #b8e6c8; border-color: #3d6b4f; }
.badge.warning { background: #3a3020; color: #f6d7a8; border-color: #6b5a30; }
.badge.danger { background: #3a2929; color: #ffaaa5; border-color: #6b4545; }
.badge.info { background: #2a3040; color: #b8d4ff; border-color: #4a5a7a; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
}
.card-body {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* Panels & cards */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

/* Master-detail layout */
.master-detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 16px;
  align-items: start;
}
@media (max-width: 720px) {
  .master-detail { grid-template-columns: 1fr; }
  .detail-panel { order: -1; }
}

/* Session list */
.session-list { list-style: none; margin: 0; padding: 0; }
.session-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  align-items: center;
  cursor: pointer;
  transition: background 0.12s;
}
.session-item:last-child { border-bottom: 0; }
.session-item:hover { background: #2e2e2e; }
.session-item.selected {
  background: #332f45;
  border-left: 3px solid var(--violet);
  padding-left: 13px;
}
.session-item:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.session-name { font-weight: 600; font-size: 15px; margin: 0 0 4px; }
.session-meta { color: var(--muted); font-size: 12px; margin: 0; }
.session-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Detail drawer/panel */
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.detail-panel h3 { margin: 0 0 8px; font-size: 18px; }
.detail-panel .detail-meta { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.detail-panel .detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.detail-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 32px 16px; }

/* Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9990;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(420px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 9991;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.2s ease;
}
.drawer[hidden] { display: none; }
.drawer.is-closing { transform: translateX(100%); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 {
  margin: 0;
  font-size: 16px;
}
.drawer-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
}
.drawer-foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
@media (prefers-reduced-motion: reduce) {
  .drawer { transition: none; }
}

/* Loading skeleton */
.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #2a2a2a 0%, #383838 50%, #2a2a2a 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
  min-height: 14px;
}
.skeleton.text { height: 14px; margin-bottom: 8px; }
.skeleton.title { height: 20px; width: 55%; margin-bottom: 12px; }
.skeleton.block { height: 72px; }
@keyframes skeleton-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; background: #333; }
}

/* Loading */
.is-loading { position: relative; }
.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  color: var(--muted);
  font-size: 13px;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--violet);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--violet); }
}

/* Empty & error states */
.empty-state {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}
.error-banner {
  border-left: 3px solid var(--danger);
  background: var(--danger-bg);
  color: #ffaaa5;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin: 12px 0;
}
.error-banner strong { display: block; margin-bottom: 4px; }

/* Status bar */
.status-bar {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
  min-height: 18px;
}
.status-bar.error { color: #ffaaa5; }
.status-bar.success { color: var(--done); }

/* Save indicator */
.save-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.save-indicator.saving { color: #b8d4ff; }
.save-indicator.saved { color: #b8e6c8; }
.save-indicator.dirty { color: #f6d7a8; }
.save-indicator.error { color: #ffaaa5; }
.save-indicator .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* Toast container */
.toast-region {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  max-width: min(480px, 92vw);
}
.toast {
  pointer-events: auto;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}
.toast.success { background: #1a3d2a; color: #b8e6c8; border: 1px solid #3d6b4f; }
.toast.error { background: #3a2929; color: #ffaaa5; border: 1px solid #6b4545; }
.toast.info { background: #2a3040; color: #b8d4ff; border: 1px solid #4a5a7a; }
.toast.warning { background: #3a3020; color: #f6d7a8; border: 1px solid #6b5a30; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
}

/* Confirm dialog */
.confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.confirm-dialog {
  background: var(--surface-raised);
  border: 1px solid #4c4c4c;
  border-radius: var(--radius);
  padding: 22px;
  width: min(420px, 100%);
  box-shadow: var(--shadow);
}
.confirm-dialog h2 { margin: 0 0 8px; font-size: 17px; }
.confirm-dialog p { margin: 0 0 18px; color: #b9b9b9; font-size: 14px; }
.confirm-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Command palette */
.cmd-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10001;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 20px 20px;
}
.cmd-palette {
  background: var(--surface-raised);
  border: 1px solid #4c4c4c;
  border-radius: var(--radius);
  width: min(520px, 100%);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.cmd-input-wrap { padding: 12px; border-bottom: 1px solid var(--line); }
.cmd-input {
  width: 100%;
  border: 1px solid #414141;
  border-radius: var(--radius-sm);
  background: #1d1d1d;
  color: #eee;
  padding: 10px 12px;
  font: inherit;
}
.cmd-input:focus { border-color: var(--violet); }
.cmd-list { list-style: none; margin: 0; padding: 6px; max-height: 320px; overflow: auto; }
.cmd-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}
.cmd-item:hover, .cmd-item.active { background: #3d3d3d; }
.cmd-item kbd {
  font: 11px ui-monospace, monospace;
  color: var(--muted);
  border: 1px solid #555;
  padding: 1px 5px;
  border-radius: 3px;
}
.cmd-hint {
  padding: 8px 14px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

/* Toolbar */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }

/* Lead text */
.lead { color: var(--muted); margin: 0 0 28px; max-width: 56ch; }

/* Brand */
.brand { font-weight: 700; font-size: 22px; margin: 0 0 6px; }
.brand i { color: var(--violet); font-style: normal; }

/* Shell layout */
.shell { max-width: 1080px; margin: 0 auto; padding: 32px 20px 48px; }

/* Tooltip hint */
.hint-inline {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
}
.hint-inline kbd {
  border: 1px solid #555;
  padding: 1px 4px;
  border-radius: 3px;
  font: 11px ui-monospace, monospace;
}
