/* =========================================================
   Devi — dashboard styles
   Loaded after style.css and built on its tokens (--bg, --surface,
   --accent …) and components (.btn, .ghost-btn, .picker, .topbar),
   so both themes work without any extra switch.
   ========================================================= */

:root {
  color-scheme: dark;
  --danger: #ff8a98;
  --danger-soft: rgba(255, 138, 152, 0.14);
  --warn: #ffcb7a;
}

:root[data-theme="light"] {
  color-scheme: light;
  --danger: #c1243a;
  --danger-soft: rgba(193, 36, 58, 0.09);
  --warn: #8a5200;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --danger: #c1243a;
    --danger-soft: rgba(193, 36, 58, 0.09);
    --warn: #8a5200;
  }
}

[hidden] { display: none !important; }

button { font: inherit; }

/* ---------- top bar additions ---------- */

.brand__slash { stroke: var(--accent-ink); }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}
.user-chip__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
}
.user-chip__name {
  max-width: 14ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-muted);
}
.logout { margin: 0; }
.logout__btn { white-space: nowrap; }
.logout__icon { display: none; }

.footer--slim { padding: 22px 0 26px; }
.footer--slim .footer__note {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
.footer__links { display: inline-flex; flex-wrap: wrap; gap: 18px; }
.footer__links a { color: inherit; text-decoration: none; }
.footer__links a:hover { color: var(--accent); }

/* ---------- buttons ---------- */

.btn--sm { padding: 7px 14px; font-size: 0.86rem; }

.btn--danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
  background: transparent;
}
.btn--danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.btn--danger.is-armed { background: var(--danger); border-color: var(--danger); color: var(--bg); }

.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn--solid[disabled]:hover { background: var(--accent); }
.btn--line[disabled]:hover { border-color: var(--line); color: var(--ink); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--ink-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.16s ease, border-color 0.16s ease;
}
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- page shell (servers, messages) ---------- */

.page { padding-block: clamp(32px, 5vw, 56px) clamp(56px, 8vw, 96px); }
.page--center { min-height: 56vh; display: grid; align-content: center; }

.page__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 24px;
  margin-bottom: 32px;
}
.page__head h1 { font-size: clamp(1.7rem, 1.1rem + 2vw, 2.4rem); }
.page__lead { margin-top: 10px; color: var(--ink-muted); max-width: 58ch; }

.state {
  display: grid;
  justify-items: start;
  gap: 12px;
  max-width: 56ch;
  padding: clamp(24px, 4vw, 40px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.state h1,
.state h2 { font-size: clamp(1.3rem, 1rem + 1vw, 1.7rem); }
.state p { color: var(--ink-muted); }
.state__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

.guild-icon {
  flex: none;
  border-radius: 14px;
  object-fit: cover;
  background: var(--surface-2);
}
.guild-icon--md { width: 48px; height: 48px; }
.guild-icon--sm { width: 40px; height: 40px; border-radius: 12px; }
.guild-icon--fallback {
  display: grid;
  place-items: center;
  border: 1px solid var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  font-family: "Unbounded", "Golos Text", sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
}

.server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.server-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color 0.18s ease;
}
.server-card:hover { border-color: var(--accent-line); }

.server-card__body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 6px;
  justify-items: start;
}
.server-card__name {
  display: -webkit-box;
  max-width: 100%;
  overflow: hidden;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
  text-decoration: none;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
a.server-card__name:focus-visible { outline: none; }
a.server-card__name:focus-visible::after { outline: 2px solid var(--accent); outline-offset: 3px; }
a.server-card__name::after {  /* the whole card is the click target */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
}
.server-card__action { flex: none; padding: 8px 16px; font-size: 0.88rem; }
.server-card--quiet { background: transparent; }

.invite-block { margin-top: clamp(40px, 6vw, 64px); }
.invite-block h2 { font-size: 1.25rem; }
.invite-block .server-grid { margin-top: 22px; }

.tag {
  display: inline-flex;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-muted);
  font-size: 0.78rem;
  font-weight: 500;
}

/* ---------- dashboard layout ---------- */

.dash { padding-block: clamp(24px, 4vw, 44px) clamp(48px, 7vw, 88px); }

.dash__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-bottom: 28px;
}
.dash__back {
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-muted);
  font-size: 0.9rem;
  text-decoration: none;
  transition: color 0.16s ease, border-color 0.16s ease;
}
.dash__back:hover { color: var(--accent); border-color: var(--accent); }

.dash__guild { display: flex; align-items: center; gap: 14px; min-width: 0; }
.dash__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(1.25rem, 1rem + 1vw, 1.7rem);
}

.dash__body {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 36px;
  align-items: start;
}

.dash__nav {
  position: sticky;
  top: 90px;
  display: grid;
  gap: 4px;
}

