/* ==========================================================================
   Rich Messages Bot — Design System v3
   Slate-Indigo · Mobile-First · Single-Page · Clean Professional Dark Theme
   ========================================================================== */

/* ── Google Fonts ── */
@import url("https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600&display=swap");

/* ══════════════════════════════════════════════
   CSS Custom Properties — Design Tokens
   ══════════════════════════════════════════════ */

:root {
  --font-primary:
    "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace;

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-full: 9999px;

  --transition-fast: 130ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 220ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 380ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 420ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Brand — Indigo palette */
  --indigo: hsl(234, 70%, 60%);
  --indigo-dim: hsl(234, 55%, 45%);
  --indigo-soft: hsl(234, 40%, 30%);
  --violet: hsl(258, 65%, 62%);
  --sky: hsl(204, 80%, 55%);
  --teal: hsl(172, 60%, 46%);
  --emerald: hsl(160, 60%, 44%);

  --accent: var(--indigo);
  --accent-gradient: linear-gradient(
    135deg,
    hsl(234, 70%, 60%) 0%,
    hsl(258, 65%, 62%) 100%
  );

  --success: hsl(142, 60%, 44%);
  --success-bg: hsla(142, 60%, 44%, 0.12);
  --warning: hsl(38, 85%, 52%);
  --warning-bg: hsla(38, 85%, 52%, 0.12);
  --danger: hsl(0, 70%, 58%);
  --danger-bg: hsla(0, 70%, 58%, 0.12);
  --info: hsl(204, 80%, 55%);
  --info-bg: hsla(204, 80%, 55%, 0.12);
}

/* ── Dark Theme (default) ── */
[data-theme="dark"],
:root {
  --bg-base: hsl(230, 22%, 7%);
  --bg-primary: hsl(230, 20%, 10%);
  --bg-secondary: hsl(230, 18%, 13%);
  --bg-tertiary: hsl(230, 16%, 17%);
  --bg-elevated: hsl(230, 18%, 15%);
  --bg-overlay: rgba(0, 0, 0, 0.65);

  --border-primary: rgba(255, 255, 255, 0.08);
  --border-secondary: rgba(255, 255, 255, 0.04);
  --border-accent: rgba(99, 102, 241, 0.35);
  --border-focus: hsl(234, 70%, 60%);

  --text-primary: hsl(220, 18%, 94%);
  --text-secondary: hsl(220, 12%, 58%);
  --text-tertiary: hsl(220, 10%, 40%);
  --text-inverse: hsl(230, 22%, 7%);
  --text-accent: var(--indigo);

  --scrollbar-track: hsl(230, 20%, 9%);
  --scrollbar-thumb: hsl(230, 16%, 22%);

  --code-bg: hsl(230, 22%, 8%);
  --code-border: rgba(255, 255, 255, 0.06);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.55);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.65);

  --nav-height: 58px;
  --bottom-nav-height: 62px;
}

/* ── Light Theme ── */
[data-theme="light"] {
  --bg-base: hsl(220, 22%, 96%);
  --bg-primary: hsl(220, 18%, 98%);
  --bg-secondary: hsl(220, 16%, 100%);
  --bg-tertiary: hsl(220, 14%, 93%);
  --bg-elevated: hsl(220, 16%, 100%);
  --bg-overlay: rgba(0, 0, 0, 0.4);

  --border-primary: rgba(0, 0, 0, 0.09);
  --border-secondary: rgba(0, 0, 0, 0.05);
  --border-accent: rgba(99, 102, 241, 0.3);
  --border-focus: var(--indigo);

  --text-primary: hsl(230, 30%, 13%);
  --text-secondary: hsl(230, 16%, 42%);
  --text-tertiary: hsl(230, 12%, 60%);
  --text-inverse: hsl(220, 22%, 96%);
  --text-accent: var(--indigo-dim);

  --scrollbar-track: hsl(220, 14%, 93%);
  --scrollbar-thumb: hsl(220, 12%, 78%);

  --code-bg: hsl(220, 16%, 93%);
  --code-border: rgba(0, 0, 0, 0.06);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.07);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.13);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.16);

  --accent: var(--indigo-dim);
  --accent-gradient: linear-gradient(
    135deg,
    hsl(234, 55%, 45%) 0%,
    hsl(258, 50%, 50%) 100%
  );
}

