/* =========================================================================
   P2P Call — design tokens
   A console / two-way-radio inspired theme: warm charcoal surfaces,
   an amber "signal" accent, IBM Plex Mono for callsigns & status,
   IBM Plex Sans for body copy. The recurring signature motif is a row
   of animated signal bars and a pulsing "dial ring".
   ========================================================================= */

:root {
  --bg: #15191c;
  --surface: #1d2226;
  --surface-raised: #262c30;
  --border: #343b40;

  --text: #ece8e1;
  --text-muted: #8b9197;

  --accent: #ff9f40;
  --accent-soft: rgba(255, 159, 64, 0.16);
  --accent-ink: #1a1410;

  --online: #6fcf97;
  --busy: #e2574c;
  --danger: #e2574c;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 18px;

  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-body: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
}

.muted {
  color: var(--text-muted);
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* =========================================================================
   Signature element — signal bars
   ========================================================================= */

.bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
}

.bars span {
  display: block;
  width: 4px;
  background: var(--accent);
  border-radius: 2px;
  transform-origin: bottom;
  animation: barPulse 1.2s ease-in-out infinite;
}

.bars-lg span {
  height: 28px;
}

.bars-md span {
  height: 20px;
}

.bars span:nth-child(1) { animation-delay: 0s; }
.bars span:nth-child(2) { animation-delay: 0.15s; }
.bars span:nth-child(3) { animation-delay: 0.3s; }
.bars span:nth-child(4) { animation-delay: 0.45s; }
.bars span:nth-child(5) { animation-delay: 0.6s; }

@keyframes barPulse {
  0%, 100% { transform: scaleY(0.35); }
  50% { transform: scaleY(1); }
}

/* =========================================================================
   Screens
   ========================================================================= */

.screen {
  min-height: 100vh;
  width: 100%;
}

/* =========================================================================
   Login screen
   ========================================================================= */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% -10%, rgba(255, 159, 64, 0.08), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.login-card .bars {
  justify-content: center;
  margin: 0 auto 22px;
}

.wordmark {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.2em;
  margin: 0 0 10px;
  color: var(--text);
}

.tagline {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 28px;
}

#login-form {
  text-align: left;
}

.field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.field-label.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  text-transform: none;
  letter-spacing: normal;
  font-family: var(--font-sans);
  font-size: 14px;
  cursor: pointer;
}

.field-label.checkbox input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

#username-input,
#password-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  font-family: var(--font-mono);
  font-size: 15px;
  color: var(--text);
  margin-bottom: 18px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#username-input::placeholder,
#password-input::placeholder {
  color: var(--text-muted);
}

#username-input:focus,
#password-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 16px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-primary:active {
  transform: scale(0.99);
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin: 14px 0 0;
}

.fine-print {
  color: var(--text-muted);
  font-size: 12px;
  margin: 20px 0 0;
}

/* =========================================================================
   App screen — top bar
   ========================================================================= */

#app-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  flex-direction: column;
  padding: 12px 20px;
  border-bottom: 1px solid var(--accent-soft);
  background: var(--surface);
  flex-shrink: 0;
  gap: 8px;
}

.topbar-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.topbar-row2 {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 0;
}

.topbar-row2:not(:has(button:not(.hidden))) {
  display: none;
}

.topbar-identity {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  flex-shrink: 0;
}

#current-username {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.current-user-username {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.85;
}

.version-badge {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  user-select: none;
  padding: 0 4px;
}

.topbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 120px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: background 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.topbar-btn:hover {
  background: var(--accent-hover, #ffae5c);
}

.topbar-btn-icon {
  font-size: 14px;
  line-height: 1;
}

.topbar-btn-text {
  line-height: 1;
}

.topbar-btn--icon {
  width: 32px;
  padding: 0;
}

.btn-icon {
  padding: 6px 8px;
  font-size: 15px;
  line-height: 1;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-ghost:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

/* Status dot */

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot.online {
  background: var(--online);
  box-shadow: 0 0 0 3px rgba(111, 207, 151, 0.18);
}

.status-dot.busy {
  background: var(--busy);
  box-shadow: 0 0 0 3px rgba(226, 87, 76, 0.18);
}

/* =========================================================================
   App screen — layout
   ========================================================================= */

.main-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 374px;
  flex-shrink: 0;
  border-right: 1px solid var(--accent-soft);
  background: var(--surface);
  padding: 20px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

.contacts-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  margin-bottom: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 16px;
}

.panel-title-left {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-width: 0;
}

.panel-title-text {
  flex-shrink: 0;
}

.panel-title .count {
  color: var(--accent);
  flex-shrink: 0;
}

#user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

#user-list.hidden {
  display: none !important;
}

