/* Portfolio app — uses tokens from /css/style.css (the portal's shared theme).
   This file adds portfolio-specific layout: three-column header + sidebar +
   workspace, contenteditable editor, image grid. */

html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden; /* the workspace handles its own scrolling */
}

/* ────── Mobile blocker ────── */
.pf-mobile-block {
  position: fixed;
  inset: 0;
  z-index: 99;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.pf-mb-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 460px;
  text-align: center;
  box-shadow: var(--shadow);
}
.pf-mb-card i { font-size: 56px; color: var(--primary); margin-bottom: 12px; }
.pf-mb-card h1 { font-size: 22px; font-weight: 700; margin: 4px 0 12px; }
.pf-mb-card p { color: var(--text2); font-size: 15px; line-height: 1.5; margin: 8px 0; }
.pf-mb-card .pf-mb-note { font-size: 13px; padding: 12px; background: var(--card2); border-radius: var(--radius-sm); margin-top: 16px; }
.pf-mb-card code { background: var(--bg3); padding: 1px 6px; border-radius: 4px; font-family: ui-monospace, monospace; font-size: 12px; }
.pf-mb-card .btn { margin-top: 16px; }

/* ────── No-session ────── */
.pf-no-session { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.pf-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; max-width: 420px; text-align: center; box-shadow: var(--shadow); }
.pf-card h1 { font-size: 22px; margin: 12px 0 8px; }
.pf-card p { color: var(--text2); margin: 8px 0 20px; }

/* ────── App shell ────── */
.pf-app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}
.pf-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
}
.header-left, .header-right { display: flex; align-items: center; gap: 10px; }
.pf-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.pf-brand i { color: var(--primary); font-size: 22px; }
.portal-btn { color: var(--primary); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; background-size: cover; background-position: center; }

/* ────── Main layout ────── */
.pf-main {
  display: grid;
  grid-template-columns: 300px 1fr;
  overflow: hidden;
  min-height: 0;
}

/* ────── Sidebar ────── */
.pf-sidebar {
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.pf-sidebar-toolbar { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); }
.pf-side-btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  font: inherit; color: var(--text);
  cursor: pointer;
  font-size: 13px; font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}
.pf-side-btn:hover { background: var(--bg3); border-color: var(--primary); color: var(--primary); }
.pf-side-btn i { font-size: 16px; }

.pf-sidebar-tree { flex: 1; overflow-y: auto; padding: 8px 6px; }
.pf-loading { padding: 16px; color: var(--text3); font-size: 13px; text-align: center; }
.pf-empty-line { padding: 12px; color: var(--text3); font-size: 13px; font-style: italic; }
.pf-tree-node { user-select: none; }
.pf-tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  position: relative;
}
.pf-tree-row:hover { background: var(--card2); }
.pf-tree-row.is-active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.pf-tree-row.is-active .pf-tree-icon { color: var(--primary); }
.pf-tree-chevron { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; color: var(--text3); cursor: pointer; flex-shrink: 0; }
.pf-tree-chevron i { font-size: 16px; transition: transform 0.15s; }
.pf-tree-chevron.is-open i { transform: rotate(90deg); }
.pf-tree-icon { color: var(--text2); font-size: 16px; flex-shrink: 0; }
.pf-tree-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pf-tree-actions { display: none; gap: 2px; }
.pf-tree-row:hover .pf-tree-actions { display: flex; }
.pf-tree-actions .icon-btn { width: 22px; height: 22px; padding: 0; font-size: 14px; color: var(--text2); border-radius: 4px; }
.pf-tree-actions .icon-btn:hover { background: var(--bg3); color: var(--primary); }
.pf-tree-children { padding-left: 18px; display: none; }
.pf-tree-children.is-open { display: block; }

.pf-sidebar-foot { padding: 8px 12px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text3); }

