/* ==========================================================================
   Mehrnet Tools — Rates-aligned core design system
   ========================================================================== */

:root {
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, Monaco, Consolas, monospace;

  --text-xs: 0.72rem;
  --text-sm: 0.80rem;
  --text-base: 0.88rem;
  --text-md: 1.02rem;
  --text-lg: 1.20rem;
  --text-xl: 1.45rem;
  --text-2xl: 1.80rem;

  --space-1: 0.2rem;
  --space-2: 0.35rem;
  --space-3: 0.5rem;
  --space-4: 0.75rem;
  --space-5: 1rem;
  --space-6: 1.25rem;
  --space-7: 1.5rem;
  --space-8: 2rem;
  --space-9: 2.5rem;
  --space-10: 3rem;

  --radius-xs: 0.35rem;
  --radius-sm: 0.4rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.65rem;
  --radius-xl: 0.85rem;
  --radius-full: 999rem;

  --duration-fast: 0.15s;
  --duration-base: 0.2s;
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
}

/* ==========================================================================
   Themes — neutral grayscale Tools palette
   ========================================================================== */

[data-theme="dark"] {
  --bg-primary: #111315;
  --bg-secondary: #181a1d;
  --bg-card: #202327;
  --bg-card-hover: #2a2e33;
  --glass-bg: rgba(17, 19, 21, 0.92);

  --text-primary: #f5f5f5;
  --text-secondary: #b6bcc4;
  --text-muted: #8a919a;

  --border: rgba(255, 255, 255, 0.11);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.2);

  --accent-primary: #64748b;
  --accent-secondary: #38bdf8;
  --accent: #64748b;
  --accent-hover: #475569;
  --accent-rgb: 100, 116, 139;
  --accent-subtle: rgba(100, 116, 139, 0.16);
  --accent-text: #38bdf8;
  --accent-contrast: #16181b;
  --accent-gradient: linear-gradient(135deg, #64748b 0%, #38bdf8 100%);

  --success: #10b981;
  --success-subtle: rgba(16, 185, 129, 0.14);
  --warning: #f59e0b;
  --warning-subtle: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-subtle: rgba(239, 68, 68, 0.14);

  --shadow-sm: 0 0.0625rem 0.125rem 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 0.25rem 0.375rem -0.0625rem rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 0.625rem 0.9375rem -0.1875rem rgba(0, 0, 0, 0.6);
}