/* ══════════════════════════════════════════════
   Reset & Base
   ══════════════════════════════════════════════ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-primary);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-base);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* removed radial gradient for pure clean theme */

::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ══════════════════════════════════════════════
   App Shell
   ══════════════════════════════════════════════ */

.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ── Top Header ── */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  z-index: 100;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
}

.header-inner {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 var(--space-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.header-brand-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.header-brand-text span {
  color: var(--indigo);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* User Avatar */
.header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--border-primary);
  overflow: hidden;
  cursor: pointer;
  transition:
    border-color var(--transition-fast),
    opacity var(--transition-fast);
  flex-shrink: 0;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--indigo);
  position: relative;
}

.header-avatar:hover {
  border-color: var(--indigo);
  opacity: 0.85;
}
.header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.header-avatar .online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 7px;
  height: 7px;
  background: var(--success);
  border-radius: 50%;
  border: 1.5px solid var(--bg-primary);
}

/* ── Main ── */
.app-main {
  flex: 1;
  padding-top: var(--nav-height);
  padding-bottom: calc(var(--bottom-nav-height) + var(--space-md));
  position: relative;
  z-index: 1;
}

.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-md);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Ensure sections span full width when centered */
.page-container > section,
.page-container > div {
  width: 100%;
}

/* ── Bottom Navigation ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  z-index: 100;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 var(--space-sm);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  color: var(--text-tertiary);
  min-width: 60px;
  border: none;
  background: transparent;
  font-family: var(--font-primary);
}

.bottom-nav-item .nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-base);
}

.bottom-nav-item .nav-label {
  font-size: 0.67rem;
  font-weight: 500;
}

.bottom-nav-item.active {
  color: var(--indigo);
}
.bottom-nav-item.active .nav-icon {
  transform: translateY(-1px);
}
.bottom-nav-item:hover:not(.active) {
  color: var(--text-secondary);
}

/* Indicator dot for active item */
.bottom-nav-item.active::after {
  content: "";
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--indigo);
  margin: 0 auto;
  margin-top: 1px;
}

/* ── Pages (SPA) ── */
.page-view {
  display: none;
  animation: pageIn 0.25s ease-out;
}
.page-view.active {
  display: block;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ══════════════════════════════════════════════
   Typography
   ══════════════════════════════════════════════ */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.page-title {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
}

.gradient-text {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.text-sm {
  font-size: 0.875rem;
}
.text-xs {
  font-size: 0.78rem;
}
.text-secondary {
  color: var(--text-secondary);
}
.text-tertiary {
  color: var(--text-tertiary);
}
.text-accent {
  color: var(--indigo);
}

/* ══════════════════════════════════════════════
   Cards
   ══════════════════════════════════════════════ */

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  overflow: visible;
}

.card-header {
  padding: var(--space-md) var(--space-md);
  border-bottom: 1px solid var(--border-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  flex-wrap: wrap;
  cursor: default;
  border-radius: calc(var(--radius-lg) - 1px) calc(var(--radius-lg) - 1px) 0 0;
}

.keyboard-builder:not(:has(.kb-body.open)) .card-header {
  border-radius: calc(var(--radius-lg) - 1px);
}

.card-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.card-body {
  padding: var(--space-lg);
}
.card-body-sm {
  padding: var(--space-md);
}

/* ══════════════════════════════════════════════
   Buttons
   ══════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-family: var(--font-primary);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: -0.01em;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Primary */
.btn-primary {
  background: var(--accent-gradient);
  color: white;
  border-color: transparent;
}
.btn-primary:hover {
  filter: brightness(1.1);
}

/* Secondary */
.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-primary);
}
.btn-secondary:hover {
  background: var(--bg-elevated);
  border-color: var(--border-accent);
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-primary);
}
.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Danger */
.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: hsla(0, 70%, 58%, 0.2);
}
.btn-danger:hover {
  background: var(--danger);
  color: white;
}

/* Sizes */
.btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}
.btn-lg {
  padding: 11px 24px;
  font-size: 0.95rem;
  border-radius: var(--radius-lg);
}
.btn-icon {
  padding: 7px;
  width: 34px;
  height: 34px;
  justify-content: center;
  border-radius: var(--radius-md);
}
.btn-full {
  width: 100%;
  justify-content: center;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid var(--border-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--indigo);
}