.user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface-raised);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  font-size: 13px;
  min-height: 36px;
  cursor: pointer;
  box-sizing: border-box;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.user-item:hover {
  border-color: var(--accent);
}

.user-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  min-width: 0;
  flex: 1;
}

.name-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}

.user-item-left .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.5;
}

.btn-call {
  background: transparent;
  border: 1px solid var(--online);
  color: var(--online);
  border-radius: var(--radius-sm);
  padding: 3px 5px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-call svg {
  display: block;
}

.btn-call:hover:not(:disabled) {
  background: var(--online);
  color: #0e2418;
}

.btn-call:disabled {
  border-color: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}

#empty-list-msg {
  font-size: 13px;
  line-height: 1.7;
  margin-top: 4px;
}

.contacts-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  gap: 12px;
  flex: 1;
}

.contacts-empty-icon {
  font-size: 32px;
  opacity: 0.6;
}

.panel-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 120px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: background 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.panel-add-btn:hover {
  background: var(--accent-hover, #ffae5c);
}

.panel-add-btn-icon {
  font-size: 14px;
  line-height: 1;
}

.panel-add-btn-text {
  line-height: 1;
}

.panel-title-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.contacts-hint-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.contacts-hint-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--accent-soft);
  background: transparent;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.contacts-hint-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.contacts-hint-tooltip {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 240px;
  padding: 10px 12px;
  background: var(--surface-raised);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  z-index: 1000;
}

.context-menu {
  position: fixed;
  min-width: 220px;
  background: var(--surface-raised);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 1100;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 4px;
}

.context-menu-item {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.context-menu-item:hover,
.context-menu-item:focus {
  background: var(--accent-soft);
  color: var(--accent-ink);
  outline: none;
}

.context-menu-item.danger {
  color: var(--danger, #e2574c);
}

.context-menu-item.danger:hover,
.context-menu-item.danger:focus {
  background: rgba(226, 87, 76, 0.15);
  color: var(--danger, #e2574c);
}

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

.context-menu-cancel {
  color: var(--text-muted);
}

.delete-contact-warning {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0 0 16px;
}

.delete-contact-warning.danger {
  color: var(--danger, #e2574c);
}

/* =========================================================================
   Add contacts panel
   ========================================================================= */

#add-contacts-panel {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
}

#add-contacts-panel.hidden {
  display: none;
}

.add-contacts-panel-header h2 {
  margin: 0;
  font-size: 16px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.add-contacts-count {
  min-width: 28px;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: center;
}

.add-contacts-panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 16px 0;
  display: flex;
  flex-direction: column;
}

.add-contacts-controls,
.add-contacts-panel-body > .admin-user-list,
.add-contacts-panel-footer {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

.add-contacts-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.add-contacts-panel-body > .admin-user-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  flex-shrink: 0;
}

.add-contacts-controls .admin-search {
  flex: 1;
  margin-bottom: 0;
  max-width: none;
  border-color: var(--accent-soft);
}

.add-contacts-sort {
  background: var(--surface-raised);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 14px;
}

.add-contacts-sort:focus {
  border-color: var(--accent);
  outline: none;
}

.add-contacts-item.admin-user-item {
  position: relative;
  padding: 12px 40px 12px 14px;
  justify-content: flex-start;
  cursor: pointer;
  user-select: none;
  background: var(--surface-raised);
  border: 1px solid var(--accent-soft);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.add-contacts-item.admin-user-item:hover {
  background: var(--surface-raised);
  border-color: var(--accent);
}

.add-contacts-item.admin-user-item.selected {
  background: rgba(255, 159, 64, 0.12);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.add-contacts-item.admin-user-item::after {
  content: none;
}

.add-contacts-item.admin-user-item.selected::after {
  content: '✓';
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
}

.admin-user-info {
  min-width: 0;
  flex: 1;
}

.admin-user-name,
.admin-user-sub {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.add-contacts-empty {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.add-contacts-panel-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  padding: 16px 0;
  background: var(--bg);
  position: sticky;
  bottom: 0;
  margin-top: auto;
}

/* =========================================================================
   Manage channel panel
   ========================================================================= */

#manage-channel-modal.modal {
  padding: 0;
  align-items: stretch;
  justify-content: stretch;
  background: var(--bg);
}

.modal-content.modal-content-fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  background: var(--bg);
  border: none;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  text-align: left;
  box-shadow: none;
}

.manage-channel-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--accent-soft);
  background: var(--surface);
}

.manage-channel-header-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.manage-channel-header-row h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}

