/* ============================================================================
   FILE DOWNLOADER — Application styles
   Layered on top of kit.css (PYMEHackers design system). The design tokens in
   :root are never redefined here: this file only adds the pieces the platform
   needs (file tables, forms, modals, stat tiles) using those same tokens.

   Mobile rules honoured throughout: no fixed pixel widths for content, no
   100vw, no overflow-x:hidden on html/body, min-width:0 on every grid/flex
   child that holds text, and overflow-wrap:anywhere on anything that can hold
   a path, a token or an e-mail address.
   ============================================================================ */

/* ----------------------------------------------------------------------------
   0. HIDDEN ELEMENTS
   The browser's own `[hidden] { display: none }` is a low-specificity user
   agent rule, so any class that sets `display` (the kit's .button uses
   inline-flex) silently defeats it. Everything in this application toggles
   visibility through the `hidden` attribute, so it is enforced once here.
   ---------------------------------------------------------------------------- */

[hidden] {
  display: none !important;
}

/* Flex/grid children and user-supplied text must be allowed to shrink. */
body * {
  min-width: 0;
  overflow-wrap: anywhere;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ----------------------------------------------------------------------------
   0b. TOP BAR
   The kit's .nav is a three-column flex row with a 28px gap and no wrapping,
   which is fine for a landing page but overflows here: this application adds a
   language selector and a sign-out button next to the brand. The row is
   therefore allowed to wrap and its gap shrinks on narrow screens.
   ---------------------------------------------------------------------------- */

.nav {
  flex-wrap: wrap;
  gap: 12px 18px;
  padding: 10px 0;
}

.nav > * {
  min-width: 0;
}

.nav-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.nav-tools .button {
  white-space: nowrap;
}

@media (max-width: 760px) {
  .nav {
    gap: 10px 12px;
  }

  /* The kit pins the mobile drop-down 78px from the top of .topbar (which is
     the containing block, being position:sticky). This bar can wrap and grow
     taller than that, so the menu is anchored to the bar's own height. */
  .nav-links {
    top: calc(100% + 8px);
  }
}

@media (max-width: 400px) {
  .nav-tools .button {
    padding: 6px 11px;
    font-size: 0.78rem;
  }

}

/* ----------------------------------------------------------------------------
   1. APPLICATION SHELL
   ---------------------------------------------------------------------------- */

.app-main {
  padding: 34px 0 72px;
}

.app-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 26px;
}

.app-head > * {
  min-width: 0;
}

.app-head h1 {
  font-size: clamp(1.9rem, 4.4vw, 2.9rem);
  letter-spacing: -0.055em;
  line-height: 1.02;
}

.app-head p {
  color: var(--color-muted);
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.app-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ----------------------------------------------------------------------------
   2. PANELS
   ---------------------------------------------------------------------------- */

.app-panel {
  background: linear-gradient(180deg, #141414 0%, #101010 100%);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.18);
  padding: 22px;
  margin-bottom: 22px;
  min-width: 0;
}

.app-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.app-panel-head > * {
  min-width: 0;
}

.app-panel-head h2 {
  font-size: 1.28rem;
  letter-spacing: -0.035em;
  line-height: 1.02;
}

.app-panel-note {
  color: var(--color-muted-2);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

/* ----------------------------------------------------------------------------
   3. STAT TILES
   ---------------------------------------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-tile {
  min-width: 0;
  background: #0A0A0A;
  border: 1px solid var(--color-border-soft);
  border-radius: 14px;
  padding: 16px 18px;
}

.stat-tile .stat-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-muted-2);
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.stat-tile .stat-value {
  display: block;
  font-size: clamp(1.35rem, 3.4vw, 1.85rem);
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 1.05;
  color: var(--color-text);
  overflow-wrap: anywhere;
}

.stat-tile .stat-value.red {
  color: var(--color-red);
}

.stat-tile .stat-sub {
  display: block;
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--color-muted-2);
  overflow-wrap: anywhere;
}

/* ----------------------------------------------------------------------------
   4. TABLES
   Every table lives inside .table-wrap so wide content scrolls in its own box
   instead of dragging the whole document sideways.
   ---------------------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  border: 1px solid var(--color-border-soft);
}

.app-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 520px;
}

.app-table th,
.app-table td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  vertical-align: middle;
}

.app-table th {
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-muted-2);
  background: #0A0A0A;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.app-table tbody tr:hover {
  background: rgba(210, 44, 33, 0.045);
}

.app-table tbody tr:last-child td {
  border-bottom: none;
}

.app-table td.cell-path,
.app-table td.cell-wrap {
  overflow-wrap: anywhere;
  min-width: 0;
}

.app-table td.cell-num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.app-table td.cell-actions {
  white-space: nowrap;
  text-align: right;
}

.app-table .muted {
  color: var(--color-muted-2);
}

/* ----------------------------------------------------------------------------
   5. FILE BROWSER
   ---------------------------------------------------------------------------- */

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  min-width: 0;
}

.crumbs a,
.crumbs span {
  color: var(--color-muted);
  overflow-wrap: anywhere;
}

.crumbs a:hover {
  color: var(--color-red);
}

.crumbs .sep {
  color: var(--color-muted-2);
}

.crumbs .current {
  color: var(--color-text);
  font-weight: 700;
}

.entry-name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.entry-name .entry-icon {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  color: var(--color-red);
  filter: drop-shadow(0 0 12px rgba(210, 44, 33, 0.22));
}

.entry-name .entry-label {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--color-text);
}

.entry-name a.entry-label:hover {
  color: var(--color-red);
}

.entry-name .entry-link-badge {
  flex: 0 0 auto;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.filter-row > * {
  min-width: 0;
  flex: 1 1 200px;
}

/* ----------------------------------------------------------------------------
   6. FORMS
   ---------------------------------------------------------------------------- */

.field {
  margin-bottom: 15px;
  min-width: 0;
}

.field label,
.label {
  display: block;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-muted-2);
  margin-bottom: 7px;
}

.input,
.select,
.textarea {
  width: 100%;
  max-width: 100%;
  padding: 11px 13px;
  background: #0A0A0A;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-red);
  box-shadow: 0 0 0 3px rgba(210, 44, 33, 0.18);
}

.textarea {
  min-height: 90px;
  resize: vertical;
}

.field-hint {
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--color-muted-2);
  overflow-wrap: anywhere;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
  gap: 14px;
}

