:root {
  --bg: #f6f6f7;
  --surface: #ffffff;
  --surface-subtle: #f1f1f3;
  --surface-hover: #e8e8ec;
  --border: rgba(0, 0, 0, 0.07);
  --border-strong: rgba(0, 0, 0, 0.14);
  --text: #111113;
  --text-secondary: #6e6e77;
  --text-tertiary: #9ca3af;
  --accent: #111113;
  --accent-hover: #27272a;
  --danger: #dc2626;
  --danger-subtle: rgba(220, 38, 38, 0.08);
  --success: #16a34a;
  --radius-card: 14px;
  --radius-ctrl: 10px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.03), 0 8px 24px rgba(0, 0, 0, 0.04);
  --shadow-modal: 0 4px 12px rgba(0, 0, 0, 0.06), 0 24px 48px rgba(0, 0, 0, 0.14);
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Monaco, Consolas, monospace;

  /* Compatibility aliases for dynamic JS markup */
  --bg2: var(--surface);
  --bg3: var(--surface-subtle);
  --accent2: #3f3f46;
  --text-muted: var(--text-secondary);
  --text-dim: var(--text-tertiary);
  --radius: var(--radius-card);
  --shadow: var(--shadow-card);
}

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

html, body {
  min-height: 100%;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.008em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

button, input, select, textarea, a {
  font-family: inherit;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* ── Full-Window Drag & Drop Feedback ── */
body.window-drag-over::after {
  content: '';
  position: fixed;
  inset: 12px;
  border: 2px dashed var(--accent);
  border-radius: 18px;
  background: rgba(17, 17, 19, 0.03);
  pointer-events: none;
  z-index: 9000;
}

body.window-drag-over .drop-zone {
  border-color: var(--accent);
  background: var(--surface-subtle);
}

/* ── Shared Controls & Inputs ── */
.input-field {
  width: 100%;
  height: 40px;
  background: var(--surface-subtle);
  border: 1px solid transparent;
  border-radius: var(--radius-ctrl);
  padding: 0 13px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-field::placeholder {
  color: var(--text-tertiary);
}

.input-field:focus {
  background: var(--surface);
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(17, 17, 19, 0.05);
}

.input-readonly {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  background: var(--accent);
  color: #ffffff;
  border: 1px solid var(--accent);
  border-radius: var(--radius-ctrl);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

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

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

.btn-primary:disabled {
  background: var(--surface-subtle);
  border-color: var(--border);
  color: var(--text-tertiary);
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-ctrl);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-secondary:hover {
  background: var(--surface-subtle);
}

.btn-block {
  width: 100%;
  height: 40px;
}

.btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 30px;
  padding: 0 11px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-sm svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.btn-sm:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.btn-ghost-sm {
  background: var(--surface-subtle);
  border-color: transparent;
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.btn-ghost-sm:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-danger-outline {
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.25);
}

.btn-danger-outline:hover {
  background: var(--danger-subtle);
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.4);
}

.btn-danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger-solid:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #ffffff;
}

.btn-danger-block {
  width: 100%;
  height: 38px;
  background: var(--danger-subtle);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.2);
  border-radius: var(--radius-ctrl);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-danger-block:hover {
  background: var(--danger);
  color: #ffffff;
}

.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-icon svg {
  width: 17px;
  height: 17px;
}

.btn-icon:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.btn-icon.btn-danger:hover {
  background: var(--danger-subtle);
  color: var(--danger);
}

/* ── User Badges ── */
.user-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.user-badge:empty {
  display: none;
}

.badge-admin {
  background: rgba(17, 17, 19, 0.08);
  color: var(--text);
}

.badge-perm {
  background: var(--surface-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.badge-temp {
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
}

/* ── Login Screen ── */
.login-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, #ffffff 0%, var(--bg) 70%);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 356px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px 28px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.login-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.login-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.login-brand {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-form .btn-block {
  margin-top: 4px;
}

/* ── Workspace Portal ── */
.portal-screen {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, #ffffff 0%, var(--bg) 70%);
  z-index: 9500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.portal-shell {
  width: 100%;
  max-width: 580px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.portal-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
}

.portal-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.portal-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
}

.portal-brand-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
}

.portal-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.portal-action-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.portal-action-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text);
}

