/* ---------------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius);
  font-size: 14.5px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease), color 120ms var(--ease), opacity 120ms;
  user-select: none;
}

.btn .icon {
  margin-left: -2px;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #2d2d2d;
}

.btn-ghost {
  color: var(--text-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #1d0f0e;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn:disabled {
  opacity: 0.45;
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  color: var(--text-3);
  flex: none;
  transition: background-color 120ms var(--ease), color 120ms var(--ease);
}

.icon-btn:hover,
.icon-btn[aria-expanded="true"] {
  background: var(--bg-hover);
  color: var(--text);
}

.icon-btn-sm {
  width: 26px;
  height: 26px;
}

.icon-btn-xs {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------------------
   Form controls
   --------------------------------------------------------------------------- */
.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  transition: border-color 120ms var(--ease), box-shadow 120ms var(--ease);
}

.input::placeholder {
  color: var(--text-4);
}

.input:hover {
  border-color: rgba(255, 255, 255, 0.18);
}

.input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(107, 140, 255, 0.15);
}

.input-sm {
  height: 30px;
  font-size: 13px;
}

.textarea {
  height: auto;
  min-height: 90px;
  padding: 9px 11px;
  resize: vertical;
  line-height: 1.5;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-error {
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius);
  padding: 8px 10px;
}

/* ---------------------------------------------------------------------------
   Avatars, badges
   --------------------------------------------------------------------------- */
.avatar {
  --avatar-size: 20px;
  --avatar-hue: 220;
  width: var(--avatar-size);
  height: var(--avatar-size);
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: calc(var(--avatar-size) * 0.42);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: hsl(var(--avatar-hue) 45% 88%);
  background: hsl(var(--avatar-hue) 28% 32%);
  user-select: none;
}

.avatar-empty {
  background: transparent;
  border: 1.5px dashed var(--text-4);
}

.status-glyph.status-todo { color: var(--status-todo); }
.status-glyph.status-in_progress { color: var(--status-progress); }
.status-glyph.status-done { color: var(--status-done); }

.priority-glyph.priority-low { color: var(--priority-low); }
.priority-glyph.priority-medium { color: var(--priority-medium); }
.priority-glyph.priority-high { color: var(--priority-high); }
.priority-glyph.priority-urgent { color: var(--priority-urgent); }

.status-badge,
.priority-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.priority-badge.priority-urgent .priority-label {
  color: var(--priority-urgent);
  font-weight: 500;
}

.priority-badge.priority-high .priority-label {
  color: var(--priority-high);
}

/* ---------------------------------------------------------------------------
   Popover menu
   --------------------------------------------------------------------------- */
.menu {
  position: fixed;
  z-index: 1000;
  max-width: min(320px, calc(100vw - 16px));
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 4px;
  animation: pop-in 110ms var(--ease);
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-3px); }
}

.menu-search {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  margin-bottom: 4px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.menu-search::placeholder {
  color: var(--text-4);
}

.menu-list {
  max-height: 300px;
  overflow-y: auto;
  overflow-x: hidden;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border-radius: var(--radius);
  text-align: left;
  font-size: 14.5px;
  color: var(--text);
}

.menu-item.is-focused {
  background: var(--bg-hover);
}

.menu-item.is-danger {
  color: var(--danger);
}

.menu-item.is-danger .icon {
  color: var(--danger);
}

.menu-item-icon {
  display: inline-flex;
  color: var(--text-2);
}

.menu-item-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-item-hint {
  font-size: 12px;
  color: var(--text-3);
}

.menu-item-check {
  color: var(--text-2);
}

.menu-divider {
  height: 1px;
  margin: 4px 0;
  background: var(--border);
}

.menu-empty {
  padding: 8px;
  color: var(--text-3);
  font-size: 13px;
}

/* ---------------------------------------------------------------------------
   Dialog
   --------------------------------------------------------------------------- */
.dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--border-strong);
  animation: dialog-in 140ms var(--ease);
}

.dialog-md {
  width: min(520px, calc(100vw - 32px));
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  animation: fade-in 140ms var(--ease);
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(6px) scale(0.985); }
}

@keyframes fade-in {
  from { opacity: 0; }
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 0 20px;
}

.dialog-title {
  font-size: 17px;
  font-weight: 600;
}

.dialog-description {
  padding: 8px 20px 0;
  color: var(--text-2);
  font-size: 13.5px;
}

.dialog-body {
  padding: 16px 20px 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 20px;
}

/* ---------------------------------------------------------------------------
   Toasts
   --------------------------------------------------------------------------- */
.toast-region {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(460px, calc(100vw - 32px));
  padding: 9px 12px;
  background: #2b2b2b;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  font-size: 14.5px;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 160ms var(--ease), transform 160ms var(--ease);
}

.toast.is-visible {
  opacity: 1;
  transform: none;
}

.toast-icon {
  color: var(--status-done);
}

.toast-error .toast-icon {
  color: var(--danger);
}

.toast-action {
  margin-left: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-weight: 500;
}

.toast-action:hover {
  background: var(--accent-soft);
}

/* ---------------------------------------------------------------------------
   Empty / loading states
   --------------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 64px 24px;
  gap: 6px;
}

.empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin-bottom: 10px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-3);
}

.empty-title {
  font-size: 15px;
  font-weight: 600;
}

.empty-text {
  color: var(--text-3);
  max-width: 340px;
  margin-bottom: 14px;
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 64px 0;
  color: var(--text-3);
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text-2);
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
