/* ==========================================================================
   md.tsbyin.dev - Markdown Workspace & Viewer Style System
   Design Language: Dark-Tech / Minimal Editorial
   ========================================================================== */

:root {
  --bg-primary: #090d16;
  --bg-secondary: #0f172a;
  --bg-surface: #131c31;
  --bg-surface-hover: #1e293b;
  --bg-card: rgba(19, 28, 49, 0.7);
  --bg-code: #0b1120;
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-active: rgba(56, 189, 248, 0.4);
  --border-card: rgba(255, 255, 255, 0.12);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-primary: #38bdf8;
  --accent-secondary: #818cf8;
  --accent-glow: rgba(56, 189, 248, 0.2);
  --accent-success: #34d399;
  --accent-danger: #f87171;
  --accent-warning: #fbbf24;

  --sidebar-width: 290px;
  --toc-width: 260px;
  --header-height: 58px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-surface: #f1f5f9;
  --bg-surface-hover: #e2e8f0;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-code: #f1f5f9;

  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-active: rgba(14, 165, 233, 0.5);
  --border-card: rgba(0, 0, 0, 0.1);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent-primary: #0284c7;
  --accent-secondary: #6366f1;
  --accent-glow: rgba(2, 132, 199, 0.15);
  --accent-success: #10b981;
  --accent-danger: #ef4444;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.09);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.12);
}

html, body {
  height: 100%;
  max-height: 100vh;
  overflow: hidden;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.app-locked {
  overflow: hidden;
}

/* Custom Sleek 4px Scrollbar (Chrome, Edge, Safari & Firefox) */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(56, 189, 248, 0.22) transparent;
}
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(56, 189, 248, 0.22);
  border-radius: 999px;
  transition: all 0.2s ease;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* ==========================================================================
   Gatekeeper Lock Screen
   ========================================================================== */
.lock-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(1000px 500px at 50% 20%, rgba(56, 189, 248, 0.06), transparent),
              radial-gradient(800px 400px at 80% 80%, rgba(129, 140, 248, 0.04), transparent),
              var(--bg-primary);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.lock-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  backdrop-filter: blur(12px);
  animation: cardFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes cardFadeIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.lock-brand {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.lock-logo-img {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  margin-bottom: 0.25rem;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.lock-badge {
  display: none;
}

.lock-title {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.lock-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 320px;
}

.lock-form {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.lock-pin-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.lock-input-icon {
  position: absolute;
  left: 0.85rem;
  color: var(--text-muted);
  pointer-events: none;
}

.lock-pin-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 2.85rem 0.75rem 2.65rem;
  font-size: 1.05rem;
  color: var(--text-primary);
  letter-spacing: 0.12em;
  font-family: var(--font-mono);
  outline: none;
  transition: all 0.2s ease;
}
.lock-pin-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 14px var(--accent-glow);
  background: var(--bg-surface-hover);
}

.lock-visibility-btn {
  position: absolute;
  right: 0.75rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lock-visibility-btn:hover {
  color: var(--text-primary);
}

.lock-remember-wrap {
  display: flex;
  align-items: center;
}
.lock-remember-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.lock-checkbox {
  accent-color: var(--accent-primary);
  width: 16px;
  height: 16px;
}

.lock-error-message {
  font-size: 0.82rem;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: var(--accent-danger);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  line-height: 1.4;
  text-align: center;
}

.lock-submit-btn {
  width: 100%;
  padding: 0.75rem;
  font-size: 0.92rem;
  justify-content: center;
  border-radius: var(--radius-md);
}

/* Shake Animation */
.shake {
  animation: shakeX 0.4s ease-in-out;
}
@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-9px); }
  40%, 80% { transform: translateX(9px); }
}

/* ==========================================================================
   Top Header Navigation
   ========================================================================== */
.app-header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-toggle-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}
.sidebar-toggle-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
}

.header-logo-img {
  width: 24px;
  height: 24px;
  border-radius: 4px;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-domain {
  color: var(--accent-primary);
}

.active-file-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-surface);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  max-width: 380px;
  overflow: hidden;
}

.active-file-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  white-space: nowrap;
}
.btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-active);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), #0284c7);
  border-color: transparent;
  color: #ffffff;
  font-weight: 600;
}
.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 0 14px var(--accent-glow);
}