.portal-action-danger:hover {
  background: var(--danger-subtle);
  color: var(--danger);
}

.portal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.portal-grid[data-cards="1"] {
  grid-template-columns: minmax(0, 320px);
  justify-content: center;
}

.portal-grid[data-cards="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.portal-grid[data-cards="3"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.portal-grid[data-cards="4"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.portal-no-access {
  padding: 20px 18px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.5;
}

.portal-choice {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 138px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  text-decoration: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.15s ease;
}

.portal-choice:hover {
  border-color: var(--border-strong);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06), 0 12px 28px rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
}

.portal-choice:active {
  transform: scale(0.99);
}

.portal-choice-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.portal-choice-icon svg {
  width: 20px;
  height: 20px;
}

.portal-choice-chat .portal-choice-icon {
  background: var(--accent);
  color: #ffffff;
}

.portal-choice-drive .portal-choice-icon {
  background: var(--surface-subtle);
  color: var(--text);
  border: 1px solid var(--border);
}

.portal-choice-notes .portal-choice-icon {
  background: linear-gradient(135deg, #27272a, #18181b);
  color: #fafafa;
  border: 1px solid rgba(0, 0, 0, 0.14);
}

.portal-choice-admin .portal-choice-icon {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  border: 1px solid rgba(37, 99, 235, 0.22);
}

.portal-choice-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 24px;
}

.portal-choice-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.portal-choice-arrow {
  font-size: 16px;
  color: var(--text-tertiary);
  transition: transform 0.18s ease, color 0.18s ease;
}

.portal-choice:hover .portal-choice-arrow {
  color: var(--text);
  transform: translateX(3px);
}

/* ── Sticky Top Bar ── */
.drive-header {
  position: sticky;
  top: 0;
  z-index: 80;
  background: rgba(246, 246, 247, 0.82);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}

.drive-header-inner {
  max-width: 1080px;
  margin: 0 auto;
  height: 56px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.header-logo {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
  flex-shrink: 0;
}

.header-title {
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Quota Bar ── */
.quota-bar-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 6px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  max-width: 240px;
  min-width: 0;
}

.quota-bar {
  width: 56px;
  height: 5px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}

.quota-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.quota-fill.quota-warn {
  background: var(--danger);
}

.quota-text {
  font-size: 11.5px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Cloud Drive Workspace Container ── */
.drive-workspace {
  max-width: 1080px;
  margin: 0 auto;
  padding: 22px 20px 56px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Top Composer Deck ── */
.composer-deck {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 16px;
  align-items: stretch;
}

.composer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 46px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

/* Segmented Mode Toggle */
.mode-toggle {
  display: inline-flex;
  align-items: center;
  background: var(--surface-subtle);
  padding: 2px;
  border-radius: 8px;
  gap: 2px;
}

.mode-option {
  position: relative;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mode-option input:checked + .mode-label {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* File Drop Zone */
.drop-zone {
  flex: 1;
  margin: 12px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px;
  background: rgba(241, 241, 243, 0.4);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: border-color 0.15s ease, background 0.15s ease;
  overflow: hidden;
  min-height: 150px;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--surface-subtle);
}

.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px 16px;
  text-align: center;
}

.drop-icon-wrap {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: transform 0.15s ease;
}

.drop-zone:hover .drop-icon-wrap,
.drop-zone.drag-over .drop-icon-wrap {
  transform: translateY(-2px);
}

.drop-icon {
  width: 18px;
  height: 18px;
}

.drop-hint {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.upload-progress {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-bar {
  flex: 1;
  height: 5px;
  background: var(--surface-subtle);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.progress-text,
#progress-text {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Text / Clipboard Composer */
#text-input {
  flex: 1;
  width: 100%;
  min-height: 112px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  padding: 12px 14px;
  resize: none;
}

#text-input::placeholder {
  color: var(--text-tertiary);
}

.text-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: rgba(246, 246, 247, 0.5);
}

#text-name {
  flex: 1;
  height: 34px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  min-width: 0;
  transition: border-color 0.15s ease;
}

#text-name::placeholder {
  color: var(--text-tertiary);
}

#text-name:focus {
  border-color: var(--border-strong);
}