/* ────── Workspace ────── */
.pf-workspace {
  overflow-y: auto;
  padding: 28px 36px 80px;
  background: var(--bg);
}
.pf-ws-empty {
  max-width: 480px; margin: 80px auto; text-align: center;
  color: var(--text2);
}
.pf-ws-empty i { font-size: 80px; color: var(--bg3); }
.pf-ws-empty h2 { font-size: 22px; color: var(--text); margin: 16px 0 8px; }
.pf-ws-empty p { font-size: 15px; line-height: 1.6; }

/* Item editor */
.pf-item { max-width: 980px; margin: 0 auto; }
.pf-item-crumbs { font-size: 13px; color: var(--text2); margin-bottom: 10px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pf-item-crumbs i { font-size: 14px; }
.pf-item-crumb { color: var(--text2); }
.pf-item-crumb.is-folder { color: var(--primary); font-weight: 600; }

.pf-item-title-input {
  width: 100%;
  font-size: 32px;
  font-weight: 800;
  font-family: inherit;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 4px 0;
  margin: 0 0 16px;
  outline: none;
}
.pf-item-title-input::placeholder { color: var(--text3); }

.pf-toolbar {
  display: flex; gap: 4px; flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  position: sticky;
  top: 0;
  z-index: 5;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.pf-tb-btn {
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text2);
  font-size: 18px;
  font-family: inherit;
  font-weight: 600;
}
.pf-tb-btn:hover { background: var(--bg3); color: var(--text); }
.pf-tb-btn.is-active { background: var(--primary-light); color: var(--primary); }
.pf-tb-divider { width: 1px; background: var(--border); margin: 4px 4px; }

.pf-body {
  min-height: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  font-size: 16px; line-height: 1.7;
  color: var(--text);
  outline: none;
  box-shadow: var(--shadow);
}
.pf-body:empty::before { content: attr(data-placeholder); color: var(--text3); }
.pf-body h2 { font-size: 24px; font-weight: 700; margin: 24px 0 12px; }
.pf-body h3 { font-size: 19px; font-weight: 700; margin: 20px 0 8px; }
.pf-body p { margin: 0 0 12px; }
.pf-body ul, .pf-body ol { margin: 0 0 12px; padding-left: 28px; }
.pf-body li { margin: 4px 0; }
.pf-body a { color: var(--primary); text-decoration: underline; }
.pf-body code { background: var(--bg3); padding: 1px 6px; border-radius: 4px; font-family: ui-monospace, monospace; font-size: 13px; }
.pf-body blockquote { border-left: 3px solid var(--primary); padding: 4px 12px; color: var(--text2); margin: 0 0 12px; }

/* Image grid */
.pf-images {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.pf-image-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.pf-image-thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: var(--bg3);
  display: block;
  cursor: zoom-in;
}
.pf-image-caption {
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  border-top: 1px solid var(--border);
  min-height: 38px;
  line-height: 1.4;
}
.pf-image-caption:empty::before { content: 'Add a caption…'; color: var(--text3); }
.pf-image-actions { display: flex; gap: 4px; padding: 6px 8px; border-top: 1px solid var(--border); background: var(--card2); }
.pf-image-actions .icon-btn { width: 28px; height: 28px; font-size: 14px; color: var(--text2); }
.pf-image-actions .icon-btn:hover { color: var(--primary); }
.pf-image-actions .icon-btn.is-danger:hover { color: var(--danger); }

.pf-upload-card {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  color: var(--text2);
  transition: border-color 0.15s, color 0.15s;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 178px;
  background: var(--card);
}
.pf-upload-card:hover { border-color: var(--primary); color: var(--primary); }
.pf-upload-card i { font-size: 42px; }
.pf-upload-card span { font-size: 14px; margin-top: 6px; }

/* Image lightbox */
.pf-lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 200; display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.pf-lightbox img { max-width: 90vw; max-height: 90vh; }

/* ────── Settings modal ────── */
.pf-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.pf-modal-card { background: var(--card); border-radius: var(--radius); width: 100%; max-width: 540px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 24px 64px rgba(0,0,0,0.35); }
.pf-modal-card header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.pf-modal-card header h2 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 8px; }
.pf-modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.pf-modal-card footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: 8px; }

