:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-raised: var(--bg);
  --text: #1a1d21;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #0d9488;
  --accent-soft: #ccfbf1;
  --accent-hover: #0f766e;
  --on-accent: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.08), 0 1px 2px rgb(0 0 0 / 0.06);
  --font:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono:
    ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono",
    monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #0e0f12;
    --surface-raised: #16171c;
    --text: #e6e8eb;
    --muted: #9ca3af;
    --border: #24262c;
    --accent: #00f5c8;
    --accent-soft: #052b23;
    --accent-hover: #57ffe4;
    --on-accent: #04211b;
    --danger: #f87171;
    --danger-soft: #2a1114;
    --success: #4ade80;
    --success-soft: #143021;
    --shadow: 0 8px 30px rgb(0 0 0 / 0.6);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

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

a:hover {
  text-decoration: underline;
}

h1 {
  margin: 0;
}

[class^="iconoir-"],
[class*=" iconoir-"] {
  font-size: 1.25em;
  vertical-align: -0.12em;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1.25rem;
  margin-bottom: 1.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 650;
  font-size: 1.05rem;
  color: var(--accent);
}

.brand:hover {
  text-decoration: none;
  color: var(--accent);
}

/* Nav rail: on wide screens it is fixed to the viewport's left edge and does
   not participate in layout, so the content column stays a plain centered
   .container. Below 1400px it becomes a slide-in drawer instead (see the
   media query at the bottom of this file). */
#sidebar {
  padding: 0.5rem;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.side-nav a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
}

.side-nav a:hover {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
}

.nav-backdrop {
  display: none;
}