[data-theme="black"] {
  --bg-primary: #050505;
  --bg-secondary: #0d0d0e;
  --bg-card: #161719;
  --bg-card-hover: #222326;
  --glass-bg: rgba(5, 5, 5, 0.94);

  --text-primary: #ffffff;
  --text-secondary: #b4b4b5;
  --text-muted: #88898b;

  --border: rgba(255, 255, 255, 0.14);
  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-hover: rgba(255, 255, 255, 0.24);

  --accent-primary: #94a3b8;
  --accent-secondary: #7dd3fc;
  --accent: #94a3b8;
  --accent-hover: #cbd5e1;
  --accent-rgb: 148, 163, 184;
  --accent-subtle: rgba(148, 163, 184, 0.18);
  --accent-text: #7dd3fc;
  --accent-contrast: #0b0b0c;
  --accent-gradient: linear-gradient(135deg, #94a3b8 0%, #7dd3fc 100%);

  --success: #4ade80;
  --success-subtle: rgba(74, 222, 128, 0.14);
  --warning: #facc15;
  --warning-subtle: rgba(250, 204, 21, 0.14);
  --danger: #f87171;
  --danger-subtle: rgba(248, 113, 113, 0.14);

  --shadow-sm: 0 0.0625rem 0.125rem 0 rgba(0, 0, 0, 0.8);
  --shadow-md: 0 0.25rem 0.375rem -0.0625rem rgba(0, 0, 0, 0.9);
  --shadow-lg: 0 0.625rem 0.9375rem -0.1875rem rgba(0, 0, 0, 0.95);
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f8f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f1f2;
  --glass-bg: rgba(255, 255, 255, 0.94);

  --text-primary: #17191c;
  --text-secondary: #4d535a;
  --text-muted: #737a82;

  --border: rgba(23, 25, 28, 0.12);
  --border-subtle: rgba(23, 25, 28, 0.07);
  --border-hover: rgba(23, 25, 28, 0.2);

  --accent-primary: #475569;
  --accent-secondary: #0284c7;
  --accent: #475569;
  --accent-hover: #334155;
  --accent-rgb: 71, 85, 105;
  --accent-subtle: rgba(71, 85, 105, 0.12);
  --accent-text: #0284c7;
  --accent-contrast: #ffffff;
  --accent-gradient: linear-gradient(135deg, #475569 0%, #0284c7 100%);

  --success: #059669;
  --success-subtle: rgba(5, 150, 105, 0.1);
  --warning: #d97706;
  --warning-subtle: rgba(217, 119, 6, 0.1);
  --danger: #dc2626;
  --danger-subtle: rgba(220, 38, 38, 0.1);

  --shadow-sm: 0 0.0625rem 0.125rem 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 0.25rem 0.375rem -0.0625rem rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 0.625rem 0.9375rem -0.1875rem rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   Typography and full-height viewport shell
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar {
  display: none;
}

html {
  height: 100%;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html[lang="fa"],
html[dir="rtl"] {
  direction: rtl;
  text-align: right;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Tahoma, Arial, sans-serif;
}

body {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-primary);
}

.page {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.content {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 76rem;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

#app-view {
  width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

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

.container {
  width: 100%;
  max-width: 76rem;
  margin: 0 auto;
  padding: 0 var(--space-6);
}

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

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.icon,
.logo-svg {
  display: inline-block;
  flex-shrink: 0;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon {
  width: 1rem;
  height: 1rem;
  vertical-align: middle;
}

.icon-fill {
  fill: currentColor;
  stroke: none;
}

button,
a,
summary {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
summary:focus-visible,
input:focus-visible {
  outline: 0.125rem solid var(--accent);
  outline-offset: 0.1875rem;
}

/* ==========================================================================
   Loading indicators
   ========================================================================== */

#boot-spinner {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  transition: opacity 0.25s var(--ease-out);
}

#boot-spinner.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 2rem;
  height: 2rem;
  border: 0.2rem solid var(--border);
  border-top-color: var(--accent);
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
}

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

#top-loading-bar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 9999;
  height: 0.16rem;
  overflow: hidden;
  background: transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease-out);
}

#top-loading-bar.running {
  opacity: 1;
}

#top-loading-bar .seg {
  position: absolute;
  inset-block: 0;
  inset-inline-start: -40%;
  width: 40%;
  background: var(--accent);
  box-shadow: 0 0 0.5rem rgba(var(--accent-rgb), 0.45);
}

#top-loading-bar.running .seg {
  animation: top-loading-bar-loop 1.35s linear infinite;
}

@keyframes top-loading-bar-loop {
  from { inset-inline-start: -40%; }
  to { inset-inline-start: 100%; }
}

/* ==========================================================================
   Rates-style header navigation
   ========================================================================== */

.nav {
  position: sticky;
  top: 0;
  z-index: 900;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  height: 3.75rem;
  background: var(--glass-bg);
  border-bottom: 0.0625rem solid var(--border);
  backdrop-filter: blur(0.75rem);
  -webkit-backdrop-filter: blur(0.75rem);
}

.nav-container {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

.nav-brand {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  color: var(--accent);
  background: var(--bg-secondary);
  border: 0.0625rem solid var(--border);
  border-radius: var(--radius-md);
  transition: transform var(--duration-fast), border-color var(--duration-fast);
}

.nav-brand:hover .brand-logo-icon {
  border-color: var(--border-hover);
  transform: translateY(-0.0625rem);
}

.logo-svg {
  width: 1.25rem;
  height: 1.25rem;
}

.brand-favicon {
  background: transparent;
  border-color: transparent;
}

.brand-logo-image {
  display: block;
  width: 2rem;
  height: 2rem;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-mark {
  color: var(--text-primary);
  font-size: var(--text-base);
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.brand-sub {
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.nav-center {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.nav-center a {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2rem;
  padding: 0.4rem 0.75rem;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.nav-center a:hover {
  color: var(--text-primary);
  background: var(--bg-secondary);
}

.nav-center a.active {
  color: var(--accent-text);
  background: var(--accent-subtle);
  font-weight: 600;
}

.nav-right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.4rem 0.75rem;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 0.0625rem solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast), color var(--duration-fast);
}

.action-btn.user-btn {
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  justify-content: center;
  border-radius: var(--radius-full);
}

.action-btn.user-btn .icon {
  width: 1.15rem;
  height: 1.15rem;
}

.action-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.action-btn.active,
.action-btn[aria-expanded="true"] {
  color: var(--accent-text);
  background: var(--accent-subtle);
  border-color: var(--accent);
}

/* ==========================================================================
   Rates-style settings dropdown
   ========================================================================== */

.custom-dropdown {
  position: relative;
  display: inline-flex;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  inset-inline-end: 0;
  z-index: 1500;
  max-height: min(18rem, calc(100dvh - 6rem));
  overflow: hidden;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 0.0625rem solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-0.25rem);
  transition: opacity var(--duration-fast), transform var(--duration-fast);
}

.custom-dropdown.active .dropdown-menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.dropdown-menu-settings {
  display: flex;
  flex-direction: column;
  min-width: 13.5rem;
  padding: var(--space-4);
}

.picker-label {
  margin-bottom: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.theme-btn,
.lang-btn {
  min-height: 2.25rem;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 0.0625rem solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast), color var(--duration-fast);
}

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
}

.theme-btn .icon {
  width: 1.1rem;
  height: 1.1rem;
}

.theme-btn:hover,
.theme-btn.active,
.lang-btn:hover,
.lang-btn.active {
  color: var(--accent-text);
  background: var(--accent-subtle);
  border-color: var(--accent);
}

.dropdown-divider {
  height: 0;
  margin: var(--space-3) 0;
  border: 0;
  border-top: 0.0625rem solid var(--border);
}

.lang-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
}

.lang-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
}