.manage-channel-header .add-contacts-count {
  flex-shrink: 0;
}

.manage-channel-body {
  flex: 1 1 auto;
  overflow: hidden;
  padding: 16px 16px 0;
  display: flex;
  flex-direction: column;
}

.manage-channel-name {
  flex-shrink: 0;
  margin: 0 0 16px;
}

.manage-channel-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

@media (min-width: 760px) {
  .manage-channel-body {
    align-items: center;
  }

  .manage-channel-body > .manage-channel-name,
  .manage-channel-body > .manage-channel-scroll {
    width: 100%;
    max-width: 960px;
  }
}

.manage-channel-name {
  margin: 0 0 16px;
  padding: 10px 12px;
  background: var(--surface-raised);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  word-break: break-all;
}

.manage-channel-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--accent-soft);
}

.manage-channel-section-add {
  border-bottom: none;
  margin-bottom: 0;
}

.manage-channel-section-title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

.manage-channel-section .manage-channel-search {
  display: block;
  width: 100%;
  max-width: none;
  margin-bottom: 12px;
}

.manage-channel-body .admin-user-list {
  margin-bottom: 0;
  max-width: none;
  width: 100%;
}

.manage-channel-members-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 760px) {
  .manage-channel-members-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.manage-channel-member {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--surface-raised);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-md);
  transition: background 0.15s ease, border-color 0.15s ease;
  min-width: 0;
  box-sizing: border-box;
}

.manage-channel-member:hover {
  background: var(--surface-raised);
  border-color: var(--accent);
}

.manage-channel-member-info {
  min-width: 0;
  flex: 1;
}

.manage-channel-member-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.manage-channel-member-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.manage-channel-member-owner {
  font-size: 12px;
  color: var(--accent);
  margin-left: 8px;
  flex-shrink: 0;
}

.manage-channel-member-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  padding: 4px 8px;
  flex-shrink: 0;
}

.manage-channel-member-remove:hover {
  color: var(--danger);
}

.manage-channel-add-list .add-contacts-item {
  position: relative;
  padding: 8px 40px 8px 10px;
  justify-content: flex-start;
  cursor: pointer;
  user-select: none;
  background: var(--surface-raised);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-md);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.manage-channel-add-list .add-contacts-item:hover {
  border-color: var(--accent);
}

.manage-channel-add-list .add-contacts-item.selected {
  background: rgba(255, 159, 64, 0.12);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.manage-channel-add-list .add-contacts-item::after {
  content: none;
}

.manage-channel-add-list .add-contacts-item.selected::after {
  content: '✓';
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
}

.manage-channel-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  padding: 16px;
  border-top: 1px solid var(--accent-soft);
  flex-wrap: wrap;
  background: var(--bg);
}

.manage-channel-footer .btn-decline {
  margin-right: auto;
}

.manage-channel-footer .btn-primary-sm {
  margin-left: auto;
}

/* =========================================================================
   Call area — idle state
   ========================================================================= */

.call-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  padding: 24px;
  min-height: 0;
  gap: 16px;
}

.call-area-top {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
}