.btn-icon-only {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
  flex-shrink: 0;
}

/* Dropdown Menu for Download */
.dropdown-wrap {
  position: relative;
}
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 0.4rem;
  min-width: 200px;
  display: none;
  flex-direction: column;
  z-index: 150;
  animation: fadeInDown 0.15s ease;
}
.dropdown-wrap.open .dropdown-menu {
  display: flex;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
}
.dropdown-item:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

/* ==========================================================================
   Main Application Layout
   ========================================================================== */
.app-container {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--header-height));
  max-height: calc(100vh - var(--header-height));
  overflow: hidden;
  position: relative;
}

/* Left Sidebar - File Manager */
.app-sidebar {
  width: var(--sidebar-width);
  height: 100%;
  max-height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform 0.25s ease, width 0.25s ease;
  z-index: 90;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex-shrink: 0;
}

.sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.file-count-badge {
  font-size: 0.75rem;
  background: var(--bg-surface);
  color: var(--accent-primary);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-weight: 600;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 0.65rem;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.65rem 0.45rem 2.2rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s ease;
}
.search-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-glow);
}

.sidebar-file-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.file-group-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.5rem 0.65rem 0.25rem;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  border: 1px solid transparent;
}
.file-item:hover {
  background: var(--bg-surface-hover);
}
.file-item.active {
  background: var(--bg-surface);
  border-color: var(--border-active);
}
.file-item.active .file-item-name {
  color: var(--accent-primary);
  font-weight: 600;
}

.file-item-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow: hidden;
}
.file-item-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}
.file-item.active .file-item-icon {
  color: var(--accent-primary);
}
.file-item-name {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}
.file-size-tag {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.file-del-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.15s ease;
}
.file-item:hover .file-del-btn {
  opacity: 1;
}
.file-del-btn:hover {
  color: var(--accent-danger);
  background: rgba(248, 113, 113, 0.1);
}

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
}

.dropzone-trigger {
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.65rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  background: var(--bg-surface);
  transition: all 0.2s ease;
}
.dropzone-trigger:hover {
  border-color: var(--accent-primary);
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

/* ==========================================================================
   Center Content & Desktop Wide Screen Layout
   ========================================================================== */
.app-main {
  flex: 1;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
  position: relative;
  min-width: 0;
}

.doc-meta-bar {
  padding: 0.55rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 20;
}

.doc-stats {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.stat-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.stat-highlight {
  color: var(--text-secondary);
  font-weight: 500;
}

.view-mode-tabs {
  display: flex;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 0.2rem;
  border: 1px solid var(--border-subtle);
}
.view-tab-btn {
  background: transparent;
  border: none;
  font-size: 0.78rem;
  color: var(--text-secondary);
  padding: 0.25rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s ease;
}
.view-tab-btn.active {
  background: var(--bg-surface-hover);
  color: var(--accent-primary);
  font-weight: 600;
}

.content-viewport {
  flex: 1;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  display: flex;
  position: relative;
  min-height: 0;
}

/* Desktop Wide Markdown Container: Mở rộng lên 1320px */
.markdown-body-container {
  flex: 1;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 2.5rem 3rem 5rem;
  line-height: 1.8;
  color: var(--text-primary);
  transition: max-width 0.25s ease, padding 0.25s ease;
}

/* Chế độ Full-Width khi người dùng bật nút Mở rộng */
.content-viewport.full-width-mode .markdown-body-container {
  max-width: 96%;
  padding: 2rem 2.5rem 5rem;
}

.raw-editor-container {
  flex: 1;
  display: none;
  height: 100%;
}
.raw-editor-textarea {
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: none;
  outline: none;
  resize: none;
  padding: 2.5rem;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  line-height: 1.6;
}

/* Right TOC Sidebar */
.app-toc {
  width: var(--toc-width);
  height: 100%;
  max-height: 100%;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-subtle);
  padding: 0;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.toc-header {
  padding: 1.15rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.toc-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 0.85rem 1rem 3rem;
  min-height: 0;
}
.toc-link {
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-decoration: none;
  display: block;
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toc-link:hover {
  color: var(--text-primary);
  border-left-color: var(--accent-primary);
  background: var(--bg-surface-hover);
}
.toc-level-1 { padding-left: 0.4rem; font-weight: 600; }
.toc-level-2 { padding-left: 0.9rem; }
.toc-level-3 { padding-left: 1.4rem; font-size: 0.78rem; }
.toc-level-4 { padding-left: 1.9rem; font-size: 0.75rem; color: var(--text-muted); }

/* ==========================================================================
   Markdown Elements Styling
   ========================================================================== */
.markdown-body-container h1,
.markdown-body-container h2,
.markdown-body-container h3,
.markdown-body-container h4 {
  color: var(--text-primary);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.35;
  margin-top: 2.25rem;
  margin-bottom: 0.85rem;
  scroll-margin-top: 80px;
}
.markdown-body-container h1 {
  font-size: 2.15rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border-subtle);
}
.markdown-body-container h2 {
  font-size: 1.55rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-subtle);
}
.markdown-body-container h3 { font-size: 1.25rem; }
.markdown-body-container h4 { font-size: 1.05rem; }

.markdown-body-container p {
  margin-bottom: 1.25rem;
  color: var(--text-secondary);
  font-size: 1rem;
}

.markdown-body-container a {
  color: var(--accent-primary);
  text-decoration: none;
  border-bottom: 1px dashed var(--accent-primary);
  transition: opacity 0.15s ease;
}
.markdown-body-container a:hover {
  opacity: 0.8;
  border-bottom-style: solid;
}

.markdown-body-container strong {
  color: var(--text-primary);
  font-weight: 600;
}

.markdown-body-container hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 2.25rem 0;
}

