:root {
  --bg-1: #f8fbff;
  --bg-2: #ffffff;
  --bg-3: #f7fbff;

  --card: #ffffff;
  --card-soft: #f8fafc;
  --card-hover: #f3f7ff;

  --text: #182033;
  --muted: #697386;

  --primary: #3267ff;
  --primary-soft: rgba(50, 103, 255, 0.1);
  --primary-soft-2: rgba(50, 103, 255, 0.06);

  --success: #16834a;
  --danger: #d64545;
  --warning: #9a6400;

  --border: rgba(130, 146, 174, 0.22);
  --border-strong: rgba(130, 146, 174, 0.34);

  --shadow: 0 2px 4px rgba(29, 57, 107, 0.08);
  --shadow-soft: 0 2px 4px rgba(29, 57, 107, 0.06);
  --key-shadow: 0 2px 4px rgba(32, 44, 75, 0.05);

  --radius-lg: 22px;
  --radius-md: 15px;
  --radius-sm: 11px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family: Tahoma, Arial, sans-serif;
  color: var(--text);
  direction: rtl;
  background:
    radial-gradient(
      circle at top right,
      rgba(50, 103, 255, 0.06),
      transparent 32%
    ),
    radial-gradient(
      circle at bottom left,
      rgba(0, 166, 143, 0.05),
      transparent 30%
    ),
    linear-gradient(135deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
}

html:lang(fa) body {
  font-family: "Vazir", Tahoma, Arial, sans-serif;
}

/* =========================
   Main Layout
========================= */
.page,
.main-column,
.workspace,
.left-column,
.right-column,
.templates-boxes,
.templates-list {
  background: transparent !important;
}

.page {
  width: min(1320px, calc(100% - 28px));
  height: calc(100vh - 28px);
  margin: 14px auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  overflow: hidden;
  direction: ltr;
}

.main-column {
  min-width: 0;
  min-height: 0;
  direction: rtl;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.right-column {
  min-width: 0;
  min-height: 0;
  height: 100%;
  direction: rtl;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: transparent;
}

/* =========================
   Shared Cards
========================= */

.title-card,
.mode-card,
.editor-card,
.keyboard-card,
.templates-search-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

/* =========================
   Header / Hero
========================= */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 255px;
  gap: 14px;
  align-items: stretch;
  margin-bottom: 14px;
  direction: rtl;
  flex: 0 0 auto;
}

.title-card {
  padding: 18px 22px;
}

h1 {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: -0.4px;
  color: #121a2c;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
  font-size: 14px;
}

/* =========================
   Mode Switch
========================= */

.mode-card {
  padding: 14px;
  min-width: 0;
  direction: ltr;
}

.mode-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 118px;
  justify-content: center;
  padding: 9px 12px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #00a68f);
  box-shadow: 0 8px 18px rgba(50, 103, 255, 0.22);
  font-size: 13px;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.22);
}

.switch-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: right;
  direction: rtl;
}

.mode-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* =========================
   Buttons
========================= */

button,
input {
  font-family: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.mode-btn,
.action-btn,
.keyboard-toggle,
.template-card,
.mini-btn,
.category-toggle,
.subcategory-toggle {
  border: 0;
  cursor: pointer;
  transition:
    transform 0.14s ease,
    background 0.14s ease,
    box-shadow 0.14s ease,
    border-color 0.14s ease;
}

.mode-btn {
  background: var(--card-soft);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 13px;
  border: 1px solid var(--border);
}

.mode-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(50, 103, 255, 0.2);
}

.mode-btn:hover,
.action-btn:hover,
.keyboard-toggle:hover,
.key:hover,
.template-card:hover,
.mini-btn:hover,
.category-toggle:hover,
.subcategory-toggle:hover {
  transform: translateY(-1px);
}

.mode-btn:active,
.action-btn:active,
.keyboard-toggle:active,
.key:active,
.template-card:active,
.mini-btn:active,
.category-toggle:active,
.subcategory-toggle:active {
  transform: translateY(0);
}

/* =========================
   Editor
========================= */

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  direction: rtl;
}

.left-column {
  min-width: 0;
  min-height: 0;
  height: 100%;
  direction: rtl;
  display: flex;
  flex-direction: column;
}

