/* PenPad — shared styles for auth pages, dashboard and the editor shell. */

[x-cloak] { display: none !important; }

:root {
  --pen-accent: #6366f1;
  --pen-bg: #0f1117;
  --pen-panel: #171923;
  --pen-panel-2: #1e212d;
  --pen-border: #2a2e3a;
  --pen-text-dim: #9aa1b1;
}

body {
  background-color: #0b0d12;
  min-height: 100vh;
}

.boot-loader {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-screen {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--pen-accent), #8b5cf6);
  color: #fff;
  font-size: 1.4rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  border-radius: 16px;
  border: 1px solid var(--pen-border);
}

.pen-card {
  border-radius: 12px;
  border: 1px solid var(--pen-border);
  transition: transform .12s ease, box-shadow .12s ease;
}
.pen-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .35) !important;
}

.app-navbar {
  background-color: var(--pen-panel);
  border-color: var(--pen-border) !important;
}

.navbar-avatar-link { line-height: 0; }
.navbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--pen-border);
}

.discover-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
}

.discover-desc {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tag-chip { font-weight: 400; }

.profile-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--pen-border);
}

.stat-card { border: 1px solid var(--pen-border); border-radius: 12px; text-align: center; }
.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--pen-text-dim); font-size: .8rem; }

.activity-list .list-group-item { border-color: var(--pen-border); }

/* ---------------------------------------------------------------- */
/* Custom modal system (replaces window.confirm/prompt)               */
/* ---------------------------------------------------------------- */

.app-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 1050;
}
.app-modal {
  position: fixed;
  inset: 0;
  z-index: 1055;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.app-modal-dialog {
  width: 100%;
  max-width: 440px;
  background: var(--pen-panel);
  border: 1px solid var(--pen-border);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
  color: #e2e8f0;
}
.app-modal-wide { max-width: 720px; }
.app-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--pen-border);
}
.app-modal-body { padding: 1.25rem; }
.app-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--pen-border);
}

.history-body { display: flex; gap: 1rem; min-height: 320px; max-height: 60vh; }
.history-list { width: 45%; overflow-y: auto; border-right: 1px solid var(--pen-border); padding-right: .75rem; }
.history-item {
  padding: .5rem .6rem;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: .25rem;
}
.history-item:hover { background: var(--pen-panel-2); }
.history-item.active { background: rgba(99, 102, 241, .25); }
.history-preview { flex: 1; overflow: auto; }
.history-code {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: .8rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

@media (max-width: 767.98px) {
  .history-body { flex-direction: column; max-height: 70vh; }
  .history-list { width: 100%; border-right: 0; border-bottom: 1px solid var(--pen-border); max-height: 35%; padding-right: 0; }
}

/* ---------------------------------------------------------------- */
/* Toasts                                                             */
/* ---------------------------------------------------------------- */

.toast-stack {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 1080;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-width: min(90vw, 360px);
}
.app-toast {
  padding: .65rem 1rem;
  border-radius: 8px;
  color: #fff;
  font-size: .85rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .35);
}
.app-toast-danger { background: #dc2626; }
.app-toast-success { background: #16a34a; }

/* ---------------------------------------------------------------- */
/* Editor shell                                                       */
/* ---------------------------------------------------------------- */

html, body { height: 100%; }

.editor-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--pen-bg);
  color: #d7dae0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .6rem;
  background: var(--pen-panel);
  border-bottom: 1px solid var(--pen-border);
  flex-wrap: wrap;
}