.idle-state {
  text-align: center;
}

.idle-title {
  font-family: var(--font-mono);
  font-size: 15px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text);
  margin: 26px 0 8px;
}

.idle-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0;
}

/* Dial ring — pulsing circle used for idle state, video placeholder & ringing */

.dial-ring {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dial-ring::before,
.dial-ring::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid var(--accent);
  opacity: 0;
  animation: ringPulse 3s ease-out infinite;
}

.dial-ring::after {
  animation-delay: 1.5s;
}

.dial-ring.small {
  width: 88px;
  height: 88px;
}

.dial-ring.ringing {
  width: 96px;
  height: 96px;
}

.dial-ring.ringing::before,
.dial-ring.ringing::after {
  border-color: var(--online);
  animation-duration: 1.6s;
}

.dial-ring.ringing::after {
  animation-delay: 0.8s;
}

@keyframes ringPulse {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(1.7); opacity: 0; }
}

/* =========================================================================
   Call area — active call state
   ========================================================================= */

.call-state {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.video-grid {
  flex: 1;
  position: relative;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--accent-soft);
  min-height: 0;
}

.remote-videos {
  width: 100%;
  height: 100%;
  display: grid;
  gap: 6px;
  overflow: auto;
}

.remote-tile {
  position: relative;
  min-height: 90px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
  cursor: pointer;
}

/* =========================================================================
   Режим "увеличения" плитки: одна большая + полоса миниатюр снизу
   ========================================================================= */

.focus-stage {
  position: absolute;
  inset: 0;
  bottom: 104px;
}

.focus-stage .remote-tile {
  position: absolute;
  inset: 0;
  min-height: 0;
  cursor: default;
}

.filmstrip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 96px;
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 6px;
  overflow-x: auto;
  background: rgba(0, 0, 0, 0.35);
}

.filmstrip .remote-tile {
  position: relative;
  flex: 0 0 128px;
  height: 100%;
  min-height: 0;
  border-radius: var(--radius-sm);
}

.btn-return-grid {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 5;
  background: rgba(10, 12, 14, 0.65);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-return-grid:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.remote-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

.video-wrapper.remote {
  width: 100%;
  height: 100%;
  position: relative;
}

.video-wrapper.remote video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
}

.video-wrapper.local {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 180px;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  background: var(--surface-raised);
}

.video-wrapper.local video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scaleX(-1); /* mirror, like a mirror/selfie view */
}

.video-label {
  position: absolute;
  bottom: 10px;
  left: 12px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  font-size: 12px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
  pointer-events: none;
}

/* ---- Управление громкостью участника в сайдбаре ---- */

/* Карточка участника, который сейчас в звонке вместе с тобой */
.user-item--in-call {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

/* Верхняя строка: имя + кнопка — flex-row внутри колонки */
.user-item--in-call > .user-item-left {
  /* уже flex-row по умолчанию */
}
.user-item--in-call > .btn-call {
  align-self: flex-start;
}

/* Строка с регулятором громкости */
.user-vol-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
}

.user-vol-mute {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  opacity: 0.8;
  transition: opacity 0.12s, transform 0.12s;
}
.user-vol-mute:hover  { opacity: 1; transform: scale(1.15); }
.user-vol-mute.is-muted { opacity: 0.5; }

.user-vol-slider {
  flex: 1;
  min-width: 0;
  height: 3px;
  cursor: pointer;
  accent-color: var(--accent, #2563eb);
}

.video-wrapper.local .video-label {
  font-size: 10px;
  bottom: 6px;
  left: 6px;
  padding: 2px 7px;
}

/* Call controls */

.call-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding-bottom: 4px;
  flex-shrink: 0;
}

.control-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.control-btn:hover {
  border-color: var(--accent);
}