.field-row > * {
  min-width: 0;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
  min-width: 0;
}

.check input[type="checkbox"] {
  flex: 0 0 auto;
  margin-top: 3px;
  width: 17px;
  height: 17px;
  accent-color: var(--color-red);
}

.check span {
  min-width: 0;
  color: var(--color-muted);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

/* ----------------------------------------------------------------------------
   7. BUTTONS (small variants on top of the kit's .button)
   ---------------------------------------------------------------------------- */

.button-small {
  padding: 7px 13px;
  font-size: 0.82rem;
  border-radius: 999px;
}

.button-ghost {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-muted);
}

.button-ghost:hover {
  border-color: var(--color-red);
  color: var(--color-text);
}

.button-danger {
  background: transparent;
  border: 1px solid rgba(210, 44, 33, 0.45);
  color: var(--color-red);
}

.button-danger:hover {
  background: rgba(210, 44, 33, 0.12);
  color: var(--color-red-hover);
}

.button[disabled],
.button[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

/* ----------------------------------------------------------------------------
   8. BADGES
   ---------------------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--color-border);
  color: var(--color-muted);
  white-space: nowrap;
}

.badge-ok {
  border-color: rgba(210, 44, 33, 0.30);
  color: var(--color-red);
  background: rgba(210, 44, 33, 0.08);
}

.badge-off {
  border-color: var(--color-border);
  color: var(--color-muted-2);
}

.badge-admin {
  border-color: rgba(255, 255, 255, 0.22);
  color: var(--color-text);
}

/* ----------------------------------------------------------------------------
   9. TABS
   ---------------------------------------------------------------------------- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--color-border-soft);
  padding-bottom: 12px;
}

.tab {
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-muted);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover {
  color: var(--color-text);
}

.tab[aria-selected="true"] {
  border-color: rgba(210, 44, 33, 0.30);
  background: rgba(210, 44, 33, 0.10);
  color: var(--color-red);
}

.tab-panel[hidden] {
  display: none;
}

/* ----------------------------------------------------------------------------
   10. MODAL
   ---------------------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
  z-index: 90;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 560px;
  background: linear-gradient(180deg, #161616 0%, #0E0E0E 100%);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft), var(--shadow-red);
  padding: 26px;
  margin: auto;
  min-width: 0;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.modal-head h2 {
  font-size: 1.35rem;
  letter-spacing: -0.04em;
  line-height: 1.05;
  min-width: 0;
  overflow-wrap: anywhere;
}

.modal-close {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  color: var(--color-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  border-color: var(--color-red);
  color: var(--color-text);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ----------------------------------------------------------------------------
   11. RESULT / SECRET BOXES
   Short link URLs, generated passwords and TOTP secrets are long unbroken
   strings, so they always get overflow-wrap:anywhere.
   ---------------------------------------------------------------------------- */

.secret-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  background: #000;
  border: 1px solid rgba(210, 44, 33, 0.28);
  border-radius: 12px;
  padding: 13px 15px;
  margin: 12px 0;
  min-width: 0;
}

