/* Cerulean Office — dark-first UI. One accent (cerulean), near-black surfaces,
   subtle borders, system font stack. Perceived speed matters: transitions are
   short, skeletons show immediately. */

:root {
  --bg: #0c0f13;
  --bg-1: #12161c;
  --bg-2: #171c24;
  --bg-3: #1e242e;
  --border: #262d38;
  --border-strong: #333c49;
  --text: #e6ebf2;
  --text-dim: #9aa6b6;
  --text-faint: #6b7684;
  --accent: #2b9fd8;
  --accent-hi: #4bb6e8;
  --accent-dim: rgba(43, 159, 216, 0.14);
  --danger: #e5533c;
  --danger-dim: rgba(229, 83, 60, 0.14);
  --ok: #3fb860;
  --warn: #e0a83a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: var(--accent-hi); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- App shell ---------- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: 0.2px;
  cursor: pointer;
  user-select: none;
}
.brand .logo {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #1c6ea0);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
}
.brand .name { color: var(--text); }
.brand .name b { color: var(--accent-hi); }

.search {
  flex: 1;
  max-width: 460px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
}
.search .ico { color: var(--text-faint); }

.topbar-spacer { flex: 1; }

.me {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
}
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent-hi);
  display: grid;
  place-items: center;
  font-weight: 650;
  font-size: 12px;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 57px;
  z-index: 20;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 200px;
  flex-wrap: wrap;
  font-size: 14px;
}
.crumbs .crumb {
  color: var(--text-dim);
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 6px;
}
.crumbs .crumb:hover { background: var(--bg-2); color: var(--text); }
.crumbs .crumb.current { color: var(--text); font-weight: 600; cursor: default; }
.crumbs .crumb.current:hover { background: none; }
.crumbs .sep { color: var(--text-faint); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #05222f;
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn.danger:hover { background: var(--danger-dim); }
.btn.sm { padding: 5px 9px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .ico { font-size: 15px; line-height: 1; }

/* ---------- Main / listing ---------- */
.main { flex: 1; padding: 18px 20px 60px; }

.listing {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-1);
}

.row {
  display: grid;
  grid-template-columns: 1fr 150px 110px 40px;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.row:last-child { border-bottom: none; }
.row:hover { background: var(--bg-2); }
.row.head {
  cursor: default;
  color: var(--text-faint);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-1);
}
.row.head:hover { background: var(--bg-1); }

.cell-name {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}
.cell-name .fname {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-dim { color: var(--text-dim); font-size: 13px; }
.cell-right { text-align: right; }

.ficon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 16px;
  flex: none;
  background: var(--bg-3);
}
.ficon.folder { background: rgba(43, 159, 216, 0.16); }
.ficon.document { background: rgba(63, 132, 232, 0.16); }
.ficon.spreadsheet { background: rgba(63, 184, 96, 0.16); }
.ficon.file { background: var(--bg-3); }

/* Thumbnail: same footprint as an icon; the type icon shows until (and unless)
   the image loads, then the image covers it. */
.fthumb {
  position: relative;
  width: 30px;
  height: 30px;
  flex: none;
}
.fthumb .thumb-img {
  position: absolute;
  inset: 0;
  width: 30px;
  height: 30px;
  object-fit: cover;
  border-radius: 7px;
  opacity: 0;
  transition: opacity 0.15s ease;
  background: var(--bg-3);
}
.fthumb.has-img .thumb-img { opacity: 1; }
.fthumb.has-img .ficon { visibility: hidden; }

.kebab {
  border: none;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  font-size: 18px;
  line-height: 1;
}
.kebab:hover { background: var(--bg-3); color: var(--text); }

/* ---------- States ---------- */
.state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-dim);
}
.state .big { font-size: 40px; margin-bottom: 10px; opacity: 0.7; }
.state h3 { margin: 0 0 6px; color: var(--text); font-weight: 600; }

.skeleton-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.skeleton {
  background: linear-gradient(90deg, var(--bg-2), var(--bg-3), var(--bg-2));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 14px;
  font-size: 15px;
  font-weight: 600;
}
.section-title .muted { color: var(--text-dim); font-weight: 400; font-size: 13px; }

/* ---------- Context menu ---------- */
.menu {
  position: fixed;
  z-index: 100;
  min-width: 190px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 6px;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.menu-item:hover { background: var(--bg-3); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-dim); }
.menu-item .ico { width: 18px; text-align: center; }
.menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }

/* ---------- Modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow: auto;
  background: var(--bg-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.close-x {
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.close-x:hover { color: var(--text); }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 13px;
}
.field input[type="text"],
.field input[type="password"],
.field input[type="number"],
.field input[type="email"],
.field select {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.row-2 { display: flex; gap: 12px; }
.row-2 > * { flex: 1; }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.toggle input { display: none; }
.toggle .track {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  position: relative;
  transition: background 0.15s;
  flex: none;
}
.toggle .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform 0.15s, background 0.15s;
}
.toggle input:checked + .track { background: var(--accent-dim); border-color: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(18px); background: var(--accent-hi); }
.toggle .lbl small { display: block; color: var(--text-faint); font-size: 12px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: -18px -20px 18px;
  padding: 0 12px;
}
.tab {
  padding: 12px 14px;
  cursor: pointer;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Lists inside modals ---------- */