.control-btn.hangup {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.control-btn.hangup svg {
  transform: rotate(135deg);
}

.control-btn.hangup:hover {
  filter: brightness(1.1);
}

.control-btn .strike {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.control-btn.off {
  color: var(--text-muted);
}

.control-btn.off .strike::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 10%;
  right: 10%;
  height: 2px;
  background: var(--danger);
  transform: translateY(-50%) rotate(-45deg);
  border-radius: 2px;
}

/* =========================================================================
   Сайдбар: секции "Контакты" и "Каналы"
   ========================================================================= */

.sidebar-section {
  /* базовый контейнер секции; верхняя граница и отступ задаются отдельно для каналов */
}

.channels-section {
  padding-top: 12px;
  border-top: 1px solid var(--accent-soft);
  display: flex;
  flex-direction: column;
  max-height: 50%;
  min-height: 120px;
}

.btn-mini {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  width: 22px;
  height: 22px;
  line-height: 1;
  font-size: 14px;
  cursor: pointer;
  margin-left: 8px;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-mini:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#channel-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-raised);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
}

.channel-item:hover {
  border-color: var(--accent);
}

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

/* Третий статус кружка - "в звонке", чтобы не путать с офлайн/онлайн */
.status-dot.in-call {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Значки непрочитанного - у участников (личные чаты) и у каналов */

.badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--online);
  color: #0e2418;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 999px;
  margin-left: 4px;
}

.badge-missed-call {
  background: var(--online);
}

.badge-icon {
  font-size: 11px;
  transform: rotate(100deg);
  display: inline-block;
}

.badge-channel-unread {
  flex-shrink: 0;
  color: var(--online);
  font-size: 13px;
}

/* =========================================================================
   Чат-док
   ========================================================================= */

.chat-dock {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 320px;
}

.chat-dock.collapsed {
  height: 48px;
}

.chat-dock-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--accent-soft);
  flex-shrink: 0;
}

.chat-dock.collapsed .chat-dock-header {
  border-bottom: none;
}

.chat-dock-title {
  font-size: 13px;
  letter-spacing: 0.04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-dock-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.chat-dock-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
}

.chat-empty-hint {
  margin: auto;
  font-size: 13px;
  text-align: center;
}

.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  margin-bottom: 2px;
  border-radius: 12px;
  padding: 6px 10px;
  position: relative;
}

/* Группировка: последующие сообщения от того же автора — максимально близко. */
.chat-message.chat-message-follow-up {
  margin-top: 0;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

/* Начало нового блока от другого автора — заметный отступ сверху. */
.chat-message + .chat-message:not(.chat-message-follow-up) {
  margin-top: 12px;
}

.chat-message.own {
  align-self: flex-end;
  background: rgba(255, 159, 64, 0.18);
  border-bottom-right-radius: 4px;
}

.chat-message.other {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border-bottom-left-radius: 4px;
}

.chat-message .chat-message-author {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 2px;
}

.chat-message .chat-message-body {
  white-space: pre-wrap;
}

.chat-message-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-message-time {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
  margin-top: 2px;
  align-self: flex-end;
}

.chat-message .chat-message-delete {
  position: absolute;
  top: 2px;
  right: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  opacity: 0.35;
}

.chat-message:hover .chat-message-delete,
.chat-message .chat-message-delete:focus-visible {
  opacity: 1;
}

.chat-message .chat-message-delete:hover {
  color: var(--danger);
}

.chat-message-call {
  justify-content: center;
  text-align: center;
  padding: 2px 0;
  background: transparent;
  max-width: 100%;
}

.chat-message-call-text {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* время сообщения — под текстом, вправо, уменьшенное и полупрозрачное */


.chat-load-more {
  align-self: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  margin-bottom: 6px;
}

.chat-load-more:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  min-width: 0;
}

.chat-input-row input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
}

.chat-input-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary-sm {
  width: auto;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-md);
  padding: 9px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-primary-sm:hover {
  filter: brightness(1.08);
}

/* =========================================================================
   Модалки создания/управления каналом
   ========================================================================= */

.modal-content-wide {
  max-width: 420px;
  width: 100%;
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: left;
}

.modal-content-wide .incoming-label {
  text-align: center;
}

.modal-content-wide input[type="text"],
.modal-content-wide input[type="password"],
.modal-content-wide #create-channel-name {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  margin: 0 0 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.modal-content-wide input[type="text"]:focus,
.modal-content-wide input[type="password"]:focus,
.modal-content-wide #create-channel-name:focus {
  border-color: var(--accent);
  outline: none;
}