/* ══════════════════════════════════════════════
   Form Elements
   ══════════════════════════════════════════════ */

.form-group {
  margin-bottom: var(--space-md);
}

.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  font-family: var(--font-primary);
  font-size: 0.9rem;
  color: var(--text-primary);
  transition:
    border-color var(--transition-fast),
    background var(--transition-fast);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.form-select option {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 10px;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-tertiary);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--indigo);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 3px hsla(234, 70%, 60%, 0.12);
}

.form-textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.5;
  font-family: inherit;
}

.form-textarea::-webkit-scrollbar {
  width: 12px;
}
.form-textarea::-webkit-scrollbar-track {
  background: transparent;
}
.form-textarea::-webkit-scrollbar-thumb {
  background-color: var(--border-primary);
  border-radius: 6px;
  border: 3px solid var(--bg-tertiary);
}
.form-textarea:focus::-webkit-scrollbar-thumb {
  border-color: var(--bg-elevated);
}
.form-textarea::-webkit-scrollbar-corner {
  background: transparent;
}
.form-textarea::-webkit-resizer {
  background-color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10 2L2 10' stroke='%236c7a89' stroke-width='1.5' stroke-linecap='round'/%3E%3Cpath d='M10 6L6 10' stroke='%236c7a89' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: 12px 12px;
  background-repeat: no-repeat;
  background-position: bottom 4px right 4px;
}

/* Custom Dropdown (for styled selects) */
.custom-dropdown {
  position: relative;
  width: 100%;
}

.custom-dropdown-value {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 42px;
  padding: 0 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all var(--transition-base);
  user-select: none;
}

.custom-dropdown.open .custom-dropdown-value {
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px hsla(234, 70%, 60%, 0.15);
}

.custom-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  background: var(--bg-elevated, var(--bg-secondary));
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-5px);
  transition: all var(--transition-base);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  padding: 6px 0;
}

.custom-dropdown.open .custom-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.custom-dropdown-menu.dropdown-up {
  top: auto;
  bottom: calc(100% + 6px);
  transform: translateY(5px);
}

.custom-dropdown.open .custom-dropdown-menu.dropdown-up {
  transform: translateY(0);
}

.custom-dropdown-item {
  padding: 10px 14px;
  margin: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.custom-dropdown-item:hover {
  background: hsla(234, 70%, 60%, 0.1);
}

.form-select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2360748a' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.form-hint {
  font-size: 0.76rem;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* ── Toggle Switch ── */
.toggle-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
  gap: var(--space-md);
}
.toggle-wrap:hover {
  background: var(--bg-elevated);
}

.toggle-info {
  flex: 1;
}
.toggle-info .toggle-label {
  font-size: 0.88rem;
  font-weight: 600;
}
.toggle-info .toggle-hint {
  font-size: 0.76rem;
  color: var(--text-tertiary);
}

.toggle {
  position: relative;
  width: 42px;
  height: 23px;
  flex-shrink: 0;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-primary);
  transition: all var(--transition-base);
  cursor: pointer;
}

.toggle input:checked + .toggle-track {
  background: var(--accent-gradient);
  border-color: transparent;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition-spring);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(19px);
}

/* ══════════════════════════════════════════════
   Badges & Chips
   ══════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-accent {
  background: hsla(234, 70%, 60%, 0.12);
  color: var(--indigo);
  border: 1px solid hsla(234, 70%, 60%, 0.25);
}
.badge-violet {
  background: hsla(258, 65%, 62%, 0.12);
  color: var(--violet);
  border: 1px solid hsla(258, 65%, 62%, 0.25);
}
.badge-success {
  background: var(--success-bg);
  color: var(--success);
}
.badge-warning {
  background: var(--warning-bg);
  color: var(--warning);
}
.badge-danger {
  background: var(--danger-bg);
  color: var(--danger);
}
.badge-neutral {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}
.badge-teal {
  background: hsla(172, 60%, 46%, 0.12);
  color: var(--teal);
  border: 1px solid hsla(172, 60%, 46%, 0.25);
}
.badge-sky {
  background: hsla(204, 80%, 55%, 0.12);
  color: var(--sky);
  border: 1px solid hsla(204, 80%, 55%, 0.25);
}

.mode-badge-rich_html {
  background: hsla(234, 70%, 60%, 0.1);
  color: var(--indigo);
  border: 1px solid hsla(234, 70%, 60%, 0.2);
}
.mode-badge-rich_markdown {
  background: hsla(258, 65%, 62%, 0.1);
  color: var(--violet);
  border: 1px solid hsla(258, 65%, 62%, 0.2);
}
.mode-badge-html {
  background: hsla(38, 85%, 52%, 0.1);
  color: var(--warning);
  border: 1px solid hsla(38, 85%, 52%, 0.2);
}
.mode-badge-markdownv2 {
  background: hsla(172, 60%, 46%, 0.1);
  color: var(--teal);
  border: 1px solid hsla(172, 60%, 46%, 0.2);
}

/* ══════════════════════════════════════════════
   Mode Selector
   ══════════════════════════════════════════════ */