.secret-box code {
  flex: 1 1 240px;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.88rem;
  color: var(--color-text);
  overflow-wrap: anywhere;
}

.qr-box {
  display: flex;
  justify-content: center;
  padding: 16px;
  background: #FFFFFF;
  border-radius: 14px;
  margin: 14px 0;
}

.qr-box svg {
  width: 100%;
  max-width: 220px;
  height: auto;
  display: block;
}

/* ----------------------------------------------------------------------------
   12. MESSAGES AND TOASTS
   ---------------------------------------------------------------------------- */

.notice {
  border-radius: 12px;
  padding: 13px 16px;
  margin-bottom: 18px;
  font-size: 0.92rem;
  border: 1px solid var(--color-border);
  color: var(--color-muted);
  overflow-wrap: anywhere;
}

.notice-error {
  border-color: rgba(210, 44, 33, 0.45);
  background: rgba(210, 44, 33, 0.10);
  color: #F0C9C6;
}

.notice-ok {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text);
}

.notice[hidden] {
  display: none;
}

.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
  z-index: 120;
}

.toast {
  max-width: 100%;
  background: #0A0A0A;
  border: 1px solid rgba(210, 44, 33, 0.30);
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
  padding: 12px 16px;
  color: var(--color-text);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
  pointer-events: auto;
}

.toast-error {
  border-color: rgba(210, 44, 33, 0.55);
  color: #F0C9C6;
}

/* ----------------------------------------------------------------------------
   13. LOGIN / SHARE PAGES
   ---------------------------------------------------------------------------- */

.auth-wrap {
  display: flex;
  justify-content: center;
  padding: 56px 0 80px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: linear-gradient(180deg, #151515 0%, #0D0D0D 100%);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft), var(--shadow-red);
  padding: 32px 28px;
  min-width: 0;
}

.auth-card h1 {
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  letter-spacing: -0.055em;
  line-height: 1.02;
  margin-bottom: 8px;
}

.auth-card .lead {
  margin-bottom: 24px;
}

.share-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 12px;
  margin: 20px 0;
}

.share-meta > div {
  min-width: 0;
}

.share-meta dt {
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-muted-2);
  margin-bottom: 5px;
}

.share-meta dd {
  color: var(--color-text);
  overflow-wrap: anywhere;
}

/* ----------------------------------------------------------------------------
   14. LANGUAGE SWITCH
   ---------------------------------------------------------------------------- */

.lang-switch {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.lang-switch .select {
  /* Intrinsic select width includes the widest code, padding and native arrow. */
  width: auto;
  min-width: 0;
  padding: 7px 11px;
  font-size: 0.82rem;
  border-radius: 999px;
}

/* ----------------------------------------------------------------------------
   15. EMPTY STATES AND LOADERS
   ---------------------------------------------------------------------------- */

.empty-state {
  text-align: center;
  padding: 46px 20px;
  color: var(--color-muted-2);
}

.empty-state strong {
  display: block;
  color: var(--color-text);
  font-size: 1.1rem;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.loading {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--color-red);
  border-radius: 50%;
  animation: fd-spin 0.7s linear infinite;
  vertical-align: -2px;
}

@keyframes fd-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading {
    animation: none;
  }
}

/* ----------------------------------------------------------------------------
   16. MOBILE
   Only spacing and type scale change; no layout depends on a fixed width.
   ---------------------------------------------------------------------------- */

@media (max-width: 760px) {
  .app-main {
    padding: 24px 0 56px;
  }

  .app-panel {
    padding: 18px 15px;
    border-radius: 14px;
  }

  .modal {
    padding: 20px 16px;
    border-radius: 18px;
  }

  .auth-card {
    padding: 26px 18px;
  }

  .app-table {
    font-size: 0.86rem;
    min-width: 460px;
  }

  .app-table th,
  .app-table td {
    padding: 9px 11px;
  }

  .app-actions .button {
    flex: 1 1 auto;
    justify-content: center;
  }
}

@media (max-width: 420px) {
  .app-table {
    min-width: 380px;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toast-stack {
    align-items: stretch;
  }
}

@media (max-width: 639px) {
  pre {
    padding: 8px;
    font-size: 11px;
  }
}