.text-footer .btn-primary {
  height: 34px;
  padding: 0 15px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* ── File & Snippet Stream Section ── */
.panel-items {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.items-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.items-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 20px;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Segmented Filter Buttons */
.filter-btns {
  display: inline-flex;
  align-items: center;
  background: var(--surface-subtle);
  padding: 2px;
  border-radius: 8px;
  gap: 2px;
}

.filter-btn {
  height: 26px;
  padding: 0 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.filter-btn:hover {
  color: var(--text);
}

.filter-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.items-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Search Input */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-input {
  width: 180px;
  height: 32px;
  padding: 0 10px 0 30px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: width 0.2s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input::placeholder {
  color: var(--text-tertiary);
}

.search-input:focus {
  width: 220px;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(17, 17, 19, 0.04);
}

.refresh-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a1a1aa;
  opacity: 0.45;
  transition: opacity 0.2s ease, background 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
}

.refresh-dot.active {
  background: var(--success);
  opacity: 1;
  transform: scale(1.25);
}

/* ── Sticky Batch Selection Bar ── */
.selection-bar {
  position: sticky;
  top: 64px;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.select-all-wrap {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  user-select: none;
}

.selection-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-batch-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-batch-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
}

.btn-batch-primary:disabled {
  background: var(--surface-subtle);
  border-color: var(--border);
  color: var(--text-tertiary);
  cursor: not-allowed;
}

.btn-batch-danger {
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.25);
}

.btn-batch-danger:hover {
  background: var(--danger-subtle);
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.4);
}

/* ── Custom Checkbox ── */
.item-check {
  appearance: none;
  -webkit-appearance: none;
  width: 17px;
  height: 17px;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.item-check:hover {
  border-color: var(--text-secondary);
}

.item-check:checked {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23ffffff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='3.5 8.5 6.5 11.5 12.5 4.5'/%3E%3C/svg%3E");
  background-size: 12px 12px;
  background-position: center;
  background-repeat: no-repeat;
}

.item-check:indeterminate {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23ffffff' stroke-width='2.2' stroke-linecap='round'%3E%3Cline x1='4' y1='8' x2='12' y2='8'/%3E%3C/svg%3E");
  background-size: 12px 12px;
  background-position: center;
  background-repeat: no-repeat;
}

/* ── Items Stream List & Cards ── */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.item-card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

.item-card.selected {
  border-color: var(--accent);
  background: #fafafb;
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.item-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: #3f3f46;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  cursor: pointer;
}

.item-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.item-icon svg {
  width: 18px;
  height: 18px;
}

.item-icon.icon-image {
  color: #2563eb;
  background: rgba(37, 99, 235, 0.06);
  border-color: rgba(37, 99, 235, 0.12);
}

.item-icon.icon-code {
  color: #4f46e5;
  background: rgba(79, 70, 229, 0.06);
  border-color: rgba(79, 70, 229, 0.12);
}

.item-icon.icon-video,
.item-icon.icon-audio {
  color: #7c3aed;
  background: rgba(124, 58, 237, 0.06);
  border-color: rgba(124, 58, 237, 0.12);
}

.item-icon.icon-archive {
  color: #b45309;
  background: rgba(180, 83, 9, 0.06);
  border-color: rgba(180, 83, 9, 0.12);
}

.item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.item-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  word-break: break-word;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.item-name:hover {
  color: #000000;
}

.rename-input,
.item-rename-input,
.item-name input {
  height: 28px;
  padding: 0 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  min-width: 160px;
}

.item-title-text {
  word-break: break-word;
}

.mode-badge,
.uploader-badge {
  display: inline-flex;
  align-items: center;
  height: 19px;
  padding: 0 6px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 500;
  background: var(--surface-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  line-height: 1;
  white-space: nowrap;
}

.item-preview {
  font-size: 12.5px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  line-height: 1.45;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-preview a.detected-link {
  color: #2563eb;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 1px;
  font-size: 12px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.item-size {
  color: var(--text-secondary);
}

.item-expiry {
  color: var(--text-tertiary);
}

.item-expiry.soon {
  color: #d97706;
  font-weight: 500;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.btn-action {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-action svg {
  width: 15px;
  height: 15px;
}

.btn-action:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.btn-action.btn-open-link {
  color: #2563eb;
}

.btn-action.btn-open-link:hover {
  background: rgba(37, 99, 235, 0.08);
  color: #1d4ed8;
}

.btn-action.btn-del:hover {
  background: var(--danger-subtle);
  color: var(--danger);
}

.btn-action.btn-copy-ok,
.btn-sm.btn-copy-ok {
  background: rgba(22, 163, 74, 0.1);
  color: var(--success);
  border-color: rgba(22, 163, 74, 0.2);
}

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 56px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  color: var(--text-tertiary);
  text-align: center;
}

.empty-icon {
  width: 28px;
  height: 28px;
  opacity: 0.65;
}

.empty-state p {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ── Modals ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 9700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(17, 17, 19, 0.36);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-box {
  position: relative;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 88vh;
  overflow: hidden;
}

.modal-xs {
  max-width: 310px;
  align-items: center;
}

.modal-sm {
  max-width: 380px;
}

.modal-lg {
  max-width: 540px;
}

.modal-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text);
}

.modal-item-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  word-break: break-all;
  margin-top: -6px;
}

.modal-stack {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-subbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-summary {
  font-size: 12.5px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.modal-subbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.modal-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 2px;
}

.empty-inline {
  padding: 20px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--text-tertiary);
}

/* QR Modal */
.qr-container {
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-container canvas {
  display: block;
  border-radius: 6px;
}

.qr-url {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  word-break: break-all;
  text-align: center;
}

/* Devices & Accounts Rows */
.device-item {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctrl);
  padding: 11px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.device-item.current {
  background: var(--surface);
  border-color: var(--border-strong);
}

.device-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 13px;
  min-width: 0;
  flex: 1;
}

.device-info .ip {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}

.device-info .ua {
  color: var(--text-tertiary);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Account Composer inside Modal */
.acct-composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.acct-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.acct-perm-row {
  gap: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.acct-perm-title {
  color: var(--text-secondary);
  font-size: 12.5px;
}

.acct-perm-chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
}

.perm-pill-btn {
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.12s ease;
}

.perm-pill-btn.is-on {
  border-color: rgba(22, 163, 74, 0.35);
  background: rgba(22, 163, 74, 0.1);
  color: #15803d;
  font-weight: 500;
}

.perm-pill-btn.is-off {
  border-color: rgba(220, 38, 38, 0.25);
  background: rgba(220, 38, 38, 0.08);
  color: #dc2626;
}

.acct-composer .input-field {
  background: var(--surface);
  border-color: var(--border);
  height: 36px;
  font-size: 13px;
}

.acct-select {
  max-width: 140px;
}

.acct-random-btn {
  height: 36px;
  padding: 0 12px;
}

.acct-submit {
  flex: 1;
  height: 36px;
  font-size: 13px;
}

.acct-created-card {
  width: 100%;
  background: var(--surface-subtle);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.acct-created-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.acct-created-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.acct-created-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

.acct-created-creds {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 13px;
}

.acct-created-creds div {
  display: flex;
  align-items: center;
  gap: 6px;
}

.acct-created-creds span {
  color: var(--text-secondary);
}

.acct-created-creds strong {
  font-family: var(--font-mono);
  color: var(--text);
}

/* ── Toast Notifications ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10000;
  pointer-events: none;
}

.toast {
  background: #18181b;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  animation: toastIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 320px;
}

.toast.toast-err {
  background: var(--danger);
  border-color: var(--danger);
}

.toast.toast-out {
  animation: toastOut 0.18s ease forwards;
}

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

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

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.22);
}

/* ── Responsive & Mobile Polish ── */
@media (max-width: 768px) {
  .input-field,
  #text-input,
  #text-name,
  .search-input {
    font-size: 16px;
  }

  .drive-header-inner {
    height: 52px;
    padding: 0 12px;
    gap: 8px;
  }

  .header-left {
    gap: 6px;
  }

  .header-title {
    font-size: 14.5px;
  }

  .quota-bar-wrap,
  #user-badge {
    display: none !important;
  }

  .header-right {
    gap: 2px;
  }

  .btn-icon {
    width: 32px;
    height: 32px;
  }

  .drive-workspace {
    padding: 12px 12px calc(32px + env(safe-area-inset-bottom, 0px));
    gap: 16px;
  }

  .composer-deck {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .drop-zone {
    min-height: 0;
    margin: 10px;
  }

  .drop-zone-inner {
    flex-direction: row;
    padding: 12px 14px;
    gap: 10px;
  }

  .drop-icon-wrap {
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }

  #text-input {
    min-height: 76px;
    padding: 10px 12px;
  }

  .items-header {
    gap: 8px;
  }

  .items-header-right {
    width: 100%;
    justify-content: space-between;
  }

  .search-wrap {
    flex: 1;
  }

  .search-input,
  .search-input:focus {
    width: 100%;
  }

  .selection-bar {
    top: 58px;
    padding: 8px 10px;
    flex-wrap: wrap;
  }

  .item-card {
    padding: 10px 12px;
    gap: 10px;
  }

  .item-icon {
    width: 34px;
    height: 34px;
  }

  .btn-action {
    width: 30px;
    height: 30px;
  }

  .acct-row {
    flex-wrap: wrap;
  }

  .acct-select {
    max-width: none;
    flex: 1;
  }

  #toast-container {
    left: 16px;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    align-items: center;
  }
}

@media (max-width: 460px) {
  .portal-top {
    flex-wrap: wrap;
  }

  .portal-grid,
  .portal-grid[data-cards="1"],
  .portal-grid[data-cards="2"],
  .portal-grid[data-cards="3"],
  .portal-grid[data-cards="4"] {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .portal-choice {
    min-height: 0;
    flex-direction: row;
    align-items: center;
    padding: 16px 18px;
  }

  .portal-choice-foot {
    margin-top: 0;
    flex: 1;
    margin-left: 14px;
  }
}

/* ── Ultra-Small Screen / Apple Watch Mode ── */
@media (max-width: 320px) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
  }

  .login-screen,
  .portal-screen {
    padding: 8px;
    align-items: flex-start;
  }

  .login-card {
    padding: 14px 12px;
    gap: 12px;
  }

  .portal-choice {
    padding: 12px;
  }

  .portal-choice-arrow {
    display: none;
  }
}

/* ── Instant Drive Preview Modal ── */
.modal-preview {
  max-width: min(1040px, 94vw);
  width: 94vw;
  height: min(88vh, 840px);
  max-height: 92vh;
  padding: 0;
  gap: 0;
}

.preview-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.preview-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.preview-kind-badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 6px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  flex-shrink: 0;
}

.preview-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  flex-shrink: 0;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.preview-mode-tabs {
  display: inline-flex;
  background: var(--surface-subtle);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.preview-tab {
  height: 26px;
  padding: 0 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.preview-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.preview-img-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.preview-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
}

.preview-stage.is-pdf-stage {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.preview-pdf-ios-bar {
  flex-shrink: 0;
  padding: 6px 12px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
}

.preview-pdf-ios-bar a {
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.preview-loading {
  margin: auto;
  color: var(--text-secondary);
  font-size: 13.5px;
}

.preview-image-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(circle, rgba(0, 0, 0, 0.04) 1px, transparent 1px) 0 0 / 16px 16px,
    #f3f4f6;
}

.preview-image-el {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  transition: transform 0.16s ease;
  transform-origin: center center;
}

.preview-pdf-frame {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: none;
  background: #525659;
  flex: 1;
  display: block;
}

.preview-media-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #111113;
}

.preview-video-el {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  outline: none;
}

.preview-audio-card {
  width: 100%;
  max-width: 480px;
  margin: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.preview-audio-card audio {
  width: 100%;
}

.preview-text-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 20px 24px;
  background: var(--surface);
}

.preview-truncated-banner {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
  font-size: 12.5px;
}

.preview-code-pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 2;
}

.preview-md-view {
  max-width: 780px;
  margin: 0 auto;
  font-size: 14.5px;
  line-height: 1.72;
  color: var(--text);
}

.preview-md-view h1,
.preview-md-view h2,
.preview-md-view h3,
.preview-md-view h4,
.preview-md-view h5,
.preview-md-view h6 {
  margin: 16px 0 8px;
  font-weight: 600;
  line-height: 1.35;
}
.preview-md-view h1 { font-size: 1.55em; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.preview-md-view h2 { font-size: 1.3em; }
.preview-md-view h3 { font-size: 1.12em; }
.preview-md-view h4 { font-size: 1em; }
.preview-md-view h5, .preview-md-view h6 { font-size: 0.92em; color: var(--text-secondary); }
.preview-md-view p { margin: 0 0 10px; }
.preview-md-view ul, .preview-md-view ol { margin: 6px 0 12px 22px; }
.preview-md-view li > ul, .preview-md-view li > ol { margin: 4px 0 4px 18px; }
.preview-md-view blockquote {
  border-left: 3px solid var(--border-strong);
  padding: 4px 12px;
  color: var(--text-secondary);
  margin: 10px 0;
}
.preview-md-view blockquote > p:last-child,
.preview-md-view blockquote > ul:last-child,
.preview-md-view blockquote > ol:last-child { margin-bottom: 0; }
.preview-math-block {
  margin: 12px 0;
  text-align: center;
  overflow-x: auto;
  background: transparent;
}
.preview-md-view .katex .cjk_fallback,
.preview-md-view .katex .mtext {
  font-family: var(--font-sans);
  font-size: 0.86em;
}
.preview-md-view code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--surface-subtle);
  padding: 2px 5px;
  border-radius: 4px;
}
.preview-md-view pre {
  background: #18181b;
  color: #f4f4f5;
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 10px 0;
}
.preview-md-view pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}
.preview-md-view hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}
.preview-md-view del {
  color: var(--text-tertiary);
  text-decoration: line-through;
}
.preview-md-table-wrap {
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.preview-md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.preview-md-table th, .preview-md-table td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.preview-md-table th {
  background: var(--surface-subtle);
  font-weight: 600;
}
.preview-task-list {
  list-style: none;
  margin-left: 4px !important;
  padding-left: 0;
}
.preview-task-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 4px 0;
}
.preview-task-item input[type="checkbox"] {
  margin-top: 4px;
  accent-color: var(--accent);
}
.preview-task-item.is-done span {
  text-decoration: line-through;
  color: var(--text-tertiary);
}
.preview-math-block {
  margin: 12px 0;
  text-align: center;
  overflow-x: auto;
}