.lang-code {
  display: inline-grid;
  width: 1.55rem;
  height: 1.15rem;
  place-items: center;
  flex-shrink: 0;
  color: var(--text-secondary);
  background: var(--bg-primary);
  border: 0.0625rem solid var(--border);
  border-radius: 0.1875rem;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  line-height: 1;
}

.lang-flag {
  width: 1.15rem;
  height: 1.15rem;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 0.1875rem;
}

/* ==========================================================================
   TOTP view
   ========================================================================== */

.view-pane.active {
  display: block;
  animation: fade-in var(--duration-base) var(--ease-out);
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(0.25rem); }
  to { opacity: 1; transform: translateY(0); }
}

.tool-view {
  width: min(100%, 48rem);
  margin: 0 auto;
}

.setup-view,
.direct-view {
  width: min(100%, 42rem);
}

.setup-card {
  width: min(100%, 36rem);
  margin: 0 auto;
}

.direct-card {
  width: 100%;
}

.setup-view .toolbar,
.direct-view .toolbar {
  margin-bottom: var(--space-5);
}

.toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.section-kicker {
  margin-bottom: var(--space-2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.section-title {
  color: var(--text-primary);
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.section-subtitle {
  max-width: 38rem;
  margin-top: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.route-context {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  min-height: 2rem;
  margin-bottom: var(--space-5);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.route-label {
  padding: 0.15rem 0.4rem;
  color: var(--accent-text);
  background: var(--accent-subtle);
  border: 0.0625rem solid rgba(var(--accent-rgb), 0.2);
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.route-context.direct .route-label {
  color: var(--warning);
  background: var(--warning-subtle);
  border-color: color-mix(in srgb, var(--warning) 24%, transparent);
}

.route-context code {
  max-width: min(100%, 22rem);
  overflow: hidden;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  direction: ltr;
  text-align: left;
  text-overflow: ellipsis;
  unicode-bidi: isolate;
  white-space: nowrap;
}

.route-description {
  flex: 1 1 18rem;
}

.tool-card {
  overflow: hidden;
  background: var(--bg-card);
  border: 0.0625rem solid var(--border);
  border-radius: var(--radius-xl);
}

.tool-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5);
  border-bottom: 0.0625rem solid var(--border);
}

.tool-card-heading {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.tool-icon {
  display: grid;
  width: 2.2rem;
  height: 2.2rem;
  place-items: center;
  flex-shrink: 0;
  color: var(--accent-text);
  background: var(--accent-subtle);
  border: 0.0625rem solid rgba(var(--accent-rgb), 0.2);
  border-radius: var(--radius-md);
}

.tool-icon .icon {
  width: 1.1rem;
  height: 1.1rem;
}

.tool-title {
  color: var(--text-primary);
  font-size: var(--text-base);
  font-weight: 700;
}

.tool-subtitle {
  margin-top: var(--space-1);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.local-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
  color: var(--success);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.status-dot {
  width: 0.4rem;
  height: 0.4rem;
  flex-shrink: 0;
  background: currentColor;
  border-radius: var(--radius-full);
  box-shadow: 0 0 0.4rem currentColor;
}

.tool-card-body {
  padding: var(--space-6);
}

.setup-note {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-top: var(--space-6);
  padding: var(--space-4);
  color: var(--text-secondary);
  background: var(--accent-subtle);
  border: 0.0625rem solid rgba(var(--accent-rgb), 0.16);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  line-height: 1.55;
}

.setup-note > .icon {
  flex: 0 0 auto;
  margin-top: 0.1rem;
  color: var(--accent-text);
}

.setup-note strong {
  color: var(--text-primary);
}

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 600;
}

.field-hint {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
}

.secret-field {
  display: flex;
  align-items: center;
  min-height: 3rem;
  background: var(--bg-secondary);
  border: 0.0625rem solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.secret-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.1875rem var(--accent-subtle);
}

.secret-field.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 0.1875rem var(--danger-subtle);
}

.secret-field input {
  min-width: 0;
  height: 2.9rem;
  flex: 1;
  padding: 0 var(--space-4);
  color: var(--text-primary);
  background: transparent;
  border: 0;
  outline: 0;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  letter-spacing: 0.025em;
  direction: ltr;
  text-align: left;
}

.secret-field input::placeholder {
  color: var(--text-muted);
  font-family: var(--font-sans);
  letter-spacing: 0;
}

html[lang="fa"] .secret-field input::placeholder {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Tahoma, Arial, sans-serif;
}

.field-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding-inline-end: var(--space-2);
}

.field-action {
  display: inline-grid;
  width: 2.15rem;
  height: 2.15rem;
  place-items: center;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--duration-fast), background var(--duration-fast);
}

.field-action:hover {
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.feedback {
  min-height: 1.5rem;
  padding-top: var(--space-2);
  color: var(--danger);
  font-size: var(--text-xs);
}

.feedback:empty {
  min-height: var(--space-4);
  padding-top: 0;
}

.helper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.helper-copy {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.helper-copy .icon {
  width: 0.85rem;
  height: 0.85rem;
  color: var(--accent-text);
}

.text-action {
  min-height: 2rem;
  padding: var(--space-1) var(--space-2);
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  transition: color var(--duration-fast), background var(--duration-fast);
}

.text-action:hover {
  color: var(--text-primary);
  background: var(--bg-secondary);
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 2.75rem;
  margin-top: var(--space-4);
  padding: 0 var(--space-5);
  color: var(--accent-contrast);
  background: var(--accent);
  border: 0.0625rem solid var(--accent);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast), transform var(--duration-fast);
}

.primary-action:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-0.0625rem);
}

.primary-action:active {
  transform: translateY(0);
}

.primary-action .icon {
  width: 0.95rem;
  height: 0.95rem;
}

.section-divider {
  height: 0;
  margin: var(--space-6) 0;
  border: 0;
  border-top: 0.0625rem solid var(--border);
}

.code-panel {
  padding: var(--space-5);
  background: var(--bg-secondary);
  border: 0.0625rem solid var(--border);
  border-radius: var(--radius-lg);
}

.code-panel-top,
.code-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.history-section {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 0.0625rem solid var(--border-subtle);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.history-count {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
}

.history-list {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 2.35rem;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-secondary);
  border: 0.0625rem solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.history-code {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  letter-spacing: 0.08em;
  direction: ltr;
  white-space: nowrap;
}

.history-time,
.history-empty {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.history-time {
  flex: 0 0 auto;
  direction: ltr;
  white-space: nowrap;
}

.history-empty {
  padding: var(--space-2) 0;
  text-align: center;
}

.direct-actions {
  display: flex;
  justify-content: center;
  padding-top: var(--space-5);
}

.secondary-action {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.35rem;
  padding: var(--space-2) var(--space-3);
  color: var(--text-secondary);
  border: 0.0625rem solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: 600;
  transition: background var(--duration-fast), border-color var(--duration-fast), color var(--duration-fast);
}

.secondary-action:hover {
  color: var(--text-primary);
  background: var(--bg-secondary);
  border-color: var(--border-hover);
}

.secondary-action .icon {
  width: 0.85rem;
  height: 0.85rem;
}

.code-label {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.code-state {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
}

.code-state.live {
  color: var(--success);
}

.code-state.error {
  color: var(--danger);
}

.code-value {
  min-height: 4.2rem;
  margin: var(--space-4) 0;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: clamp(2.65rem, 9vw, 4rem);
  font-weight: 700;
  letter-spacing: 0.1em;
  line-height: 1.05;
  direction: ltr;
  white-space: nowrap;
  text-align: center;
  text-indent: 0.1em;
  unicode-bidi: isolate;
}

.code-value.placeholder {
  color: var(--text-muted);
  font-size: 2.35rem;
  opacity: 0.45;
}

.code-value.is-refreshing {
  animation: code-refresh 0.22s var(--ease-out);
}

@keyframes code-refresh {
  from { opacity: 0.35; transform: translateY(0.1875rem); }
  to { opacity: 1; transform: translateY(0); }
}

.code-bottom {
  padding-top: var(--space-4);
  border-top: 0.0625rem solid var(--border-subtle);
}

.code-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  direction: ltr;
  unicode-bidi: isolate;
}

.meta-divider {
  color: var(--border-hover);
}

.copy-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 2.25rem;
  padding: var(--space-2) var(--space-3);
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 0.0625rem solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  transition: color var(--duration-fast), background var(--duration-fast), border-color var(--duration-fast);
}

.copy-code:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.copy-code:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.timer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.timer-ring {
  position: relative;
  display: inline-grid;
  width: 1.55rem;
  height: 1.55rem;
  place-items: center;
  flex-shrink: 0;
  --timer-angle: 360deg;
  --timer-color: var(--accent);
  background: conic-gradient(var(--timer-color) 0deg var(--timer-angle), var(--border-hover) var(--timer-angle) 360deg);
  border-radius: var(--radius-full);
}

.timer-ring::before {
  position: absolute;
  inset: 0.2rem;
  content: "";
  background: var(--bg-secondary);
  border-radius: inherit;
}

.timer-ring.is-low {
  --timer-color: var(--warning);
}

.timer-ring.timer-progress-0 { --timer-angle: 0deg; }
.timer-ring.timer-progress-5 { --timer-angle: 18deg; }
.timer-ring.timer-progress-10 { --timer-angle: 36deg; }
.timer-ring.timer-progress-15 { --timer-angle: 54deg; }
.timer-ring.timer-progress-20 { --timer-angle: 72deg; }
.timer-ring.timer-progress-25 { --timer-angle: 90deg; }
.timer-ring.timer-progress-30 { --timer-angle: 108deg; }
.timer-ring.timer-progress-35 { --timer-angle: 126deg; }
.timer-ring.timer-progress-40 { --timer-angle: 144deg; }
.timer-ring.timer-progress-45 { --timer-angle: 162deg; }
.timer-ring.timer-progress-50 { --timer-angle: 180deg; }
.timer-ring.timer-progress-55 { --timer-angle: 198deg; }
.timer-ring.timer-progress-60 { --timer-angle: 216deg; }
.timer-ring.timer-progress-65 { --timer-angle: 234deg; }
.timer-ring.timer-progress-70 { --timer-angle: 252deg; }
.timer-ring.timer-progress-75 { --timer-angle: 270deg; }
.timer-ring.timer-progress-80 { --timer-angle: 288deg; }
.timer-ring.timer-progress-85 { --timer-angle: 306deg; }
.timer-ring.timer-progress-90 { --timer-angle: 324deg; }
.timer-ring.timer-progress-95 { --timer-angle: 342deg; }
.timer-ring.timer-progress-100 { --timer-angle: 360deg; }

.timer-ring .timer-progress {
  display: none;
}

.timer-ring > #seconds-number {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 1;
  color: var(--text-secondary);
  font-size: 0.5rem;
  direction: ltr;
}

.clipboard-helper {
  position: fixed;
  inset: -9999px auto auto -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.security-strip {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding: var(--space-4);
  color: var(--text-secondary);
  background: var(--success-subtle);
  border: 0.0625rem solid color-mix(in srgb, var(--success) 20%, transparent);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  line-height: 1.55;
}

.security-strip.direct {
  background: var(--warning-subtle);
  border-color: color-mix(in srgb, var(--warning) 22%, transparent);
}

.security-strip .icon {
  width: 0.95rem;
  height: 0.95rem;
  margin-top: 0.1rem;
  color: var(--success);
}

.security-strip.direct .icon {
  color: var(--warning);
}

.security-strip strong {
  color: var(--text-primary);
}

.security-strip code {
  color: var(--warning);
  font-family: var(--font-mono);
  direction: ltr;
  unicode-bidi: isolate;
}

.advanced {
  margin-top: var(--space-5);
  border-top: 0.0625rem solid var(--border);
}

.advanced summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2.75rem;
  padding-top: var(--space-3);
  color: var(--text-secondary);
  border-radius: var(--radius-xs);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.advanced summary::-webkit-details-marker {
  display: none;
}

.advanced summary::after {
  content: "+";
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  font-weight: 400;
}

.advanced[open] summary::after {
  content: "−";
}

.advanced-content {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  padding-top: var(--space-2);
}

.meta-cell {
  min-width: 0;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-secondary);
  border: 0.0625rem solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.meta-cell-label {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--text-muted);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.meta-cell-value {
  display: block;
  overflow: hidden;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

#toast-container {
  position: fixed;
  top: 1rem;
  left: 50%;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  width: calc(100% - 2rem);
  max-width: 24rem;
  pointer-events: none;
  transform: translateX(-50%);
}

.toast {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  overflow: hidden;
  padding-block: var(--space-4);
  padding-inline: var(--space-5) var(--space-3);
  color: var(--text-primary);
  background: var(--bg-card);
  border: 0.0625rem solid var(--border);
  border-inline-start: 0.2rem solid var(--accent);
  border-radius: var(--radius-lg);
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.4);
  font-size: var(--text-sm);
  pointer-events: auto;
  animation: toast-in 0.25s var(--ease-out);
}

.toast.success { border-inline-start-color: var(--success); }
.toast.error { border-inline-start-color: var(--danger); }
.toast > .icon { color: var(--accent-text); }
.toast.success > .icon { color: var(--success); }
.toast.error > .icon { color: var(--danger); }
.toast-message { flex: 1; line-height: 1.35; }

.toast-close {
  display: inline-grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  flex-shrink: 0;
  padding: 0;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.toast-close:hover {
  color: var(--text-primary);
  background: var(--bg-secondary);
}

.toast-progress {
  position: absolute;
  inset: auto auto 0 0;
  width: 100%;
  height: 0.15rem;
  background: var(--accent);
  animation: toast-progress 3.2s linear forwards;
}

html[dir="rtl"] .toast-progress {
  right: 0;
  left: auto;
}

.toast.success .toast-progress { background: var(--success); }
.toast.error .toast-progress { background: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-0.6rem); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-progress {
  from { width: 100%; }
  to { width: 0; }
}

/* ==========================================================================
   Responsive and RTL refinements
   ========================================================================== */

html[dir="rtl"] .section-kicker,
html[dir="rtl"] .picker-label,
html[dir="rtl"] .route-label,
html[dir="rtl"] .code-label,
html[dir="rtl"] .local-badge,
html[dir="rtl"] .meta-cell-label {
  letter-spacing: 0;
}

html[dir="rtl"] .code-meta {
  direction: ltr;
}

@media (max-width: 52rem) {
  .content {
    padding: var(--space-5) var(--space-3) 0;
  }

}

@media (max-width: 38rem) {
  .container {
    padding-inline: var(--space-4);
  }

  .nav {
    height: 3.75rem;
  }

  .nav-center a {
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: var(--space-2) var(--space-3);
  }

  .action-btn.user-btn,
  .theme-btn,
  .lang-btn,
  .field-action,
  .text-action,
  .copy-code {
    min-width: 2.75rem;
    min-height: 2.75rem;
  }

  .brand-sub {
    display: none;
  }

  .dropdown-menu-settings {
    min-width: 12.75rem;
  }

  .toolbar {
    margin-bottom: var(--space-3);
  }

  .section-title {
    font-size: var(--text-md);
  }

  .route-context {
    align-items: flex-start;
    margin-bottom: var(--space-4);
  }

  .route-description {
    flex-basis: 100%;
  }

  .tool-card-header,
  .tool-card-body {
    padding: var(--space-4);
  }

  .tool-subtitle {
    max-width: 13rem;
  }

  .secret-field input {
    padding-inline: var(--space-3);
    font-size: var(--text-xs);
  }

  .field-hint {
    display: none;
  }

  .helper-row {
    align-items: flex-start;
  }

  .code-panel {
    padding: var(--space-4);
  }

  .code-value {
    min-height: 3.65rem;
    font-size: clamp(2.15rem, 13vw, 3.3rem);
  }

  .code-bottom {
    align-items: flex-end;
  }

  .advanced-content {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 22rem) {
  .brand-text {
    display: none;
  }

  .local-badge {
    font-size: 0;
  }

  .local-badge .status-dot {
    width: 0.5rem;
    height: 0.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
