:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --text: #1f2328;
  --text-muted: #6b7280;
  --border: #e3e6ea;
  --accent: #1a73e8;
  --accent-soft: #e8f0fe;
  --accent-text: #ffffff;
  --danger: #c5221f;
  --danger-soft: #fce8e6;
  --error-bg: #fde8e8;
  --error-text: #9b1c1c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --surface: #1d2027;
    --surface-2: #23272f;
    --text: #e5e7eb;
    --text-muted: #9aa2af;
    --border: #2e323b;
    --accent: #8ab4f8;
    --accent-soft: #1f2a3d;
    --accent-text: #15171c;
    --danger: #f28b82;
    --danger-soft: #3b1d1d;
    --error-bg: #3b1d1d;
    --error-text: #f8b4b4;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.mono, code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

button { font: inherit; cursor: pointer; }

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 0.375rem;
  padding: 0.5rem 1rem;
  font-weight: 500;
}

button.subtle {
  background: none;
  border: none;
  color: var(--text-muted);
  border-radius: 0.375rem;
  padding: 0.25rem 0.5rem;
}
button.subtle:hover { background: var(--surface-2); color: var(--text); }

button.link {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
}
button.link:hover { background: var(--surface-2); color: var(--text); }

button.danger { color: var(--danger); }

/* --- login ------------------------------------------------------------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 2rem;
  max-width: 27rem;
  width: 100%;
}

.login-box h1 { margin: 0 0 0.5rem; font-size: 1.5rem; }
.tagline { color: var(--text-muted); margin-top: 0; }

.login-box label {
  display: block;
  font-weight: 500;
  margin: 1.5rem 0 0.375rem;
}

.login-box input {
  width: 100%;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.provider-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin: 0.75rem 0 1.25rem;
}

.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  color: var(--text-muted);
}
.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.login-box button.primary { width: 100%; }

/* --- shell ------------------------------------------------------------- */

.centered { min-height: 100vh; display: grid; place-items: center; }
.hint { color: var(--text-muted); padding: 1rem; }

.shell { min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.625rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { font-weight: 600; white-space: nowrap; }

.crumbs {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
}
.crumb .sep { color: var(--text-muted); margin: 0 0.125rem; }
.crumb .current { font-weight: 500; padding: 0.125rem 0.25rem; }

.session { display: flex; align-items: center; gap: 0.5rem; }
.webid { color: var(--text-muted); text-decoration: none; font-size: 0.85rem; }
.webid:hover { text-decoration: underline; }

.error {
  background: var(--error-bg);
  color: var(--error-text);
  padding: 0.5rem 1rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.body { flex: 1; display: flex; min-height: 0; }

/* --- listing ----------------------------------------------------------- */

.listing { flex: 1; min-width: 0; overflow: auto; }

table.files { width: 100%; border-collapse: collapse; }

table.files th {
  text-align: left;
  font-weight: 500;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
}

.row td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row:hover td { background: var(--surface); }
.row.selected td { background: var(--accent-soft); }

.cell-icon { width: 2rem; }
.cell-name { max-width: 22rem; }
.cell-name .slash { color: var(--text-muted); }
.cell-type, .cell-size, .cell-date { color: var(--text-muted); font-size: 0.85rem; }
.cell-size { text-align: right; width: 6rem; }
.cell-date { width: 12rem; }

.path-hint {
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0.75rem;
  word-break: break-all;
}

/* --- viewer ------------------------------------------------------------ */

.viewer {
  width: min(60%, 52rem);
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border);
}
.viewer-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }

.panes { flex: 1; display: flex; min-height: 0; }

.content { flex: 1; overflow: auto; padding: 1rem; min-width: 0; }

pre.code {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.8rem;
  line-height: 1.6;
}

img.preview { max-width: 100%; border-radius: 0.5rem; }

.no-preview { color: var(--text-muted); }
.no-preview a.primary { display: inline-block; text-decoration: none; margin-top: 0.5rem; }