.modal-content-wide .field-label {
  margin-bottom: 6px;
}

.checkbox-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  padding: 4px 0;
}

/* =========================================================================
   Incoming call modal
   ========================================================================= */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 14, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  backdrop-filter: blur(4px);
  padding: 24px;
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.avatar-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
  color: var(--online);
}

.incoming-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 22px 0 6px;
}

.caller-name {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 26px;
  overflow-wrap: anywhere;
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.btn-accept,
.btn-decline {
  flex: 1;
  border-radius: var(--radius-md);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: filter 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-accept {
  background: var(--online);
  border: none;
  color: #0e2418;
}

.btn-accept:hover {
  filter: brightness(1.08);
}

.btn-decline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.btn-decline:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger {
  flex: 1;
  border-radius: var(--radius-md);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: filter 0.15s ease;
  background: var(--danger);
  border: none;
  color: #fff;
}

.btn-danger:hover {
  filter: brightness(1.08);
}

/* =========================================================================
   Tooltip
   ========================================================================= */

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 1002;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tooltip.hidden {
  display: none;
}

/* =========================================================================
   Toast
   ========================================================================= */

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 1001;
  max-width: 90%;
  text-align: center;
}

/* =========================================================================
   Responsive
   ========================================================================= */

/* ---- Mobile tab bar ---- */
.mobile-tabs {
  display: none;
}

@media (max-width: 760px) {
  /* Tab bar */
  .mobile-tabs {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--surface);
    border-top: 1px solid var(--accent-soft);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.35);
    z-index: 200;
  }

  .mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 10px;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 0 4px;
    transition: color 0.15s;
  }

  .mobile-tab.active {
    color: var(--accent);
  }

  /* Adjust layout for tab bar height */
  #app-screen {
    padding-bottom: 56px;
  }

  /* Panels: positioned absolutely so only one is visible */
  .main-layout {
    position: relative;
    overflow: hidden;
  }

  .sidebar {
    position: absolute;
    inset: 0;
    width: 100%;
    max-height: none;
    border-right: none;
    border-bottom: none;
    display: none;
    overflow-y: auto;
    z-index: 1;
  }

  .call-area {
    position: absolute;
    inset: 0;
    width: 100%;
    display: none;
    z-index: 1;
    padding: 24px 24px 0 24px; /* убираем нижний padding, чтобы контент прилегал к подсказке/панели вкладок */
  }

  /* Tab states */
  #app-screen.mob-contacts .sidebar { display: flex; flex-direction: column; }

  #app-screen.mob-chat .call-area {
    display: flex;
    flex-direction: column;
    bottom: 22px; /* 20px hint + 1px gap сверху + 1px gap снизу; табы учтены padding-bottom у #app-screen */
  }
  #app-screen.mob-chat #call-area-top { display: none !important; }
  #app-screen.mob-call .call-area { display: flex; flex-direction: column; }
  #app-screen.mob-call .chat-dock { display: none !important; }

  /* Hide idle-state on mobile — useless placeholder */
  #idle-state { display: none !important; }

  /* Mobile header: name on its own first line, actions + version on second line.
     Layout of second line: [Profile] [Management] ............ [version][Logout] */
  .topbar {
    padding: 10px 14px;
  }
  .topbar-main {
    flex-wrap: wrap;
  }
  .topbar-identity {
    flex: 0 0 100%;
    max-width: 100%;
  }
  #current-username {
    max-width: none;
  }
  .current-user-username {
    font-size: 9px;
  }
  .topbar-actions {
    flex: 0 0 100%;
    gap: 6px;
    justify-content: flex-start;
  }
  .version-badge {
    font-size: 9px;
    padding: 0 2px;
    margin-left: auto;
    margin-right: 0;
  }
  .btn-ghost {
    padding: 5px 8px;
    font-size: 12px;
  }
  .btn-icon {
    padding: 5px 6px;
    font-size: 14px;
  }

  /* Chat dock takes remaining height on chat tab */
  #app-screen.mob-chat .chat-dock {
    flex: 1;
    height: auto;
  }
  #app-screen.mob-chat .chat-dock.collapsed {
    flex: none;
    height: 44px;
  }

  .video-wrapper.local {
    width: 96px;
  }

  .remote-videos {
    gap: 4px;
  }

  .focus-stage {
    bottom: 84px;
  }

  .filmstrip {
    height: 76px;
  }

  .filmstrip .remote-tile {
    flex: 0 0 96px;
  }

  .login-card {
    padding: 32px 24px;
  }
}

