/* File Manager — fullscreen app shell (pairs with site/js/file-manager.js). */

.tool-widget[data-tool="file-manager"] {
  padding: 0;
  overflow: hidden;
  border: 0;
  background: none;
  box-shadow: none;
}
.tool-widget[data-tool="file-manager"] .tool-output { display: none; }

#fileManager {
  display: block;
  height: calc(100dvh - 120px);
  min-height: 560px;
  visibility: hidden;
  font-family: var(--font-sans, "Geist", system-ui, sans-serif);
  color: var(--ink, #0f172a);
  background: var(--surface, #fff);
}
#fileManager.ready { visibility: visible; }

html.fm-fs .site-header,
html.fm-fs .breadcrumb,
html.fm-fs .tool-header,
html.fm-fs .reading-progress,
html.fm-fs .site-footer,
html.fm-fs footer,
html.fm-fs .back-to-top,
html.fm-fs #toolHistory,
html.fm-fs .tool-howto,
html.fm-fs .tool-explainer,
html.fm-fs .tool-disclaimer-line,
html.fm-fs .tools-cta,
html.fm-fs .tool-related,
html.fm-fs .tool-guide-link,
html.fm-fs .tool-api-note {
  display: none !important;
}
html.fm-fs,
html.fm-fs body { overflow: hidden; overscroll-behavior: none; }
html.fm-fs main { padding: 0 !important; }
html.fm-fs .tool-widget[data-tool="file-manager"] {
  position: fixed;
  inset: 0;
  z-index: 200;
  height: 100dvh;
  margin: 0;
  border: 0;
  border-radius: 0;
  background-color: var(--surface);
}
html.fm-fs #fileManager { height: 100dvh; min-height: 0; }

.fm {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line, #e2e8f0);
  background: var(--canvas, #f8fafc);
}
html.fm-fs .fm { border: 0; }

.fm * { box-sizing: border-box; }
.fm button, .fm input, .fm select, .fm textarea {
  font: inherit;
  color: inherit;
}
.fm-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 8px;
  background: var(--surface, #fff);
  cursor: pointer;
  white-space: nowrap;
}
.fm-btn:hover { background: var(--canvas, #f1f5f9); }
.fm-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.fm-btn.primary {
  background: var(--accent, #4f46e5);
  border-color: transparent;
  color: #fff;
}
.fm-btn.primary:hover { filter: brightness(1.05); }
.fm-btn.ghost { border-color: transparent; background: transparent; }
.fm-btn.danger:hover { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.fm-ico {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fm-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface, #fff);
  border-bottom: 1px solid var(--line, #e2e8f0);
  min-height: 48px;
}
.fm-brand {
  font-weight: 650;
  letter-spacing: -0.02em;
  margin-right: 4px;
}
.fm-top-spacer { flex: 1; }
.fm-status {
  font-size: 12px;
  color: var(--ink-muted, #64748b);
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fm-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 6px 10px;
  background: var(--surface, #fff);
  border-bottom: 1px solid var(--line, #e2e8f0);
}
.fm-search {
  margin-left: auto;
  height: 32px;
  min-width: 160px;
  max-width: 240px;
  width: 28vw;
  padding: 0 10px;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 8px;
  background: var(--canvas, #f8fafc);
}

.fm-body {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) minmax(280px, 38%);
  min-height: 0;
  height: 100%;
}
.fm-side, .fm-main, .fm-preview {
  min-height: 0;
  overflow: auto;
  background: var(--surface, #fff);
}
.fm-side {
  border-right: 1px solid var(--line, #e2e8f0);
  display: flex;
  flex-direction: column;
}
.fm-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted, #64748b);
}
.fm-conn {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 6px 8px;
  border-bottom: 1px solid var(--line, #e2e8f0);
}
.fm-conn-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}
.fm-conn-item:hover { background: var(--canvas, #f1f5f9); }
.fm-conn-item.on {
  background: color-mix(in srgb, var(--accent, #4f46e5) 12%, transparent);
  color: var(--accent, #4f46e5);
  font-weight: 600;
}
.fm-tree { padding: 8px 6px 16px; flex: 1; overflow: auto; }
.fm-tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  padding: 5px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
}
.fm-tree-row:hover { background: var(--canvas, #f1f5f9); }
.fm-tree-row.on {
  background: color-mix(in srgb, var(--accent, #4f46e5) 14%, transparent);
}
.fm-tree-row .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fm-main { display: flex; flex-direction: column; min-width: 0; }
.fm-crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line, #e2e8f0);
  font-size: 13px;
  color: var(--ink-muted, #64748b);
}
.fm-crumbs button {
  border: 0;
  background: transparent;
  color: var(--accent, #4f46e5);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}
.fm-crumbs button:hover { background: var(--canvas, #f1f5f9); }
.fm-list-wrap { flex: 1; overflow: auto; min-height: 0; }
.fm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.fm-table th {
  position: sticky;
  top: 0;
  text-align: left;
  padding: 8px 12px;
  background: var(--canvas, #f8fafc);
  border-bottom: 1px solid var(--line, #e2e8f0);
  font-weight: 600;
  color: var(--ink-muted, #64748b);
  font-size: 12px;
}
.fm-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line, #e2e8f0);
  vertical-align: middle;
}
.fm-table tr { cursor: pointer; }
.fm-table tr:hover td { background: var(--canvas, #f8fafc); }
.fm-table tr.sel td {
  background: color-mix(in srgb, var(--accent, #4f46e5) 10%, transparent);
}
.fm-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.fm-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fm-empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--ink-muted, #64748b);
}

.fm-preview {
  border-left: 1px solid var(--line, #e2e8f0);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.fm-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 6px 0;
  border-bottom: 1px solid var(--line, #e2e8f0);
  overflow-x: auto;
  background: var(--canvas, #f8fafc);
}
.fm-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 160px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
}
.fm-tab.on {
  background: var(--surface, #fff);
  border-color: var(--line, #e2e8f0);
}
.fm-tab .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fm-tab .x {
  border: 0;
  background: transparent;
  cursor: pointer;
  opacity: 0.55;
  padding: 0;
  line-height: 1;
}
.fm-tab .x:hover { opacity: 1; }
.fm-editor-bar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line, #e2e8f0);
}
.fm-editor {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: 0;
  resize: none;
  padding: 12px;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 13px;
  line-height: 1.5;
  background: var(--surface, #fff);
  outline: none;
}
.fm-img-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
  background:
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%) 0 0 / 16px 16px,
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%) 0 8px / 16px 16px,
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%) 8px -8px / 16px 16px,
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%) -8px 0 / 16px 16px,
    #f8fafc;
}
.fm-img-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}
.fm-preview-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-muted, #64748b);
  padding: 24px;
  text-align: center;
  font-size: 13px;
}

.fm-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  border-top: 1px solid var(--line, #e2e8f0);
  background: var(--surface, #fff);
  font-size: 12px;
  color: var(--ink-muted, #64748b);
}
.fm-privacy { margin-left: auto; }

.fm-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  background: rgba(15, 23, 42, 0.45);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.fm-modal[hidden] { display: none !important; }
.fm-dialog {
  width: min(440px, 100%);
  max-height: min(92dvh, 720px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface, #fff);
  border-radius: 14px;
  border: 1px solid var(--line, #e2e8f0);
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.28);
  overflow: hidden;
}
.fm-dialog-head {
  flex: 0 0 auto;
  padding: 16px 18px 0;
}
.fm-dialog h2 {
  margin: 0 0 6px;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.fm-dialog p.lead {
  margin: 0 0 12px;
  color: var(--ink-muted, #64748b);
  font-size: 13px;
}
.fm-dialog-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 18px 8px;
  -webkit-overflow-scrolling: touch;
}
.fm-field { margin-bottom: 10px; }
.fm-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--ink-muted, #64748b);
}
.fm-field input[type="text"],
.fm-field input[type="password"],
.fm-field input[type="number"],
.fm-field select,
.fm-field textarea {
  width: 100%;
  padding: 0 10px;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 8px;
  background: var(--canvas, #f8fafc);
}
.fm-field input[type="text"],
.fm-field input[type="password"],
.fm-field input[type="number"],
.fm-field select {
  height: 36px;
}
.fm-field textarea {
  padding: 8px 10px;
  min-height: 64px;
  max-height: 140px;
  resize: vertical;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 12px;
  line-height: 1.4;
}
.fm-field[hidden],
.fm-sftp-only[hidden] { display: none !important; }
.fm-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin: 4px 0 8px;
}
.fm-dialog-actions {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line, #e2e8f0);
  background: var(--surface, #fff);
}

.fm-busy {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--surface, #fff) 70%, transparent);
  font-size: 13px;
  color: var(--ink-muted, #64748b);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.fm.loading .fm-busy { opacity: 1; pointer-events: auto; }
.fm { position: relative; }

@media (max-width: 960px) {
  .fm-body { grid-template-columns: 200px minmax(0, 1fr); }
  .fm-preview { display: none; }
  .fm.show-preview .fm-side { display: none; }
  .fm.show-preview .fm-main { display: none; }
  .fm.show-preview .fm-preview { display: flex; grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .fm-body { grid-template-columns: 1fr; }
  .fm-side { display: none; }
  .fm.show-side .fm-side { display: flex; }
  .fm.show-side .fm-main { display: none; }
  #fileManager { height: calc(100dvh - 72px); min-height: 480px; }
  .fm-search { width: 100%; max-width: none; margin-left: 0; }
}