.markdown-body-container ul,
.markdown-body-container ol {
  margin-bottom: 1.25rem;
  padding-left: 1.5rem;
  color: var(--text-secondary);
}
.markdown-body-container li {
  margin-bottom: 0.4rem;
}

/* Task Lists */
.markdown-body-container input[type="checkbox"] {
  margin-right: 0.5rem;
  accent-color: var(--accent-primary);
  transform: translateY(1px);
}

/* Blockquotes */
.markdown-body-container blockquote {
  border-left: 4px solid var(--accent-primary);
  background: var(--bg-surface);
  padding: 1.1rem 1.35rem;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin: 1.75rem 0;
  color: var(--text-secondary);
  font-style: italic;
}
.markdown-body-container blockquote p:last-child {
  margin-bottom: 0;
}

/* Tables */
.markdown-body-container table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.75rem 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-size: 0.92rem;
  display: table;
}
.markdown-body-container th,
.markdown-body-container td {
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  text-align: left;
}
.markdown-body-container th:last-child,
.markdown-body-container td:last-child {
  border-right: none;
}
.markdown-body-container tr:last-child td {
  border-bottom: none;
}
.markdown-body-container th {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
}
.markdown-body-container tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.015);
}

/* Inline Code */
.markdown-body-container :not(pre) > code {
  background: var(--bg-code);
  border: 1px solid var(--border-subtle);
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: var(--accent-primary);
}

/* Code Blocks */
.code-block-wrapper {
  margin: 1.75rem 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-code);
  box-shadow: var(--shadow-sm);
  width: 100%;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 1rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
}

.code-lang-badge {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-primary);
  letter-spacing: 0.05em;
}

.code-copy-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.code-copy-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}
.code-copy-btn.copied {
  color: var(--accent-success);
  border-color: var(--accent-success);
}

.markdown-body-container pre {
  margin: 0;
  padding: 1.25rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.6;
}

/* Fullscreen Drag & Drop Overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 13, 22, 0.88);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  border: 3px dashed var(--accent-primary);
  margin: 1rem;
  border-radius: var(--radius-lg);
}
.drop-overlay.active {
  display: flex;
}
.drop-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.drop-icon {
  width: 64px;
  height: 64px;
  color: var(--accent-primary);
  animation: bounce 1s infinite alternate;
}
.drop-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}
.drop-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
}

/* Animations */
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

/* ==========================================================================
   Mobile Responsive System (<= 768px)
   Khắc phục toàn diện lỗi hiển thị trên điện thoại
   ========================================================================== */
@media (max-width: 1024px) {
  .app-toc {
    display: none !important;
    width: 0 !important;
  }
  .app-main {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 100% !important;
    min-width: 0 !important;
  }
  .content-viewport {
    width: 100% !important;
    max-width: 100% !important;
  }
  .markdown-body-container {
    width: 100% !important;
    max-width: 100% !important;
  }
}

