/* Buttons, inputs, cards, chips, modals, toasts, tables, menus. */

/* --------------------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--text-base);
  font-weight: 550;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast),
              transform var(--t-fast), opacity var(--t-fast);
}

.btn:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--border-strong);
}

.btn:active:not(:disabled) { transform: scale(0.98); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
  border-color: transparent;
  color: var(--text-on-brand);
  box-shadow: 0 4px 14px -6px var(--accent-ring);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--brand-400), var(--brand-500));
  border-color: transparent;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: transparent;
  color: var(--text);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: var(--text-sm);
}

.btn-block { width: 100%; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  color: var(--text-dim);
  transition: background var(--t-fast), color var(--t-fast);
  flex: none;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  /* Sized to its contents even inside a stretching flex column (settings panels). */
  align-self: flex-start;
  width: fit-content;
}

.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  min-width: 30px;
  padding: 0 10px;
  border-radius: var(--r-xs);
  color: var(--text-faint);
  font-size: var(--text-sm);
  transition: background var(--t-fast), color var(--t-fast);
}

.segmented button:hover { color: var(--text); }

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ---------------------------------------------------------------------------- avatar */
.avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--r-full);
  display: grid;
  place-items: center;
  font-size: var(--text-sm);
  font-weight: 650;
  color: #fff;
  background: var(--accent);
  flex: none;
  user-select: none;
}

.avatar-lg { width: 44px; height: 44px; font-size: var(--text-md); }
.avatar-sm { width: 22px; height: 22px; font-size: 10px; }

/* ---------------------------------------------------------------------------- inputs */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span,
.label {
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--text-dim);
}

.hint {
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--text-base);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}

.input::placeholder,
.textarea::placeholder { color: var(--text-faint); }

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
  background: var(--surface);
}

.textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.55;
}

.select {
  appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2399a2b3' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 15px;
}

.input-group {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.input-group .input { flex: 1; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  display: flex;
  align-items: center;
  width: 42px;
  height: 24px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  padding: 2px;
  transition: background var(--t-fast), border-color var(--t-fast);
  flex: none;
}

.switch-thumb {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: var(--r-full);
  background: var(--text-faint);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform var(--t-base) var(--ease), background var(--t-fast);
}

.switch:hover .switch-track { border-color: var(--text-faint); }

.switch input:checked + .switch-track {
  background: var(--accent);
  border-color: transparent;
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(18px);
  background: #fff;
}

.switch input:disabled + .switch-track {
  opacity: 0.5;
  cursor: not-allowed;
}

.switch input:focus-visible + .switch-track {
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* ----------------------------------------------------------------------------- chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 25px;
  padding: 0 9px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: var(--text-xs);
  font-weight: 550;
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}

button.chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.chip.active {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

.chip-x {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border-radius: var(--r-full);
  opacity: 0.6;
}

.chip-x:hover { opacity: 1; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: var(--r-xs);
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-dim);
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-accent  { background: var(--accent-soft);  color: var(--accent); }

.dot-live {
  width: 7px;
  height: 7px;
  border-radius: var(--r-full);
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
  flex: none;
}

.dot-live.off {
  background: var(--text-faint);
  box-shadow: 0 0 0 3px var(--surface-3);
}

/* ----------------------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-body { padding: 16px; }

/* ---------------------------------------------------------------------------- modals */
.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 6, 10, 0.62);
  backdrop-filter: blur(6px);
  animation: overlay-in var(--t-base) var(--ease-out);
}

@keyframes overlay-in {
  from { opacity: 0; }
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: min(86vh, 760px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modal-in var(--t-base) var(--ease-out);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
}

.modal-wide { max-width: 720px; }
.modal-xl   { max-width: 1100px; }
.modal-full {
  max-width: min(1400px, 96vw);
  height: min(92vh, 1000px);
  max-height: none;
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.modal-head h3 { flex: 1; min-width: 0; }

.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-body.flush { padding: 0; }

.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  flex: none;
}

@media (max-width: 640px) {
  .overlay { padding: 0; align-items: flex-end; }

  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    animation: sheet-in var(--t-base) var(--ease-out);
  }

  .modal-full { height: 96vh; }
  .modal-foot { padding-bottom: calc(13px + env(safe-area-inset-bottom, 0px)); }
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
}

/* ----------------------------------------------------------------------------- menus */
.menu {
  position: fixed;
  z-index: var(--z-overlay);
  min-width: 190px;
  padding: 5px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: menu-in var(--t-fast) var(--ease-out);
}

@keyframes menu-in {
  from { opacity: 0; transform: scale(0.97); }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: var(--text-base);
  color: var(--text-dim);
  text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
}

.menu-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }

.menu-item .spacer { flex: 1; }

.menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border);
}

/* ---------------------------------------------------------------------------- toasts */
#toasts {
  position: fixed;
  z-index: var(--z-toast);
  left: 50%;
  bottom: 24px;
  translate: -50% 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: min(440px, 92vw);
  padding: 10px 14px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  pointer-events: auto;
  animation: toast-in var(--t-base) var(--ease-out);
}

.toast.leaving { animation: toast-out var(--t-base) var(--ease) forwards; }
.toast.error   { border-color: var(--danger); color: var(--danger); }
.toast.success .toast-icon { color: var(--success); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px) scale(0.97); }
}

@media (max-width: 900px) {
  #toasts { bottom: calc(var(--bottomnav-h) + 76px); }
}

/* ---------------------------------------------------------------------------- tables */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-faint);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:last-child td { border-bottom: none; }

.table-wrap {
  overflow-x: auto;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
}

/* -------------------------------------------------------------------------- skeleton */
.skeleton {
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

@keyframes shimmer {
  from { background-position: 100% 50%; }
  to   { background-position: 0 50%; }
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
  flex: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ----------------------------------------------------------------------- empty state */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 64px 20px;
  text-align: center;
  color: var(--text-faint);
}

.empty-icon {
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-faint);
}

.empty h3 { color: var(--text-dim); font-size: var(--text-md); font-weight: 600; }
.empty p { max-width: 380px; font-size: var(--text-sm); }

/* ------------------------------------------------------------------------- wizard */
/* Creation asks one question per step. Each step gets room to breathe rather than
   being one row in a tall form. */
.wizard-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 150px;
}

.wizard-head h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.wizard-head p { margin-top: 3px; }

.input-lg {
  height: 46px;
  font-size: var(--text-md);
  padding: 10px 13px;
}

.wizard-dots {
  display: flex;
  align-items: center;
  gap: 6px;
}

.wizard-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  transition: background var(--t-fast), width var(--t-fast) var(--ease);
}

.wizard-dot.done { background: var(--accent-soft); }

.wizard-dot.active {
  width: 18px;
  background: var(--accent);
}

.wizard-optional summary {
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-faint);
  list-style: none;
}

.wizard-optional summary::-webkit-details-marker { display: none; }
.wizard-optional summary::before { content: "＋ "; }
.wizard-optional[open] summary::before { content: "－ "; }

/* --------------------------------------------------------------------- folder picker */
.folder-picker {
  max-height: 300px;
  overflow-y: auto;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 4px;
}

.folder-pick {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: var(--text-dim);
  font-size: var(--text-base);
  text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
}

.folder-pick:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.folder-pick.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 550;
}

.folder-pick-icon {
  display: grid;
  place-items: center;
  width: 20px;
  font-size: 15px;
  flex: none;
  color: var(--accent);
}