/* Mobile-only logout inside the drawer; desktop keeps the topbar one */
.side-logout {
  display: none;
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.flex-wrap {
  flex-wrap: wrap;
}

.flex-1 {
  flex: 1 1 0%;
}

.flex-none {
  flex: none;
}

.min-w-0 {
  min-width: 0;
}

.gap-1 {
  gap: 0.25rem;
}

.gap-2 {
  gap: 0.5rem;
}

.gap-3 {
  gap: 0.75rem;
}

.gap-4 {
  gap: 1rem;
}

.mb-4 {
  margin-bottom: 1rem;
}

.text-sm {
  font-size: 0.875rem;
}

.text-xl {
  font-size: 1.35rem;
}

.font-medium {
  font-weight: 500;
}

.font-semibold {
  font-weight: 650;
}

.muted {
  color: var(--muted);
}

.w-full {
  width: 100%;
}

.nowrap {
  white-space: nowrap;
}

.truncate {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-right {
  text-align: right;
}

.overflow-hidden {
  overflow: hidden;
}

.hidden {
  display: none;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: var(--accent-hover);
  color: var(--on-accent);
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-card {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-card:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  filter: brightness(1.1);
}

.btn-sm {
  padding: 0.4rem 0.65rem;
  font-size: 0.85rem;
}

.dropdown {
  position: relative;
}

.dropdown > summary {
  list-style: none;
  cursor: pointer;
}

.dropdown > summary::-webkit-details-marker {
  display: none;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 11rem;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 30;
}

.dropdown[open] > .dropdown-menu {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  white-space: nowrap;
}

.dropdown-item:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Buttons rendered as dropdown items (favorites row-menu toggle): reset the
   native button look so they match the <a> entries above. */
button.dropdown-item {
  width: 100%;
  background: none;
  border: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

/* Row action menus (kebab in table rows) open flush with the button edge */
.row-menu {
  display: inline-block;
  vertical-align: middle;
}

.input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

label {
  display: block;
}

.alert {
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.9rem;
}

.alert-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.alert-warning {
  background: var(--surface-raised);
  color: var(--muted);
}

.alert-success {
  background: var(--success-soft);
  color: var(--success);
}

.text-view {
  margin: 0;
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  min-width: 0;
  color: var(--text);
}

.edit-form {
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.edit-name {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  margin-bottom: 0.9rem;
}

.file-input {
  padding: 0.45rem 0.8rem;
}

.text-edit {
  display: block;
  width: 100%;
  min-height: 60vh;
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  white-space: pre-wrap;
}

.text-edit:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.edit-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
}

.markdown-body {
  padding: 1rem;
  font-size: 0.925rem;
  line-height: 1.6;
  color: var(--text);
  overflow-wrap: anywhere;
  min-width: 0;
  max-width: 100%;
}

.markdown-body h1,
.markdown-body h2 {
  margin: 1.25rem 0 0.5rem;
  line-height: 1.3;
}

.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 1rem 0 0.4rem;
  line-height: 1.3;
}

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body p:first-child {
  margin-top: 0;
}

.markdown-body p {
  margin: 0.6rem 0;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.6rem 0;
  padding-left: 1.4rem;
}

.markdown-body li {
  margin: 0.25rem 0;
}

/* Task lists (`- [ ] todo`): checkbox sits in the bullet gutter, wrapped
   text keeps a hanging indent. Checkboxes are disabled (display only). */
.markdown-body ul.contains-task-list {
  list-style: none;
}

.markdown-body .task-list-item-checkbox {
  margin: 0 0.4em 0.1em -1.3rem;
  vertical-align: middle;
  accent-color: var(--accent);
}

.markdown-body a {
  color: var(--accent);
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface-raised);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.35em;
}

.markdown-body pre {
  margin: 0.75rem 0;
  padding: 0.85rem 1rem;
  background: var(--surface-raised);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.markdown-body pre code {
  font-size: 0.85rem;
  background: none;
  border: none;
  padding: 0;
}

.markdown-body blockquote {
  margin: 0.75rem 0;
  padding: 0.25rem 1rem;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.markdown-body blockquote p {
  margin: 0.4rem 0;
}

.markdown-body table {
  margin: 0.75rem 0;
  border-collapse: collapse;
  max-width: 100%;
  display: block;
  overflow-x: auto;
}

.markdown-body th,
.markdown-body td {
  padding: 0.35rem 0.7rem;
  text-align: left;
}

.markdown-body th {
  background: var(--surface-raised);
}

.markdown-body img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

.markdown-body hr {
  margin: 1.25rem 0;
  border: none;
  border-top: 1px solid var(--border);
}

.login-card {
  max-width: 350px;
  margin: 14vh auto 0;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.file-table {
  border-collapse: collapse;
  table-layout: fixed;
  width: 100%;
}

.file-table th {
  text-align: left;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
}

.file-table th a {
  color: var(--muted);
}

.file-table th a:hover {
  color: var(--accent);
  text-decoration: none;
}

.file-table td {
  padding: 0.85rem 1rem;
}

/* Fixed-width columns; the name column absorbs the remainder so the
   .truncate span can ellipsize long names/paths instead of overflowing */
.files-table th:nth-child(2) {
  width: 6.5rem;
}

.files-table th:nth-child(3) {
  width: 10rem;
}

.files-table th:nth-child(4) {
  width: 5rem;
}

.trash-table th:nth-child(3) {
  width: 10rem;
}

.trash-table th:nth-child(4) {
  width: 9.5rem;
}

/* Share lists: Shared with/From, Permission, Actions; Path absorbs the rest */
.shares-table th:nth-child(2) {
  width: 10rem;
}

.shares-table th:nth-child(3) {
  width: 7rem;
}

.shares-table th:nth-child(4) {
  width: 7.5rem;
}

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

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}

.file-grid-card {
  padding: 0.75rem;
}

/* Preview (grid) mode reuses the sortable table header above the cards;
   th side padding shrinks by the card padding so labels align with list mode */
.grid-head {
  margin-bottom: 0.9rem;
}

.grid-head th {
  padding: 0.25rem 0.25rem 0.85rem;
}

.file-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.75rem 0.5rem 0.65rem;
  background: var(--surface-raised);
  border-radius: var(--radius);
  color: var(--text);
  text-align: center;
}

.file-card:hover {
  background: var(--accent-soft);
  color: var(--text);
  text-decoration: none;
}

.file-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  /* Square thumbs: height follows the actual column width. */
  aspect-ratio: 1;
  /* Crops the cover-fit image to the thumb's rounded corners. */
  overflow: hidden;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 2rem;
}

/* Thumbs fill the box on both axes (aspect ratio preserved, overflow
   cropped, centered), so rows look uniform regardless of image shape. */
.file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-thumb.thumb-pending {
  opacity: 0.55;
}

.file-thumb.has-thumb {
  color: var(--text);
}

/* %image-gallery sections in the markdown text view: side/bottom padding
   matches the markdown text; the label names the folder (or the note) */
.gallery {
  padding: 0 1rem 1rem;
}

.gallery-label {
  margin: 1.25rem 0 0.5rem;
}

/* image viewer */
body.viewer-open {
  overflow: hidden;
}

dialog.viewer {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  /* UA sheets cap top-layer dialogs at calc(100% - 6px - 2em) on each
     axis; without this the dialog ends short of the viewport bottom. */
  max-height: none;
  margin: 0;
  border: none;
  padding: 0;
  background: #000;
}

/* Flex layout only while open; without the [open] guard this would
   override the UA's dialog:not([open]) { display: none } and the dialog
   could never be closed. */
dialog.viewer[open] {
  display: flex;
  flex-direction: column;
}

dialog.viewer::backdrop {
  background: rgb(0 0 0 / 0.7);
}

/* The stage fills the space between the pinned bars; its padding keeps
   a gap around the photo, which stays centered in what is left. The nav
   buttons anchor to it, so they span exactly the stage height. */
.viewer-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.viewer-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius);
}