.mode-selector {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  gap: 4px;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 3px;
  overflow-x: auto;
  scrollbar-width: none;
}
.mode-selector::-webkit-scrollbar {
  display: none;
}

.mode-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-primary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.mode-btn:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}
.mode-btn.active {
  background: var(--indigo);
  color: white;
}
/* Colored variant — used by Button Color selector */
#btn-color-selector .mode-btn.active {
  background: var(--mode-active-color, var(--indigo));
  color: white;
}
#btn-color-selector .mode-btn:hover:not(.active) {
  color: var(--mode-active-color, var(--text-primary));
}

/* ══════════════════════════════════════════════
   Toolbar with Dropdowns
   ══════════════════════════════════════════════ */

.toolbar {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  padding: var(--space-sm);
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  position: relative;
}

/* ── Loose Icon Groups ── */
.toolbar-icon-group {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-right: 4px;
}

.toolbar-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.toolbar-icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-primary);
}

/* ── Dropdown Group ── */
.toolbar-dropdown {
  position: static;
}

.toolbar-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  font-family: var(--font-primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-primary);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.toolbar-dropdown-btn:hover,
.toolbar-dropdown.open .toolbar-dropdown-btn {
  background: var(--bg-elevated);
  color: var(--indigo);
  border-color: var(--border-accent);
}

.toolbar-dropdown-btn svg {
  width: 13px;
  height: 13px;
}
.toolbar-dropdown-btn .chevron {
  width: 10px;
  height: 10px;
  transition: transform var(--transition-fast);
}
.toolbar-dropdown.open .chevron {
  transform: rotate(180deg);
}

/* Dropdown Menu — fixed positioned to avoid overflow clipping */
.toolbar-dropdown-menu {
  position: fixed;
  z-index: 500;
  background: var(--bg-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 4px;
  box-shadow: var(--shadow-lg);
  display: none;
  animation: dropdownIn 0.15s ease-out;
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-primary) transparent;
}

.toolbar-dropdown-menu::-webkit-scrollbar {
  width: 6px;
}
.toolbar-dropdown-menu::-webkit-scrollbar-track {
  background: transparent;
}
.toolbar-dropdown-menu::-webkit-scrollbar-thumb {
  background-color: var(--border-primary);
  border-radius: 3px;
}

.toolbar-dropdown.open .toolbar-dropdown-menu {
  display: grid;
  gap: 2px;
}

@keyframes dropdownIn {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ── Media source row inside dropdown ── */
.dropdown-source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  border: 1px solid var(--border-secondary);
  gap: var(--space-sm);
}

.dropdown-source-row i {
  color: var(--text-tertiary);
}

.dropdown-source-row .form-select {
  font-size: 0.72rem;
  padding: 4px 6px;
  background-color: var(--bg-primary);
  background-image: none;
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  flex: 1;
  font-weight: 600;
}

.dropdown-source-row .form-select:focus {
  border-color: var(--border-focus);
}
.toolbar-dropdown-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.toolbar-dropdown-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
.toolbar-dropdown-item svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.toolbar-divider {
  color: var(--border-primary);
  margin: 0 4px;
  font-size: 1.2rem;
  font-weight: 300;
  display: flex;
  align-items: center;
  user-select: none;
}