.meta {
  width: 17rem;
  flex: none;
  border-left: 1px solid var(--border);
  padding: 1rem;
  overflow: auto;
  background: var(--surface-2);
}

.meta h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em;
           color: var(--text-muted); margin: 0 0 0.75rem; }

.meta dl { margin: 0; }
.meta dt { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em;
           color: var(--text-muted); margin-top: 0.75rem; }
.meta dd { margin: 0.125rem 0 0; word-break: break-all; font-size: 0.85rem; }
.meta dd.bad { color: var(--danger); }
.meta dd.mono { font-size: 0.75rem; }
.meta a { color: var(--accent); }

.raw-headers { margin-top: 1.25rem; }
.raw-headers summary { cursor: pointer; color: var(--text-muted); font-size: 0.8rem; }

@media (max-width: 60rem) {
  .body { flex-direction: column; }
  .viewer { width: auto; border-left: none; border-top: 1px solid var(--border); }
  .panes { flex-direction: column; }
  .meta { width: auto; border-left: none; border-top: 1px solid var(--border); }
}

/* --- context menu ------------------------------------------------------ */

.menu-backdrop { position: fixed; inset: 0; z-index: 10; }

.menu {
  position: fixed;
  z-index: 11;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  min-width: 12rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}

.menu li.sep { height: 1px; background: var(--border); margin: 0.25rem 0; }

.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: inherit;
  padding: 0.4rem 0.625rem;
  border-radius: 0.375rem;
}
.menu button:hover { background: var(--surface-2); }
.menu button.danger:hover { background: var(--danger-soft); }

/* --- modal ------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgb(0 0 0 / 0.4);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border-radius: 0.75rem;
  padding: 1.5rem;
  max-width: 28rem;
  width: 100%;
}

.modal h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.modal .url { color: var(--text-muted); font-size: 0.75rem; word-break: break-all; }
.modal .warning { color: var(--danger); }

.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }
.modal-actions button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  border-radius: 0.375rem;
  padding: 0.4rem 0.875rem;
}
.modal-actions button.danger { border-color: var(--danger); color: var(--danger); }

/* --- sharing ----------------------------------------------------------- */

.sharing { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.sharing h2 {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); margin: 0 0 0.5rem;
}
.sharing .hint { padding: 0; font-size: 0.8rem; }
.sharing dt.agent { text-transform: none; letter-spacing: 0; font-size: 0.75rem; }