.editor-toolbar .pen-title-input {
  background: transparent;
  border: 1px solid transparent;
  color: #fff;
  font-size: .95rem;
  padding: .25rem .5rem;
  border-radius: 6px;
  max-width: 220px;
}
.editor-toolbar .pen-title-input:hover,
.editor-toolbar .pen-title-input:focus {
  border-color: var(--pen-border);
  outline: none;
  background: var(--pen-panel-2);
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: #c7cbd4;
  font-size: 1rem;
  transition: background .12s ease, color .12s ease;
}
.tool-btn:hover { background: var(--pen-panel-2); color: #fff; }
.tool-btn:disabled { opacity: .4; }
.tool-btn.active { background: var(--pen-accent); color: #fff; }

.toolbar-sep {
  width: 1px;
  align-self: stretch;
  background: var(--pen-border);
  margin: 0 .25rem;
}

.editor-status {
  margin-left: auto;
  font-size: .78rem;
  color: var(--pen-text-dim);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.editor-status .saved-flash { color: #4ade80; }

.editor-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--pen-panel);
  border-right: 1px solid var(--pen-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: .5rem .75rem;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--pen-text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.file-tree {
  flex: 1;
  overflow: auto;
  padding: .25rem 0;
  font-size: .85rem;
}

.file-node { user-select: none; }

.file-row {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .28rem .5rem;
  border-radius: 6px;
  margin: 0 .35rem;
  cursor: pointer;
  white-space: nowrap;
}
.file-row:hover { background: var(--pen-panel-2); }
.file-row.active { background: rgba(99, 102, 241, .25); color: #fff; }
.file-row.selected { outline: 1px solid var(--pen-accent); outline-offset: -1px; }
.file-row:focus { outline: 1px solid var(--pen-accent); outline-offset: -1px; }
.file-row .bi { flex-shrink: 0; }
.file-row .name { overflow: hidden; text-overflow: ellipsis; }
.file-row .row-actions { margin-left: auto; display: none; gap: .15rem; }
.file-row:hover .row-actions, .file-row:focus .row-actions { display: flex; }
.file-row .row-actions .bi { font-size: .8rem; opacity: .75; }
.file-row .row-actions .bi:hover { opacity: 1; }

.file-children { margin-left: 1rem; border-left: 1px dashed var(--pen-border); }

.editor-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tab-bar {
  display: flex;
  overflow-x: auto;
  background: var(--pen-panel);
  border-bottom: 1px solid var(--pen-border);
}

.tab {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .6rem;
  border-right: 1px solid var(--pen-border);
  font-size: .82rem;
  color: var(--pen-text-dim);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab.active { background: var(--pen-bg); color: #fff; }
.tab .close-tab { border-radius: 4px; padding: 0 .15rem; }
.tab .close-tab:hover { background: var(--pen-border); }
.tab .dirty-dot { width: 7px; height: 7px; border-radius: 50%; background: #f59e0b; }

.panes {
  flex: 1;
  display: flex;
  min-height: 0;
}

.cm-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  position: relative;
}
.cm-pane .CodeMirror {
  flex: 1;
  height: 100%;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: .88rem;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pen-text-dim);
  flex-direction: column;
  gap: .5rem;
}

.resizer {
  width: 5px;
  cursor: col-resize;
  background: var(--pen-border);
  flex-shrink: 0;
}
.resizer:hover { background: var(--pen-accent); }

.preview-pane {
  width: 45%;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--pen-border);
  background: #fff;
}
.preview-hidden .preview-pane,
.preview-hidden .resizer {
  display: none;
}
.preview-pane .preview-bar {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .25rem .5rem;
  background: var(--pen-panel);
  border-bottom: 1px solid var(--pen-border);
  color: var(--pen-text-dim);
  font-size: .75rem;
}
.preview-pane iframe {
  flex: 1;
  border: 0;
  width: 100%;
  background: #fff;
}

/* Mobile: stack, sidebar becomes offcanvas, preview becomes a switchable view */
@media (max-width: 767.98px) {
  .resizer { display: none; }
  .preview-pane { display: none; position: absolute; inset: 0; z-index: 5; width: 100%; }
  .mobile-preview-active .preview-pane { display: flex; }
  .mobile-preview-active .tab-bar,
  .mobile-preview-active .cm-pane { display: none; }
  .panes { position: relative; }
}

.offcanvas-tree { background: var(--pen-panel); color: #d7dae0; width: 260px; }
.offcanvas-tree .file-tree { height: calc(100% - 3rem); }