.pf-row { margin-bottom: 18px; }
.pf-row label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.pf-row .pf-meta { display: block; color: var(--text3); font-size: 12px; font-weight: 400; margin-top: 4px; }
.pf-row input[type="text"] {
  width: 100%; box-sizing: border-box;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font: inherit;
  color: var(--text);
}
.pf-row input[type="text"]:focus { border-color: var(--primary); outline: none; }
.pf-row code { background: var(--bg3); padding: 1px 6px; border-radius: 4px; font-family: ui-monospace, monospace; font-size: 11px; }

.pf-toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.pf-toggle input { display: none; }
.pf-toggle-slider { width: 42px; height: 24px; background: var(--bg3); border-radius: 999px; position: relative; transition: background 0.15s; flex-shrink: 0; }
.pf-toggle-slider::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: white; border-radius: 50%; transition: transform 0.15s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.pf-toggle input:checked + .pf-toggle-slider { background: var(--primary); }
.pf-toggle input:checked + .pf-toggle-slider::after { transform: translateX(18px); }
.pf-toggle-label { font-size: 14px; font-weight: 600; }
.pf-row-toggle .pf-meta { margin-top: 8px; }

.theme-seg { display: inline-flex; background: var(--card2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.theme-seg button { background: transparent; border: none; padding: 6px 12px; border-radius: 5px; font: inherit; font-size: 13px; color: var(--text2); cursor: pointer; display: flex; align-items: center; gap: 5px; }
.theme-seg button.is-active { background: var(--primary); color: white; }

.pf-storage-bar { width: 100%; height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.pf-storage-bar > div { height: 100%; background: var(--primary); transition: width 0.3s; }

.pf-row-danger { padding: 14px; background: rgba(239,68,68,0.06); border: 1px solid rgba(239,68,68,0.2); border-radius: var(--radius-sm); }

/* ────── Buttons ────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--card); color: var(--text); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s; text-decoration: none; }
.btn:hover { background: var(--card2); border-color: var(--primary); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: white; }
.btn-ghost { background: transparent; border: none; color: var(--text2); }
.btn-ghost:hover { background: var(--card2); color: var(--primary); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #DC2626; border-color: #DC2626; }
.icon-btn { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: var(--radius-sm); background: transparent; color: var(--text); cursor: pointer; font-size: 18px; }
.icon-btn:hover { background: var(--card2); }

/* ────── Toast ────── */
.pf-toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--card); padding: 10px 16px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; z-index: 300; box-shadow: 0 4px 16px rgba(0,0,0,0.25); }

/* ────── Public view tweaks ────── */
.pf-view-banner {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 36px 36px 28px;
}
.pf-view-banner h1 { font-size: 32px; font-weight: 800; margin: 0; }
.pf-view-banner p { color: var(--text2); margin: 8px 0 0; font-size: 16px; }
.pf-view-private {
  max-width: 480px; margin: 80px auto; text-align: center; padding: 32px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.pf-view-private i { font-size: 56px; color: var(--text3); }
.pf-view-private h1 { font-size: 22px; margin: 16px 0 8px; }
.pf-view-private p { color: var(--text2); }

/* ────── Responsive — only the public view shrinks gracefully; the editor is
   blocked below 900px by JS, so we don't need a small-screen layout for it. */
@media (max-width: 700px) {
  .pf-main { grid-template-columns: 1fr; }
  .pf-sidebar { display: none; }
  .pf-workspace { padding: 20px 16px 40px; }
  .pf-view-banner { padding: 24px 16px 18px; }
  .pf-view-banner h1 { font-size: 24px; }
  .pf-images { grid-template-columns: 1fr; }
}