@media (max-width: 768px) {
  /* Header trên điện thoại */
  .app-header {
    padding: 0 0.65rem;
    height: 54px;
  }
  
  .brand-section {
    gap: 0.5rem;
  }
  
  .brand-title {
    font-size: 0.95rem;
  }

  .active-file-title-wrap {
    display: none !important; /* Ẩn tên file dài trên header mobile */
  }

  .header-actions {
    gap: 0.35rem;
  }

  /* Nút hành động trên mobile: Ẩn chữ, chỉ hiển thị icon */
  .btn .btn-text {
    display: none !important;
  }

  .btn-upload,
  .btn-download {
    padding: 0 !important;
    width: 36px !important;
    height: 36px !important;
    justify-content: center !important;
    border-radius: var(--radius-sm);
  }

  .chevron-icon {
    display: none !important;
  }

  /* Ẩn nút chuyển wide screen trên mobile */
  #widthToggleBtn {
    display: none !important;
  }

  /* Meta Bar trên mobile: Gọn gàng 1 dòng */
  .doc-meta-bar {
    padding: 0.45rem 0.75rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  .doc-stats {
    font-size: 0.72rem;
    gap: 0.6rem;
    justify-content: space-between;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .doc-stats .stat-item span:first-child {
    display: none; /* Ẩn nhãn chữ như "Kích thước:", chỉ hiện giá trị "3.5 KB" */
  }

  /* Ẩn hoàn toàn tab "Chia đôi" trên màn hình điện thoại */
  .split-tab,
  [data-mode="split"] {
    display: none !important;
  }

  .view-mode-tabs {
    width: 100%;
    display: flex;
  }
  .view-tab-btn {
    flex: 1;
    text-align: center;
    padding: 0.3rem 0.5rem;
    font-size: 0.78rem;
  }

  /* Sidebar Drawer */
  .app-sidebar {
    position: fixed;
    top: 54px;
    bottom: 0;
    left: 0;
    width: 280px;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }

  /* Markdown Content Padding & Headings trên mobile */
  .markdown-body-container {
    padding: 1.25rem 0.85rem 4rem !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .markdown-body-container h1 {
    font-size: 1.45rem;
    line-height: 1.35;
    margin-top: 1.5rem;
  }
  .markdown-body-container h2 {
    font-size: 1.25rem;
    margin-top: 1.35rem;
  }
  .markdown-body-container h3 {
    font-size: 1.1rem;
  }
  .markdown-body-container p {
    font-size: 0.95rem;
  }

  /* Tables cuộn ngang an toàn */
  .markdown-body-container table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Raw textarea padding */
  .raw-editor-textarea {
    padding: 1rem;
    font-size: 0.85rem;
  }
}

/* ==========================================================================
   TsByin Custom Dark-Tech Confirmation Modal
   ========================================================================== */
.custom-modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 16, 0.82);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  z-index: 2500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  animation: modalFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalFadeIn {
  from { opacity: 0; backdrop-filter: blur(0px); }
  to { opacity: 1; backdrop-filter: blur(16px) saturate(180%); }
}

.custom-dialog {
  background: linear-gradient(165deg, rgba(17, 24, 39, 0.95) 0%, rgba(10, 14, 26, 0.98) 100%);
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: 20px;
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.8),
              0 0 35px -5px rgba(56, 189, 248, 0.15),
              inset 0 1px 0 rgba(255, 255, 255, 0.12);
  width: 100%;
  max-width: 440px;
  padding: 1.85rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: relative;
  overflow: hidden;
  animation: dialogPop 0.26s cubic-bezier(0.16, 1, 0.3, 1);
}

.custom-dialog::before {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(56, 189, 248, 0.6), transparent);
}

@keyframes dialogPop {
  from { opacity: 0; transform: translateY(16px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.custom-dialog-header {
  display: flex;
  align-items: flex-start;
  gap: 1.1rem;
}

.custom-dialog-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.16), rgba(99, 102, 241, 0.1));
  color: var(--accent-primary);
  border: 1px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.3s ease;
}
.custom-dialog-icon-wrap.danger {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.18), rgba(244, 63, 94, 0.1));
  color: var(--accent-danger);
  border-color: rgba(239, 68, 68, 0.4);
  box-shadow: 0 0 22px rgba(239, 68, 68, 0.25);
}