/* ══════════════════════════════════════════════
   Modal / Bottom Sheet
   ══════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  z-index: 300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
  padding: var(--space-md);
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-lg);
  width: 100%;
  max-width: 500px;
  max-height: 85dvh;
  overflow-y: auto;
  overflow-x: hidden;
  transform: translateY(32px);
  transition: transform var(--transition-spring);
  box-shadow: var(--shadow-xl);
}
.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-handle {
  width: 36px;
  height: 3px;
  background: var(--border-primary);
  border-radius: var(--radius-full);
  margin: 0 auto var(--space-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.modal-title {
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.modal-close:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

@media (min-width: 640px) {
  .modal {
    border-radius: var(--radius-xl);
    margin: auto;
  }
  .modal-overlay {
    align-items: center;
  }
}

@media (max-width: 480px) {
  :root {
    --space-md: 10px;
    --space-lg: 14px;
    --space-xl: 18px;
  }
  .page-container {
    padding-left: 6px;
    padding-right: 6px;
  }
  .card-header {
    padding: 10px 8px;
  }
  .card-body,
  .card-body-sm {
    padding-left: 8px;
    padding-right: 8px;
  }
  .app-header {
    padding: 10px 8px;
  }
  .section-title {
    font-size: 1.1rem;
  }
  .form-label {
    font-size: 0.75rem;
  }
  .btn {
    padding: 0 14px;
    font-size: 0.85rem;
  }
  .form-input {
    font-size: 0.9rem;
  }
  .toolbar {
    padding: 4px;
    gap: 2px;
  }
}

/* ══════════════════════════════════════════════
   Template Items
   ══════════════════════════════════════════════ */

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

.template-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast);
  gap: var(--space-sm);
}
.template-item:hover {
  border-color: var(--border-accent);
}