.modes { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.mode {
  font-size: 0.7rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
}
.mode.none { background: none; color: var(--text-muted); }
.unreported { color: var(--text-muted); font-size: 0.8rem; font-style: italic; }

/* --- address bar ------------------------------------------------------- */

.address { display: flex; gap: 0.25rem; align-items: center; flex: 1 1 18rem; min-width: 10rem; }
.address input {
  flex: 1; min-width: 0;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}
.app-header .crumbs { flex: 1 1 12rem; }

@media (max-width: 55rem) {
  .app-header { flex-wrap: wrap; }
  .address { order: 3; flex-basis: 100%; }
}

/* --- sharing controls -------------------------------------------------- */

.public-toggle { display: flex; gap: 0.4rem; align-items: center;
                 margin: 0.5rem 0 0.75rem; font-size: 0.8rem; }
.grant { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.4rem; }
.grant input[type="url"] {
  width: 100%; padding: 0.3rem 0.5rem; font: inherit; font-size: 0.8rem;
  border: 1px solid var(--border); border-radius: 0.375rem;
  background: var(--bg); color: var(--text);
}
.grant-modes { display: flex; gap: 0.6rem; flex-wrap: wrap; font-size: 0.75rem; }
.grant-modes label { display: flex; gap: 0.2rem; align-items: center; }
.grant button.primary { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.grant-contents {
  display: flex; align-items: center; gap: 0.3rem;
  font-size: 0.75rem; color: var(--text-muted);
}
button.revoke { font-size: 0.7rem; margin-left: 0.4rem; }
.sharing .warn {
  font-size: 0.8rem; color: var(--danger);
  background: var(--danger-soft); padding: 0.5rem; border-radius: 0.375rem;
}

/* what a container grants its contents — a separate set of rules from
   the container's own, so kept visibly separate rather than merged in */
.member-access {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.sharing h3.scope {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 0.4rem;
}

.member-access h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0.75rem 0 0.4rem;
}
.member-access h3:first-child { margin-top: 0; }

.inherited-from { margin-bottom: 0.5rem; }
.inherited-from .from {
  font-size: 0.8rem;
  font-weight: 500;
  margin: 0 0 0.15rem;
  word-break: break-all;
}
.inherited-from dl { margin: 0 0 0 0.75rem; }

/* --- editing ----------------------------------------------------------- */

.content-actions { display: flex; justify-content: flex-end; margin-bottom: 0.5rem; }

.editor { display: flex; flex-direction: column; height: 100%; gap: 0.5rem; }

.editor-text {
  flex: 1;
  min-height: 18rem;
  width: 100%;
  resize: vertical;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  tab-size: 2;
}
.editor-text:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.editor-actions { display: flex; align-items: center; gap: 0.5rem; }
.editor-actions .hint { flex: 1; padding: 0; font-size: 0.75rem; }
.editor-actions button.primary { padding: 0.35rem 0.9rem; font-size: 0.85rem; }

/* --- attached (auxiliary) resources ------------------------------------ */

.listing-tools {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
.reveal { display: flex; align-items: center; gap: 0.35rem; cursor: pointer; }
.listing-tools .hint { padding: 0; font-size: 0.75rem; }

.attached-row td { color: var(--text-muted); font-size: 0.8rem; }
.attached-row .cell-icon { text-align: right; padding-right: 0.5rem; }
.attached-row .rel { font-style: italic; }

.attached { margin-top: 1.25rem; }
.attached h2 {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); margin: 0 0 0.35rem;
}
.attached .hint { padding: 0; font-size: 0.72rem; margin-bottom: 0.4rem; }
button.link-row {
  display: block; width: 100%; text-align: left;
  background: none; border: 1px solid var(--border); border-radius: 0.375rem;
  color: inherit; padding: 0.3rem 0.5rem; margin-bottom: 0.25rem;
  font-size: 0.8rem;
}
button.link-row:hover { background: var(--surface); }

/* --- move / rename ----------------------------------------------------- */

.modal label { display: block; font-weight: 500; margin: 0.75rem 0 0.25rem; font-size: 0.85rem; }
.modal input[type="url"] {
  width: 100%; padding: 0.4rem 0.5rem; font: inherit; font-size: 0.85rem;
  border: 1px solid var(--border); border-radius: 0.375rem;
  background: var(--bg); color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.modal .hint { padding: 0; font-size: 0.78rem; }
ul.caveats { margin: 0.75rem 0 0; padding-left: 1.1rem; font-size: 0.78rem;
             color: var(--text-muted); }
ul.caveats li { margin-bottom: 0.3rem; }

.listing-tools button.subtle { font-size: 0.78rem; }
.tool-sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 0.25rem; }
.modal input[type="text"] {
  width: 100%; padding: 0.4rem 0.5rem; font: inherit; font-size: 0.9rem;
  border: 1px solid var(--border); border-radius: 0.375rem;
  background: var(--bg); color: var(--text);
}

label.upload {
  display: inline-block; cursor: pointer; font-size: 0.78rem;
  color: var(--text-muted); padding: 0.25rem 0.5rem; border-radius: 0.375rem;
}
label.upload:hover { background: var(--surface-2); color: var(--text); }
label.upload input[type="file"] { display: none; }

/* the mode chips are a readout, not controls */
.mode { cursor: help; user-select: none; }
.modal label.recursive {
  display: flex; align-items: center; gap: 0.4rem;
  margin-top: 0.75rem; font-weight: 500; color: var(--danger);
}