.custom-dialog-title-wrap {
  flex: 1;
}

.custom-dialog-title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.custom-dialog-message {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-top: 0.45rem;
  line-height: 1.55;
}

.custom-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

.custom-dialog-actions .btn {
  padding: 0.65rem 1.25rem;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 10px;
}

/* ==========================================================================
   TsByin Bespoke Dynamic Island / Cyber-Capsule Toast System
   ========================================================================== */
.toast-container {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 2rem);
}

.toast-capsule {
  pointer-events: auto;
  cursor: pointer;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.15rem 0.6rem 0.75rem;
  background: rgba(8, 12, 22, 0.88);
  backdrop-filter: blur(24px) saturate(190%);
  -webkit-backdrop-filter: blur(24px) saturate(190%);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 999px;
  box-shadow: 0 16px 42px -6px rgba(0, 0, 0, 0.75),
              0 0 25px -4px rgba(56, 189, 248, 0.25),
              inset 0 1px 0 rgba(255, 255, 255, 0.14);
  color: var(--text-primary);
  overflow: hidden;
  animation: toastDropIn 0.34s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease, filter 0.2s ease;
  user-select: none;
}

.toast-capsule:hover {
  transform: scale(1.02);
  border-color: rgba(56, 189, 248, 0.45);
}

@keyframes toastDropIn {
  0% {
    opacity: 0;
    transform: translateY(-28px) scale(0.92);
  }
  65% {
    opacity: 1;
    transform: translateY(4px) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.toast-capsule.toast-exit {
  opacity: 0 !important;
  transform: translateY(-20px) scale(0.94) !important;
  filter: blur(4px) !important;
}

/* Status variants */
.toast-capsule.toast-success {
  border-color: rgba(52, 211, 153, 0.32);
  box-shadow: 0 16px 42px -6px rgba(0, 0, 0, 0.75),
              0 0 28px -4px rgba(52, 211, 153, 0.28),
              inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
.toast-capsule.toast-error {
  border-color: rgba(248, 113, 113, 0.35);
  box-shadow: 0 16px 42px -6px rgba(0, 0, 0, 0.75),
              0 0 28px -4px rgba(248, 113, 113, 0.3),
              inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
.toast-capsule.toast-info {
  border-color: rgba(56, 189, 248, 0.35);
  box-shadow: 0 16px 42px -6px rgba(0, 0, 0, 0.75),
              0 0 28px -4px rgba(56, 189, 248, 0.28),
              inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

/* Icon halo */
.toast-halo-icon {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}
.toast-success .toast-halo-icon {
  background: rgba(52, 211, 153, 0.16);
  color: #34d399;
  box-shadow: 0 0 12px rgba(52, 211, 153, 0.4);
}
.toast-error .toast-halo-icon {
  background: rgba(248, 113, 113, 0.18);
  color: #f87171;
  box-shadow: 0 0 12px rgba(248, 113, 113, 0.4);
}
.toast-info .toast-halo-icon {
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

/* Content */
.toast-content {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.toast-brand-chip {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent-primary);
  border: 1px solid rgba(56, 189, 248, 0.22);
}
.toast-success .toast-brand-chip {
  background: rgba(52, 211, 153, 0.1);
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.22);
}
.toast-error .toast-brand-chip {
  background: rgba(248, 113, 113, 0.12);
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.25);
}

.toast-text {
  font-size: 0.86rem;
  font-weight: 500;
  color: #f1f5f9;
  line-height: 1.4;
}

/* Micro Hairline Timer Bar */
.toast-timer-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  width: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  transition: width linear;
}
.toast-success .toast-timer-bar {
  background: linear-gradient(90deg, #34d399, #06b6d4);
}
.toast-error .toast-timer-bar {
  background: linear-gradient(90deg, #f87171, #fb923c);
}

@media (max-width: 640px) {
  .toast-container {
    top: 1rem;
    max-width: calc(100vw - 1.5rem);
  }
  .toast-capsule {
    padding: 0.55rem 0.95rem 0.55rem 0.65rem;
    border-radius: 14px;
    gap: 0.55rem;
  }
  .toast-content {
    white-space: normal;
  }
  .toast-text {
    font-size: 0.8rem;
  }
  .toast-brand-chip {
    display: none;
  }
}