.viewer-error-msg {
  display: none;
  color: rgb(255 255 255 / 0.65);
}

dialog.viewer.viewer-error .viewer-img {
  display: none;
}

dialog.viewer.viewer-error .viewer-error-msg {
  display: block;
}

.viewer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex: none;
  padding: 0.6rem 1rem;
  /* Shared floor for both bars (border-box): tall enough for the close
     button on top, so top and bottom always come out the same height and
     the empty bottom bar never shifts layout while EXIF is loading. */
  min-height: 3.75rem;
  background: #000;
}

.viewer-bar-top {
  border-bottom: 1px solid rgb(255 255 255 / 0.12);
}

/* Camera and settings, centered. */
.viewer-bar-bottom {
  justify-content: center;
  border-top: 1px solid rgb(255 255 255 / 0.12);
}

/* Date taken, the middle child: space-between centers it whenever the
   counter and close button have similar widths, close enough in practice. */
.viewer-date {
  flex: none;
  font-size: 0.8rem;
  color: rgb(255 255 255 / 0.65);
  white-space: nowrap;
}

/* Natural width, centered by the bar's space-between; points and "·"
   separators are spans spaced by the flex gap and wrapped to extra lines
   when long. */
.viewer-exif {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  min-width: 0;
  column-gap: 0.6rem;
  column-gap: 1rem;
  font-size: 0.8rem;
  color: rgb(255 255 255 / 0.65);
}

.viewer-exif-sep {
  opacity: 0.6;
}

.viewer-count {
  font-size: 0.8rem;
  color: rgb(255 255 255 / 0.65);
  white-space: nowrap;
}

/* The shared ghost button styling is tuned for light surfaces; on the
   black bar it needs its own palette. */
.viewer-bar .viewer-close {
  color: rgb(255 255 255 / 0.65);
}

.viewer-bar .viewer-close:hover {
  color: rgb(255 255 255 / 0.95);
}

/* Full-height side strips over the stage; transparent until hovered. */
.viewer-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  font-size: 1.25rem;
  background: transparent;
  border: none;
  color: rgb(255 255 255 / 0.8);
  cursor: pointer;
}