.editor-card {
  padding: 14px;
  margin-bottom: 14px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  direction: rtl;
  flex: 0 0 auto;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.action-btn {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(50, 103, 255, 0.18);
  padding: 10px 13px;
  font-size: 13px;
  border-radius: 13px;
}

.action-btn.secondary,
.mini-btn {
  background: var(--card-soft);
  color: var(--text);
  box-shadow: none;
  border: 1px solid var(--border);
}

.action-btn.secondary:hover,
.mini-btn:hover {
  background: var(--card-hover);
}

.action-btn.danger {
  background: #fff1f1;
  color: var(--danger);
  border: 1px solid rgba(214, 69, 69, 0.22);
  box-shadow: none;
}

.action-btn.danger:hover {
  background: #ffe9e9;
}

.counter {
  color: var(--muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

textarea {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  font-size: 23px;
  line-height: 1.9;
  font-family: Tahoma, Arial, sans-serif;
  direction: rtl;
  text-align: right;
  unicode-bidi: embed;
  background: #ffffff;
  outline: none;
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

textarea:lang(fa) {
  font-family: "Vazir", Tahoma, Arial, sans-serif;
}

textarea:focus {
  border-color: rgba(50, 103, 255, 0.56);
  box-shadow: 0 0 0 4px rgba(50, 103, 255, 0.09);
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  min-height: 22px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.status {
  color: var(--success);
}

.status.warn {
  color: var(--warning);
}

/* =========================
   Templates Search Box
========================= */

.templates-search-card {
  padding: 12px;
  direction: rtl;
  flex: 0 0 auto;
}

.templates-header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.templates-title {
  margin: 0;
  font-size: 15px;
  text-align: center;
  color: #121a2c;
}

.template-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #ffffff;
  outline: none;
  padding: 9px 10px;
  margin-bottom: 8px;
  color: var(--text);
  direction: rtl;
  text-align: right;
  font-size: 12px;
}

.template-search:focus {
  border-color: rgba(50, 103, 255, 0.56);
  box-shadow: 0 0 0 3px rgba(50, 103, 255, 0.08);
}

.templates-help {
  margin: 0;
  font-size: 11px;
  line-height: 1.7;
  color: var(--muted);
}

/* =========================
   Templates Area
   فقط خود کارت‌ها پس‌زمینه دارند
========================= */

.templates-boxes {
  direction: rtl;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.templates-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-left: 4px;
  padding-right: 1px;
  height: 100%;
  min-height: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(105, 115, 134, 0.38) transparent;
}

.templates-list::-webkit-scrollbar {
  width: 8px;
}

.templates-list::-webkit-scrollbar-track {
  background: transparent;
}

.templates-list::-webkit-scrollbar-thumb {
  background: rgba(105, 115, 134, 0.28);
  border-radius: 999px;
}

.templates-list::-webkit-scrollbar-thumb:hover {
  background: rgba(105, 115, 134, 0.42);
}

/* =========================
   Category Cards
========================= */

.category {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: var(--key-shadow);
  overflow: hidden;
  flex: 0 0 auto;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.category.open {
  border-color: rgba(50, 103, 255, 0.24);
  box-shadow: 0 6px 18px rgba(50, 103, 255, 0.08);
}

.category-toggle {
  width: 100%;
  background: linear-gradient(
    135deg,
    var(--primary-soft),
    rgba(0, 166, 143, 0.07)
  );
  color: var(--text);
  text-align: right;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  border-radius: 0;
  padding: 9px 11px;
  font-size: 13px;
}

.category-toggle:hover {
  background: linear-gradient(
    135deg,
    rgba(50, 103, 255, 0.13),
    rgba(0, 166, 143, 0.1)
  );
}

.category-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px;
  background: #ffffff;
  transform-origin: top;
}

.category.open > .category-body {
  animation: accordionOpen 0.32s ease-out both;
}

.category.closing > .category-body {
  animation: accordionClose 0.26s ease-in both;
}

.subcategory.open > .subcategory-body {
  animation: accordionOpen 0.28s ease-out both;
}

.subcategory.closing > .subcategory-body {
  animation: accordionClose 0.24s ease-in both;
}

.keyboard-card.open .keyboard-content {
  display: block;
  animation: accordionOpen 0.28s ease-out both;
}

/* =========================
   Subcategory Cards
========================= */

.subcategory {
  border-radius: 12px;
  background: #f6f8fc;
  overflow: hidden;
  border: 1px solid rgba(130, 146, 174, 0.2);
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.subcategory.open {
  background: #f8fbff;
  border-color: rgba(50, 103, 255, 0.18);
  box-shadow: 0 4px 12px rgba(50, 103, 255, 0.05);
}

.subcategory-toggle {
  width: 100%;
  background: transparent;
  color: var(--text);
  text-align: right;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  padding: 7px 10px;
  border-radius: 0;
  font-size: 12px;
}

.subcategory-toggle:hover {
  background: rgba(50, 103, 255, 0.06);
}

.subcategory-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 6px 6px;
  transform-origin: top;
}

.subcategory.open > .subcategory-body {
  animation: accordionOpen 0.18s ease-out both;
}

.subcategory.collapsed > .subcategory-body {
  animation: accordionClose 0.14s ease-in both;
}

/* =========================
   Accordion Icons
========================= */

.category-toggle::before,
.subcategory-toggle::before {
  content: "▸";
  font-size: 12px;
  color: var(--muted);
  flex: 0 0 auto;
  transition: transform 0.18s ease;
}

.category.open > .category-toggle::before,
.subcategory.open > .subcategory-toggle::before {
  content: "▾";
}

.category-count,
.subcategory-count {
  display: none;
}

/* =========================
   Template Cards
========================= */

.template-card {
  width: 100%;
  background: #ffffff;
  color: var(--text);
  border: 1px solid rgba(130, 146, 174, 0.2);
  box-shadow: none;
  text-align: right;
  line-height: 1.6;
  padding: 7px 10px;
  border-radius: 10px;
}

.template-card:hover {
  background: var(--card-hover);
  border-color: rgba(50, 103, 255, 0.22);
}

.template-card-title {
  display: block;
  font-size: 12px;
  color: var(--text);
}

.template-card-meta {
  display: none;
}

.empty-templates {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
  padding: 10px;
  background: #ffffff;
  border-radius: 12px;
  border: 1px dashed var(--border-strong);
}

/* =========================
   Accordion Animation
========================= */

@keyframes accordionOpen {
  from {
    opacity: 0;
    transform: scaleY(0.96);
    max-height: 0;
  }

  to {
    opacity: 1;
    transform: scaleY(1);
    max-height: 1000px;
  }
}

@keyframes accordionClose {
  from {
    opacity: 1;
    transform: scaleY(1);
    max-height: 1000px;
  }

  to {
    opacity: 0;
    transform: scaleY(0.96);
    max-height: 0;
  }
}

/* =========================
   Keyboard Layout Toggle
========================= */

.keyboard-card {
  flex: 0 0 auto;
  margin-top: 0;
  overflow: hidden;
  direction: rtl;
}

.keyboard-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #ffffff;
  color: var(--text);
  text-align: right;
  font-size: 14px;
  border-radius: 24px;
  padding: 14px 18px;
}

.keyboard-toggle:hover {
  background: var(--card-hover);
}

.keyboard-toggle-text {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toggle-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 50%;
  background: var(--soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease;
  direction: ltr;
}

.keyboard-card.open .toggle-icon {
  transform: rotate(180deg);
}

.keyboard-content {
  display: none;
  padding: 0 16px 16px;
  overflow-x: auto;
  direction: ltr;
}

.keyboard-card.open .keyboard-content {
  display: block;
  animation: accordionOpen 0.18s ease-out both;
}

.keyboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 6px 0 12px;
  direction: rtl;
  color: var(--muted);
  font-size: 13px;
  min-width: 880px;
}

.keyboard {
  min-width: 880px;
}

.row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 8px;
}

.key {
  min-width: 58px;
  height: 58px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: linear-gradient(180deg, #ffffff, #f5f7fb);
  color: var(--text);
  cursor: pointer;
  display: grid;
  grid-template-rows: 1fr 1fr auto;
  align-items: center;
  justify-items: center;
  padding: 5px 6px;
  box-shadow: var(--key-shadow);
  transition: 0.14s ease;
  font-family: Tahoma, Arial, sans-serif;
}

.key:lang(fa) {
  font-family: "Vazir", Tahoma, Arial, sans-serif;
}

.key:hover {
  background: linear-gradient(180deg, #ffffff, #eef4ff);
  border-color: rgba(50, 103, 255, 0.22);
}

.key:active {
  transform: translateY(1px);
  box-shadow: none;
}

.key .shift {
  font-size: 13px;
  color: var(--muted);
  min-height: 16px;
}

.key .main {
  font-size: 21px;
  line-height: 1;
}

.key .latin {
  font-size: 11px;
  color: var(--muted);
  direction: ltr;
  font-family: Tahoma, Arial, sans-serif;
  margin-top: 2px;
}

.space {
  min-width: 330px;
}

.special {
  background: linear-gradient(180deg, #ffffff, #f5f7fb);
}

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

@media (max-width: 980px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .page {
    width: min(1320px, calc(100% - 28px));
    height: auto;
    margin: 14px auto;
    display: flex;
    flex-direction: column;
    overflow: visible;
    direction: rtl;
  }

  .main-column {
    display: block;
    overflow: visible;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .right-column {
    height: auto;
    overflow: visible;
    order: -1;
    margin-bottom: 14px;
  }

  .templates-boxes {
    overflow: visible;
  }

  .templates-list {
    max-height: 340px;
    flex: unset;
  }

  .editor-card {
    display: block;
  }

  textarea {
    min-height: 260px;
    resize: vertical;
  }
}

@media (max-width: 760px) {
  .page {
    width: min(100% - 18px, 1120px);
    margin: 10px auto;
  }

  h1 {
    font-size: 24px;
  }

  textarea {
    font-size: 20px;
    min-height: 260px;
  }
}