.dash-tab {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 12px;
  color: var(--ink-muted);
  font-weight: 500;
  text-decoration: none;
  transition: color 0.16s ease, background-color 0.16s ease;
}
.dash-tab:hover { color: var(--ink); background: var(--surface); }
.dash-tab[aria-current="page"] {
  color: var(--ink);
  background: var(--surface);
  box-shadow: inset 3px 0 0 var(--accent);
}
.dash-tab__icon { width: 1.4em; text-align: center; }
.dash-tab__dot {
  width: 8px;
  height: 8px;
  margin-inline-start: auto;
  border-radius: 50%;
  background: var(--accent);
}

.dash__content { min-width: 0; }
.dash__content:focus { outline: none; }

/* ---------- panels ---------- */

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.panel + .panel { margin-top: 18px; }

.panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: clamp(20px, 3vw, 30px) clamp(20px, 3vw, 30px) 0;
}
.panel__title { font-size: clamp(1.15rem, 1rem + 0.6vw, 1.45rem); }
.panel__title:focus { outline: none; }
.panel__lead { margin-top: 10px; max-width: 62ch; color: var(--ink-muted); font-size: 0.96rem; }
.panel__body { display: grid; gap: 22px; padding: clamp(20px, 3vw, 30px); }
.panel__body--flush { gap: 0; margin-top: 22px; padding: 0; border-top: 1px solid var(--line-soft); }
.panel__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 16px clamp(20px, 3vw, 30px);
  border-top: 1px solid var(--line-soft);
}

.status {
  flex: none;
  padding: 3px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-muted);
  font-size: 0.82rem;
  font-weight: 600;
}
.status--on { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent); }

/* ---------- form controls ---------- */

.field { display: grid; gap: 8px; }
.field__label { font-size: 0.92rem; font-weight: 600; }
.field__hint { max-width: 62ch; color: var(--ink-muted); font-size: 0.86rem; }
.field__error { color: var(--danger); font-size: 0.88rem; }
.field__preview { color: var(--ink-muted); font-size: 0.86rem; }
.field__preview b { color: var(--ink); font-weight: 600; }
.field__row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 11rem); gap: 10px; }

.input,
.select,
.textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.input:hover,
.select:hover,
.textarea:hover { border-color: var(--accent-line); }
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[aria-invalid="true"],
.textarea[aria-invalid="true"] { border-color: var(--danger); }
.input[disabled],
.select[disabled] { opacity: 0.5; cursor: not-allowed; }
.input::placeholder,
.textarea::placeholder { color: var(--ink-muted); opacity: 0.8; }

.textarea { min-height: 46px; resize: vertical; line-height: 1.45; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 0.9rem; }

.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute;
  inset-inline-end: 17px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--ink-muted);
  border-bottom: 2px solid var(--ink-muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.select { appearance: none; padding-inline-end: 42px; cursor: pointer; }
.select option,
.select optgroup { background: var(--surface); color: var(--ink); }

.note {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink-muted);
  font-size: 0.9rem;
}
.note--warn {
  border-color: color-mix(in srgb, var(--warn) 45%, transparent);
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  color: var(--ink);
}

/* ---------- switches (permissions) ---------- */

.perm-group { display: grid; gap: 4px; }
.perm-group__title {
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink-muted);
  font-size: 0.86rem;
  font-weight: 600;
}

.perm {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 12px 8px;
  border-radius: 12px;
  cursor: pointer;
}
.perm:hover { background: var(--surface-2); }
.perm__text { flex: 1; min-width: 0; display: grid; gap: 3px; }
.perm__label { font-weight: 600; }
.perm__code { margin-inline-start: 8px; color: var(--ink-muted); font-size: 0.76rem; font-weight: 400; }
.perm__desc { color: var(--ink-muted); font-size: 0.88rem; }

