/* ============================================================================
   files-web-ui — app.css
   Everything specific to this project that reboot.css doesn't provide.
   Load order: reboot.css → brand.css → app.css (later wins the cascade).

   Keep reboot.css stock — project changes belong here (or in brand.css),
   so a new design-system release is a straight drop-in replacement.
   ========================================================================== */


/* ── Base ── */

/* Icon font (iconoir, via CDN): size and align icons with inline text. */
[class^="iconoir-"],
[class*=" iconoir-"] {
  font-size: 1.25em;
  vertical-align: -0.12em;
}

/* The layout's centered column: breathing room below the sticky topbar
   and above the page end. */
.container {
  padding-top: 1.5rem;
  padding-bottom: 2rem;
}

/* Cards here manage their own padding (tables, .text-view and
   .markdown-body pad themselves), so cards stay flush. */
.card { padding: 0; }

/* Inputs stay at 16px — smaller triggers zoom-on-focus on iOS. */
.input { font-size: 1rem; }


/* ── Forms (text editor) ── */

.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;
}


/* ── Buttons ── */

/* Card-colored button — matches the card fill (reboot's .btn-ghost is
   transparent; this one sits on surfaces). */
.btn-card {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-card:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: none;
}

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


/* ── Plain text view ── */

.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);
}


/* ── Markdown view ── */

.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 .task-list-item-checkbox:not([disabled]) {
  cursor: pointer;
}

.markdown-body label.task-list-item-label {
  cursor: pointer;
}

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

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

/* Un-box the system's base code/pre styles inside markdown (bg stays). */
.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--surface-raised);
  border: 0;
  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: 0;
  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 ── */

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


/* ── File browser ── */

.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;
}

.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 .iconoir-folder {
  font-size: 2.25rem;
}


/* ── Image viewer (black lightbox over everything) ── */

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;
}


/* ── Sidebar: mobile-only logout ──
   The drawer carries its own logout below the nav links; desktop keeps the
   topbar form. Reboot.css owns the rail/drawer geometry and .nav-open logic. */

.side-logout {
  display: none;
}


/* ── Responsive ── */

@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) {
  .page-head {
    min-height: 2.75rem;
  }

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

@media (max-width: 1399.98px) {
  #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;
  }
}