.mini-list { display: flex; flex-direction: column; gap: 8px; }
.mini-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
}
.mini-item .grow { flex: 1; min-width: 0; }
.mini-item .grow .t { font-weight: 500; }
.mini-item .grow .s { color: var(--text-faint); font-size: 12px; }
.mini-item.revoked { opacity: 0.55; }

.pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--text-dim);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: rgba(63, 184, 96, 0.4); }
.pill.warn { color: var(--warn); border-color: rgba(224, 168, 58, 0.4); }
.pill.accent { color: var(--accent-hi); border-color: rgba(43, 159, 216, 0.4); }

.callout {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-2);
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-dim);
}
.callout.accent { border-color: var(--accent); background: var(--accent-dim); color: var(--text); }
.callout.danger { border-color: var(--danger); background: var(--danger-dim); color: var(--text); }

.copybox {
  display: flex;
  gap: 8px;
  align-items: center;
}
.copybox input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 380px;
}
.toast {
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow);
  animation: slidein 0.18s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
.toast .t { font-weight: 600; margin-bottom: 2px; }
.toast .m { color: var(--text-dim); font-size: 13px; word-break: break-word; }
@keyframes slidein {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---------- Editor / preview fullscreen ---------- */
.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.fs-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.fs-bar .title {
  flex: 1;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fs-body { flex: 1; position: relative; overflow: auto; background: #1a1a1a; }
#editor-container, .editor-host { position: absolute; inset: 0; }
.preview-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
}
.preview-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.preview-wrap iframe { width: 100%; height: 100%; border: none; background: #fff; }

.banner {
  padding: 14px 18px;
  margin: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--danger);
  background: var(--danger-dim);
}
.banner h3 { margin: 0 0 4px; }
.banner p { margin: 0; color: var(--text-dim); }

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-fill {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 12px;
}

.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--text-dim); }
.nowrap { white-space: nowrap; }

@media (max-width: 640px) {
  .row { grid-template-columns: 1fr 40px; }
  .row .cell-updated, .row .cell-size, .row.head .cell-updated, .row.head .cell-size { display: none; }
  .search { max-width: none; }
  .me .me-name { display: none; }
}

/* ============================ markdown editor + rendering ============================ */
.md-body { background: var(--bg); }
.md-split { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; }
.md-pane { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--border); }
.md-pane:last-child { border-right: none; }
.md-pane-h {
  flex: none; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-faint); padding: 8px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}
.md-source {
  flex: 1; min-height: 0; width: 100%; resize: none; border: none; outline: none;
  background: var(--bg); color: var(--text); padding: 18px 20px;
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: 13.5px; line-height: 1.7; tab-size: 2;
}
.md-preview { flex: 1; min-height: 0; overflow: auto; padding: 20px 26px; }
.md-status { font-size: 12px; margin-left: 4px; }

/* Rendered markdown typography — shared by member preview + guest view. */
.markdown-body { color: var(--text); line-height: 1.65; font-size: 15px; word-wrap: break-word; }
.markdown-body > *:first-child { margin-top: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 { margin: 1.4em 0 0.5em; line-height: 1.25; font-weight: 650; }
.markdown-body h1 { font-size: 1.8em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.45em; border-bottom: 1px solid var(--border); padding-bottom: 0.25em; }
.markdown-body h3 { font-size: 1.2em; }
.markdown-body p { margin: 0.75em 0; }
.markdown-body a { color: var(--accent-hi); text-decoration: underline; text-underline-offset: 2px; }
.markdown-body code {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 5px;
  padding: 0.12em 0.4em; font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.markdown-body pre {
  background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px; overflow: auto; margin: 0.9em 0;
}
.markdown-body pre code { background: none; border: none; padding: 0; font-size: 0.86em; line-height: 1.55; }
.markdown-body blockquote {
  margin: 0.9em 0; padding: 0.2em 1em; color: var(--text-dim);
  border-left: 3px solid var(--accent); background: var(--accent-dim); border-radius: 0 6px 6px 0;
}
.markdown-body ul, .markdown-body ol { margin: 0.7em 0; padding-left: 1.6em; }
.markdown-body li { margin: 0.25em 0; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
.markdown-body img { max-width: 100%; border-radius: 6px; }
.markdown-body table { border-collapse: collapse; margin: 1em 0; width: auto; display: block; overflow-x: auto; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.markdown-body th { background: var(--bg-2); font-weight: 600; }
.markdown-body del { color: var(--text-faint); }

@media (max-width: 720px) {
  .md-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .md-pane { border-right: none; border-bottom: 1px solid var(--border); }
}