/* =========================================================================
   Reduced motion
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
  .bars span,
  .dial-ring::before,
  .dial-ring::after {
    animation: none !important;
  }
}
/* =========================================================================
   Mobile: кнопка "Назад" в чате и подсказка свайпа
   ========================================================================= */

/* Кнопка "Назад" — показывается только в мобильном чате */
#chat-mobile-back {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 32px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-md);
  color: var(--accent-ink);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  z-index: 25;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: filter 0.15s;
}

#chat-mobile-back .chat-back-arrow {
  display: block;
  transform: translateY(-1px);
}

#chat-mobile-back:active {
  filter: brightness(0.95);
}

.chat-dock-header {
  position: relative;
  padding-left: 60px !important;
}


/* =========================================================================
   Изображения в чате
   ========================================================================= */

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 6px 8px;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chat-message-image .chat-message-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-message-image-thumb {
  max-width: 260px;
  max-height: 260px;
  width: auto;
  height: auto;
  border-radius: var(--radius-md);
  cursor: pointer;
  object-fit: cover;
  border: 1px solid var(--border);
}

.chat-image-preview {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
}

.chat-image-preview.hidden {
  display: none;
}

.chat-image-preview-wrap {
  position: relative;
  display: inline-flex;
  padding: 3px;
  border-radius: calc(var(--radius-sm) + 3px);
}

.chat-image-preview-wrap img {
  position: relative;
  z-index: 1;
  max-width: 80px;
  max-height: 80px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  display: block;
}

.chat-image-progress {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--radius-sm) + 3px);
  background: conic-gradient(var(--accent) calc(var(--progress, 0) * 1%), transparent 0);
  z-index: 0;
}

.chat-image-progress.pending {
  background: conic-gradient(var(--accent) 0% 30%, transparent 30% 100%);
  animation: chat-progress-spin 1s linear infinite;
}

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

.chat-image-progress.hidden {
  display: none;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.image-lightbox.hidden {
  display: none;
}

.image-lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.image-lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  font-size: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
}

@media (max-width: 759px) {
  .chat-message {
    max-width: 92%;
    font-size: 13px;
  }

  .chat-message .chat-message-author {
    font-size: 10px;
  }

  .chat-message-image-thumb {
    max-width: 200px;
    max-height: 200px;
  }

  .chat-input-row {
    gap: 6px;
    padding: 8px 10px;
  }

  .chat-input-row input {
    padding: 8px 10px;
  }

  .btn-primary-sm {
    padding: 8px 12px;
    font-size: 11px;
  }

  .btn-icon {
    padding: 5px 6px;
    font-size: 16px;
  }

  .user-item-left {
    font-size: 13px;
  }

  /* Шапка: на мобильных кнопки — только иконки, чтобы не было горизонтальной прокрутки */
  .topbar {
    padding: 10px 12px;
  }

  .topbar-actions {
    gap: 4px;
  }

  .topbar-btn {
    width: 32px;
    padding: 0;
  }

  .topbar-btn-text {
    display: none;
  }
}

/* =========================================================================
   Профиль и админ-панель
   ========================================================================= */

.profile-readonly-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.profile-readonly-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.profile-readonly-value {
  font-size: 16px;
  color: var(--text);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-field input,
.form-field textarea,
.form-field select {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  border-color: var(--accent);
  outline: none;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.required {
  color: var(--danger);
}

@media (max-width: 759px) {
  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .modal-content-wide {
    max-width: none;
    width: calc(100% - 24px);
    margin: 12px;
    padding: 20px;
  }

}

#admin-panel {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

#admin-panel.hidden {
  display: none;
}

/* =========================================================================
   Панель редактирования профиля
   ========================================================================= */

#profile-modal {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

#profile-modal.hidden {
  display: none;
}