.switch { position: relative; flex: none; width: 44px; height: 26px; margin-top: 1px; }
.switch input {
  appearance: none;
  position: absolute;
  inset: 0;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background-color 0.18s ease;
}
.switch input::before {
  content: "";
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.18s ease, background-color 0.18s ease;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::before { transform: translateX(18px); background: var(--accent-ink); }
.switch input:focus-visible { border-radius: 999px; outline-offset: 3px; }

/* ---------- permissions editor ---------- */

.perms { display: grid; grid-template-columns: 312px minmax(0, 1fr); }

.targets {
  display: grid;
  align-content: start;
  gap: 20px;
  padding: 18px;
  border-inline-end: 1px solid var(--line-soft);
}
.targets__group { display: grid; gap: 4px; }
.targets__title { padding: 0 10px 4px; color: var(--ink-muted); font-size: 0.82rem; font-weight: 600; }
.targets__empty { padding: 4px 10px; color: var(--ink-muted); font-size: 0.86rem; }
.targets__add { margin-top: 6px; }

.target {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  text-align: start;
  cursor: pointer;
  transition: background-color 0.16s ease;
}
.target:hover { background: var(--surface-2); }
.target[aria-pressed="true"] { border-color: var(--accent-line); background: var(--accent-soft); }
.target__icon { flex: none; width: 22px; text-align: center; }
.target__text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.target__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.target__sum { color: var(--ink-muted); font-size: 0.78rem; }
.target__dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.role-dot { flex: none; width: 10px; height: 10px; margin-inline: 6px; border-radius: 50%; background: var(--dot, var(--ink-muted)); }
.avatar-xs { flex: none; width: 22px; height: 22px; border-radius: 50%; object-fit: cover; background: var(--surface-2); }

.editor { display: grid; align-content: start; gap: 22px; padding: clamp(18px, 3vw, 28px); min-width: 0; }
.editor__head { display: grid; gap: 6px; }
.editor__title { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 1.1rem; font-weight: 600; }
.editor__title span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor__hint { color: var(--ink-muted); font-size: 0.9rem; }
.editor__empty { padding: 36px 8px; color: var(--ink-muted); text-align: center; }

.search { position: relative; }
.results {
  position: absolute;
  z-index: 20;
  inset-inline: 0;
  top: calc(100% + 6px);
  max-height: 260px;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.result {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  text-align: start;
  cursor: pointer;
}
.result:hover,
.result:focus-visible { background: var(--surface-2); }
.result__sub { margin-inline-start: auto; color: var(--ink-muted); font-size: 0.8rem; }
.results__note { padding: 10px 12px; color: var(--ink-muted); font-size: 0.88rem; }

.savebar {
  position: sticky;
  bottom: 16px;
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding: 12px 14px 12px 20px;
  border: 1px solid var(--accent-line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.savebar__text { font-size: 0.92rem; font-weight: 600; }
.savebar__actions { display: flex; gap: 8px; }

/* ---------- triggers ---------- */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.toolbar__search { flex: 1 1 240px; }
.toolbar__count { color: var(--ink-muted); font-size: 0.86rem; }

.trigger-list { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.trigger {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.trigger--editing,
.trigger--new { border-color: var(--accent-line); background: var(--surface); }

.trigger__row { display: grid; gap: 10px; padding: 16px 18px; }
.trigger__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.trigger__actions { display: flex; flex: none; gap: 8px; }
.trigger__preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink-muted);
  font-size: 0.92rem;
  white-space: pre-line;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.trigger__meta { color: var(--ink-muted); font-size: 0.8rem; }

.pattern {
  display: inline-block;
  max-width: 100%;
  padding: 3px 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  overflow-wrap: anywhere;
}

.trigger-form { display: grid; gap: 18px; padding: 18px; }
.trigger-form__actions { display: flex; flex-wrap: wrap; gap: 10px; }
.replies { display: grid; gap: 10px; }
.reply { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: start; }
.reply .textarea { min-height: 72px; }

.empty { padding: 28px 12px; color: var(--ink-muted); text-align: center; }
.empty__title { color: var(--ink); font-weight: 600; }

/* ---------- toasts and loading ---------- */

.toasts {
  position: fixed;
  inset-inline: 16px;
  bottom: 22px;
  z-index: 60;
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
}
.toast {
  max-width: min(520px, 100%);
  padding: 12px 18px;
  border: 1px solid var(--accent-line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.93rem;
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}
.toast--error { border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.skeleton { display: grid; gap: 14px; }
.skeleton__block {
  height: 120px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  animation: pulse 1.4s ease-in-out infinite;
}
.skeleton__block--title { height: 40px; width: 46%; }
.skeleton__block--short { height: 70px; width: 70%; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .dash__body { grid-template-columns: minmax(0, 1fr); gap: 20px; }

  .dash__nav {
    top: 66px;
    z-index: 8;
    display: flex;
    gap: 8px;
    margin-inline: -24px;
    padding: 10px 24px;
    overflow-x: auto;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(10px);
    scrollbar-width: none;
  }
  .dash__nav::-webkit-scrollbar { display: none; }
  .dash-tab { flex: none; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; }
  .dash-tab[aria-current="page"] {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-ink);
    box-shadow: none;
  }
  .dash-tab__dot { background: currentColor; }

  .perms { grid-template-columns: minmax(0, 1fr); }
  .targets { border-inline-end: 0; border-bottom: 1px solid var(--line-soft); }
}

@media (max-width: 640px) {
  .logout__icon { display: block; }
  .logout__text {  /* icon only on phones; the label stays available to screen readers */
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .logout__btn { padding: 8px 10px; }
  .perm__code { display: block; margin-inline-start: 0; }
  .user-chip__name { display: none; }
  .server-card { flex-wrap: wrap; }
  .server-card__action { width: 100%; }
  .panel__head { flex-wrap: wrap; }
  .trigger__top { flex-wrap: wrap; }
}