.preview-csv-table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.preview-csv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.preview-csv-table th,
.preview-csv-table td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
  white-space: nowrap;
}

.preview-csv-table th {
  background: var(--surface-subtle);
  font-weight: 600;
  position: sticky;
  top: 0;
}

.preview-edit-textarea {
  width: 100%;
  height: 100%;
  min-height: 360px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  background: var(--surface);
  resize: none;
  outline: none;
}

.preview-binary-card {
  margin: auto;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.preview-binary-meta {
  font-size: 12.5px;
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  .modal-preview {
    width: 100vw;
    max-width: 100vw;
    height: 92dvh;
    border-radius: 14px 14px 0 0;
  }
  .preview-topbar {
    padding: 10px 12px;
  }
  .preview-text-wrap {
    padding: 14px;
  }
}

/* ── AI Policy & Governance Controls inside Account Modal ── */
.acct-ai-details {
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  padding: 6px 10px;
}

.acct-ai-summary {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.acct-ai-summary::after {
  content: '▾';
  font-size: 12px;
  color: var(--text-secondary);
}

.acct-ai-details[open] .acct-ai-summary::after {
  content: '▴';
}

.acct-ai-panel {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.acct-ai-toprow {
  flex-wrap: wrap;
}

.acct-ai-lbl {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.acct-select-sm {
  flex: 1;
  min-width: 120px;
  height: 32px !important;
  font-size: 12.5px !important;
}

.acct-models-wrap {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.acct-ai-presets {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.btn-xs {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}

.btn-xs:hover {
  background: var(--surface-hover, #ececef);
  color: var(--text);
}

.acct-model-chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 6px;
  max-height: 170px;
  overflow-y: auto;
}

.acct-model-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  font-size: 11.5px;
  color: var(--text);
  cursor: pointer;
}

.acct-model-chip small {
  color: var(--text-secondary);
  margin-left: auto;
  font-size: 10.5px;
}

.acct-ai-num-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.acct-ai-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.acct-ai-field .input-field {
  height: 32px !important;
  font-size: 12.5px !important;
}

.acct-ai-usage-banner {
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

@media (max-width: 560px) {
  .acct-ai-num-grid {
    grid-template-columns: 1fr;
  }
}