.template-info {
  flex: 1;
  min-width: 0;
}
.template-name {
  font-weight: 600;
  font-size: 0.88rem;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.template-meta {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.template-actions {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════════
   Inline Keyboard Builder — Classic Style
   ══════════════════════════════════════════════ */

.keyboard-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.keyboard-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.row-drag-handle {
  color: var(--text-tertiary);
  cursor: grab;
  padding: 4px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}
.row-drag-handle:hover {
  color: var(--indigo);
}
.row-drag-handle:active {
  cursor: grabbing;
}

.keyboard-row-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  flex: 1;
  min-width: 0;
}

/* ── Classic tg-style button ── */
.kb-button {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.kb-button:hover {
  border-color: var(--indigo);
  background: var(--bg-elevated);
}

.tg-btn-content {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tg-btn-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  bottom: 4px;
  width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  transition:
    opacity var(--transition-fast),
    color var(--transition-fast);
}

.kb-button:hover .tg-btn-remove {
  opacity: 1;
  color: var(--danger);
}

/* Add-button style */
.tg-btn-add {
  background: transparent;
  border: 1px dashed var(--border-primary);
  color: var(--text-tertiary);
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
  flex: 1;
}
.tg-btn-add:hover {
  border-color: var(--indigo);
  color: var(--indigo);
  background: hsla(234, 70%, 60%, 0.06);
}

/* ── Collapsible keyboard section ── */
.keyboard-builder .card-header {
  cursor: pointer;
  user-select: none;
}
.keyboard-builder .card-header:hover {
  background: var(--bg-tertiary);
}

.kb-body {
  display: none;
  padding: var(--space-md);
}
.kb-body.open {
  display: block;
}

/* ══════════════════════════════════════════════
   Empty States
   ══════════════════════════════════════════════ */

.empty-state {
  text-align: center;
  padding: var(--space-xl) var(--space-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}

.empty-state-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  margin-bottom: var(--space-xs);
}

.empty-state-text {
  font-size: 0.9rem;
  font-weight: 600;
}
.empty-state-hint {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  max-width: 240px;
}

/* ══════════════════════════════════════════════
   Toast Notifications
   ══════════════════════════════════════════════ */

.toast-container {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + var(--space-md));
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-sm);
  width: 300px;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  font-size: 0.86rem;
  font-weight: 500;
  animation: toastIn 0.3s ease-out forwards;
  pointer-events: all;
}
.toast.removing {
  animation: toastOut 0.2s ease-in forwards;
}
.toast-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.toast-icon svg {
  display: block;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
@keyframes toastOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

.toast-success .toast-icon {
  color: var(--success);
}
.toast-error .toast-icon {
  color: var(--danger);
}
.toast-info .toast-icon {
  color: var(--indigo);
}
.toast-warning .toast-icon {
  color: var(--warning);
}

/* ══════════════════════════════════════════════
   Animations
   ══════════════════════════════════════════════ */

.animate-fade-in {
  animation: fadeIn 0.4s ease-out;
}
.animate-slide-up {
  animation: slideUp 0.4s ease-out;
}

.stagger-children > * {
  opacity: 0;
  animation: slideUp 0.4s ease-out forwards;
}
.stagger-children > *:nth-child(1) {
  animation-delay: 0.04s;
}
.stagger-children > *:nth-child(2) {
  animation-delay: 0.08s;
}
.stagger-children > *:nth-child(3) {
  animation-delay: 0.12s;
}
.stagger-children > *:nth-child(4) {
  animation-delay: 0.16s;
}
.stagger-children > *:nth-child(5) {
  animation-delay: 0.2s;
}
.stagger-children > *:nth-child(6) {
  animation-delay: 0.24s;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* ══════════════════════════════════════════════
   Utility Classes
   ══════════════════════════════════════════════ */

.flex {
  display: flex;
}
.flex-col {
  flex-direction: column;
}
.items-center {
  align-items: center;
}
.justify-between {
  justify-content: space-between;
}
.gap-xs {
  gap: var(--space-xs);
}
.gap-sm {
  gap: var(--space-sm);
}
.gap-md {
  gap: var(--space-md);
}
.flex-1 {
  flex: 1;
}
.flex-wrap {
  flex-wrap: wrap;
}
.flex-shrink-0 {
  flex-shrink: 0;
}
.min-w-0 {
  min-width: 0;
}

.mt-xs {
  margin-top: var(--space-xs);
}
.mt-sm {
  margin-top: var(--space-sm);
}
.mt-md {
  margin-top: var(--space-md);
}
.mt-lg {
  margin-top: var(--space-lg);
}
.mt-xl {
  margin-top: var(--space-xl);
}
.mb-sm {
  margin-bottom: var(--space-sm);
}
.mb-md {
  margin-bottom: var(--space-md);
}

.w-full {
  width: 100%;
}
.hidden {
  display: none !important;
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Theme Toggle ── */
.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.theme-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--warning);
}

/* ── Divider ── */
.divider {
  height: 1px;
  background: var(--border-primary);
  margin: var(--space-lg) 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}
.section-title-sm {
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

/* ── Reference Links ── */
.ref-links {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.ref-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-full);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition-fast);
}
.ref-link:hover {
  background: hsla(234, 70%, 60%, 0.08);
  border-color: var(--border-accent);
  color: var(--indigo);
}
.ref-link svg {
  width: 10px;
  height: 10px;
}

/* ── Search ── */
.search-wrap {
  position: relative;
}
.search-wrap .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
  width: 15px;
  height: 15px;
}
.search-wrap .form-input {
  padding-left: 34px;
}

/* ══════════════════════════════════════════════
   Responsive — Desktop Nav
   ══════════════════════════════════════════════ */

@media (min-width: 768px) {
  .bottom-nav {
    display: none;
  }
  .app-main {
    padding-bottom: var(--space-lg);
  }

  .header-desktop-nav {
    display: flex !important;
    align-items: center;
    gap: 3px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 3px;
  }

  .header-desktop-nav-btn {
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font-primary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
  }
  .header-desktop-nav-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
  }
  .header-desktop-nav-btn.active {
    background: var(--indigo);
    color: white;
  }
  .header-desktop-nav-btn svg {
    width: 14px;
    height: 14px;
  }
}

.builder-layout {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.profile-layout {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

@media (min-width: 900px) {
  .builder-layout {
    max-width: 800px;
    margin: 0 auto;
  }

  .profile-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-xl);
    align-items: start;
  }
}

@media (min-width: 640px) {
  .page-container {
    padding: var(--space-lg) var(--space-xl);
  }
}

/* ══════════════════════════════════════════════
   Info Tooltips
   ══════════════════════════════════════════════ */
.info-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  cursor: help;
  margin-left: 6px;
}

.info-icon:hover {
  color: var(--text-primary);
}

.info-icon::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  white-space: pre-wrap;
  width: max-content;
  max-width: 200px;
  text-align: center;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-secondary);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  z-index: 100;
  pointer-events: none;
}

.info-icon:hover::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(-6px);
}