.profile-panel-header {
  flex: 0 0 auto;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--accent-soft);
  background: var(--surface);
}

.profile-panel-header h2 {
  margin: 0;
  font-size: 16px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.profile-panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
}

.profile-panel-body .profile-readonly-row {
  border-bottom-color: var(--accent-soft);
}

.profile-panel-body .form-field {
  gap: 4px;
  margin-bottom: 12px;
}

.profile-panel-body .form-field:last-child {
  margin-bottom: 0;
}

.profile-panel-body .field-label {
  margin-bottom: 4px;
}

.profile-panel-body .form-field input[type="text"],
.profile-panel-body .form-field input[type="password"] {
  border-color: var(--accent-soft);
}

.profile-panel-body .form-field input[type="text"]:focus,
.profile-panel-body .form-field input[type="password"]:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.profile-section-divider {
  height: 1px;
  background: var(--accent-soft);
  margin: 20px 0 16px;
  box-shadow: 0 0 6px var(--accent-soft);
}

.profile-section-title {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.profile-panel-footer {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--accent-soft);
  background: var(--surface);
}

@media (min-width: 760px) {
  .profile-panel-body {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .profile-panel-body > * {
    width: 100%;
    max-width: 600px;
  }

  .profile-panel-footer {
    justify-content: center;
  }

  .profile-panel-footer > * {
    width: 100%;
    max-width: 600px;
  }
}

@media (max-width: 759px) {
  .profile-panel-header {
    padding: 10px 12px;
    gap: 8px;
  }

  .profile-panel-header h2 {
    font-size: 14px;
  }

  .profile-panel-body {
    padding: 12px;
  }

  .profile-panel-body .form-row {
    grid-template-columns: 1fr;
  }

  .profile-panel-footer {
    padding: 12px;
  }
}

.admin-panel-header {
  flex: 0 0 auto;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.admin-panel-header h2 {
  margin: 0;
  font-size: 16px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-panel-header .btn-primary-sm {
  flex-shrink: 0;
}

.add-user-btn-short {
  display: none;
}

.add-user-btn-long {
  display: inline;
}

.admin-panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
}

.admin-search {
  width: 100%;
  max-width: 400px;
  padding: 10px 12px;
  margin-bottom: 16px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
}

.admin-user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 600px;
}

.admin-user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.admin-user-item:hover {
  background: var(--surface-raised);
  border-color: var(--accent);
}

.admin-user-item::after {
  content: '›';
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
}

.admin-user-name {
  font-weight: 600;
  font-size: 15px;
}

.admin-user-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

@media (max-width: 759px) {
  .admin-user-name {
    font-size: 13px;
  }

  .admin-user-sub {
    font-size: 11px;
  }
}

label.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  cursor: pointer;
}

label.checkbox input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* Mobile admin panel tweaks */
@media (max-width: 759px) {
  .admin-panel-header {
    padding: 10px 12px;
    gap: 8px;
  }
  .admin-panel-header h2 {
    font-size: 14px;
  }
  .admin-panel-header .btn-primary-sm {
    padding: 4px 8px;
    font-size: 13px;
    min-width: 28px;
  }
  .admin-panel-body {
    padding: 12px;
  }
  .admin-user-item {
    padding: 10px 12px;
  }
  .add-user-btn-short {
    display: inline;
  }
  .add-user-btn-long {
    display: none;
  }
}

/* Desktop: центрируем содержимое панелей, чтобы карточки не тянулись на пол-экрана */
@media (min-width: 760px) {
  .admin-panel-body {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .add-contacts-panel-body {
    align-items: center;
  }

  .add-contacts-panel-body > .admin-user-list {
    grid-template-columns: 1fr 1fr;
  }

  .add-contacts-controls,
  .add-contacts-panel-body > .admin-user-list,
  .add-contacts-panel-footer {
    max-width: 960px;
  }
}