.viewer-nav:hover:not(:disabled) {
  background: rgb(255 255 255 / 0.1);
  color: #fff;
}

.viewer-nav:disabled {
  opacity: 0.3;
  cursor: default;
}

.viewer-prev {
  left: 0;
}

.viewer-next {
  right: 0;
}

.file-card-name {
  width: 100%;
  font-size: 0.85rem;
  line-height: 1.3;
}

.file-name a {
  color: var(--text);
}

.file-name a:hover {
  color: var(--accent);
  text-decoration: none;
}

/* Header rows exist in every view (browse, shares, forms, trash); the
   min-height floor matches the .btn-sm height so rows without right-side
   actions keep the same height. Wrapping crumbs still grow the row. */
.page-head {
  min-height: 2.5rem;
}

.breadcrumbs a {
  color: var(--muted);
}

.breadcrumbs a:hover {
  color: var(--accent);
  text-decoration: none;
}

.breadcrumbs .iconoir-nav-arrow-right {
  color: var(--muted);
  font-size: 0.8em;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2.5rem 1rem;
  color: var(--muted);
}

.empty .iconoir-folder {
  font-size: 2.25rem;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--accent-soft);
  color: var(--accent);
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  .container {
    padding: 0 0.85rem 1.5rem;
  }

  .topbar {
    padding: 0.7rem 1rem;
  }

  .file-table th,
  .file-table td {
    padding: 0.7rem 0.75rem;
  }

  .file-table th:nth-child(3),
  .file-table td:nth-child(3) {
    display: none;
  }

  /* File browser: Size yields to the name; Modified stays hidden above */
  .files-table th:nth-child(2),
  .files-table td:nth-child(2) {
    display: none;
  }

  /* Share lists: Shared with/From yield to the path; Permission hidden too,
   leaving just Path | Actions like the trash table */
  .shares-table th:nth-child(2),
  .shares-table td:nth-child(2) {
    display: none;
  }

  .shares-table th:nth-child(4) {
    width: 7rem;
  }

  .trash-table th:nth-child(2),
  .trash-table td:nth-child(2) {
    display: none;
  }

  .file-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.5rem;
  }

  .file-thumb {
    font-size: 1.6rem;
  }
}

@media (pointer: coarse) {
  .btn {
    min-height: 2.75rem;
  }

  .btn-sm {
    min-height: 2.75rem;
    min-width: 2.75rem;
    padding: 0.5rem 0.85rem;
    justify-content: center;
  }

  .page-head {
    min-height: 2.75rem;
  }

  .viewer-nav {
    width: 4.5rem;
  }
}

/* Wide screens: permanent rail at the viewport's left edge */
@media (min-width: 1400px) {
  #sidebar {
    position: fixed;
    top: 4.6rem;
    bottom: 0;
    left: 1.25rem;
    width: 13rem;
    padding: 0.5rem 0;
    overflow-y: auto;
  }
}

/* Below that (desktop-narrow, tablet, mobile): hamburger + slide-in drawer.
   The toggle must come after .btn in the cascade so its display: none wins. */
.nav-toggle {
  display: none;
}

@media (max-width: 1399px) {
  .nav-toggle {
    display: inline-flex;
  }

  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(16rem, 82vw);
    margin: 0;
    border-radius: 0;
    background: var(--surface);
    box-shadow: var(--shadow);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
  }

  html.nav-open #sidebar {
    transform: none;
  }

  #sidebar {
    display: flex;
    flex-direction: column;
  }

  .side-logout {
    display: block;
    margin-top: auto;
    padding: 0.5rem;
  }

  .side-logout .btn {
    width: 100%;
    justify-content: center;
  }

  .logout-form {
    display: none;
  }

  html.nav-open > body {
    overflow: hidden;
  }

  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgb(0 0 0 / 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  html.nav-open .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
}
