/* ==========================================================================
   File Explorer — stylesheet
   Light by default, dark via [data-theme="dark"] on <html>.
   ========================================================================== */

:root {
  --bg: #f5f7f6;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f1f4f3;
  --surface-3: #e9eeec;
  --border: #e3e8e6;
  --border-strong: #d2dad7;
  --text: #16201d;
  --text-soft: #4a5b56;
  --muted: #77877f;
  --accent: #0f766e;
  --accent-hover: #0c5f59;
  --accent-soft: #e3f1ef;
  --accent-ring: rgba(15, 118, 110, 0.25);
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --warn: #b54708;
  --warn-soft: #fdf1e3;
  --shadow-sm: 0 1px 2px rgba(16, 32, 29, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 32, 29, 0.08);
  --shadow-lg: 0 18px 48px rgba(16, 32, 29, 0.14);
  --radius-sm: 7px;
  --radius: 11px;
  --radius-lg: 16px;
  --header-h: 60px;
  --c-pdf: #c8372d;
  --c-doc: #2563a8;
  --c-sheet: #1d7a4c;
  --c-slide: #c05621;
  --c-image: #7c4dbe;
  --c-video: #c22a6e;
  --c-audio: #b57f10;
  --c-archive: #8a6a4a;
  --c-code: #3f5a68;
  --c-other: #78888a;
}

[data-theme='dark'] {
  --bg: #0d1312;
  --bg-elevated: #141c1b;
  --surface: #151e1c;
  --surface-2: #1b2624;
  --surface-3: #223029;
  --border: #26332f;
  --border-strong: #35443f;
  --text: #e7efec;
  --text-soft: #b3c2bd;
  --muted: #839791;
  --accent: #4fd1bd;
  --accent-hover: #6fddcb;
  --accent-soft: #14302c;
  --accent-ring: rgba(79, 209, 189, 0.28);
  --danger: #ff8078;
  --danger-soft: #3a1d1b;
  --warn: #f0a95c;
  --warn-soft: #3a2a17;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.55);
  --c-pdf: #ff8a80;
  --c-doc: #7cb0ea;
  --c-sheet: #6fce9c;
  --c-slide: #f0a86a;
  --c-image: #b998f0;
  --c-video: #f07ab0;
  --c-audio: #e3c069;
  --c-archive: #c3a184;
  --c-code: #8fb0bd;
  --c-other: #9aadaa;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

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

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13.5px;
  font-weight: 550;
  letter-spacing: 0.005em;
  white-space: nowrap;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.1s ease, opacity 0.14s ease;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

[data-theme='dark'] .btn-primary {
  color: #04231f;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-block {
  width: 100%;
  height: 44px;
  font-size: 14.5px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  transition: background 0.14s ease, color 0.14s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   PIN gate
   -------------------------------------------------------------------------- */

.lock {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 520px at 50% -12%, var(--accent-soft), transparent 70%),
    var(--bg);
  overflow-y: auto;
}

.lock-card {
  width: 100%;
  max-width: 372px;
  padding: 34px 30px 26px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: rise 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.lock-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.lock-mark,
.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: var(--accent-soft);
  color: var(--accent);
}

.lock-mark svg {
  width: 24px;
  height: 24px;
}

.lock-card h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.lock-sub {
  margin: 14px 0 20px;
  color: var(--muted);
  font-size: 13.5px;
}

.pin-input {
  width: 100%;
  height: 58px;
  padding: 0 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.42em;
  text-align: center;
  text-indent: 0.42em;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.pin-input::placeholder {
  color: var(--muted);
  letter-spacing: 0.3em;
  text-indent: 0.3em;
}

.pin-input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}

.pin-input:disabled {
  opacity: 0.6;
}

.lock-message {
  min-height: 20px;
  margin: 12px 0 16px;
  font-size: 13px;
  color: var(--muted);
}

.lock-message.is-error {
  color: var(--danger);
  font-weight: 500;
}

.lock-message.is-warn {
  color: var(--warn);
  font-weight: 500;
}

.lock-card.shake {
  animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

.lock-foot {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 11.5px;
}

/* --------------------------------------------------------------------------
   Shell
   -------------------------------------------------------------------------- */

.app {
  min-height: 100vh;
  padding-bottom: 96px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--header-h);
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 22px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 4px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand:hover {
  background: var(--surface-2);
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
}

.brand-mark svg {
  width: 17px;
  height: 17px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  margin-right: 6px;
}

.search svg {
  position: absolute;
  left: 10px;
  width: 15px;
  height: 15px;
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 180px;
  height: 36px;
  padding: 0 12px 0 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, width 0.18s ease, background 0.14s ease;
}

.search input::placeholder {
  color: var(--muted);
}

.search input:focus {
  outline: none;
  width: 230px;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

#theme-toggle .icon-moon {
  display: none;
}

[data-theme='dark'] #theme-toggle .icon-sun {
  display: none;
}

[data-theme='dark'] #theme-toggle .icon-moon {
  display: block;
}

/* Breadcrumbs ------------------------------------------------------------- */

.crumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 22px 11px;
  font-size: 13px;
}

.crumb {
  padding: 3px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  transition: background 0.14s ease, color 0.14s ease;
}

.crumb:hover {
  background: var(--surface-2);
  color: var(--text);
}

.crumb.is-current {
  color: var(--text);
  font-weight: 600;
}

.crumb-sep {
  color: var(--border-strong);
  user-select: none;
}

/* --------------------------------------------------------------------------
   Main content
   -------------------------------------------------------------------------- */

.main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 22px 40px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 12px;
}

.section-title {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-meta {
  font-size: 12.5px;
  color: var(--muted);
}

.section + .section {
  margin-top: 30px;
}

/* Folder grid ------------------------------------------------------------- */

.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(212px, 1fr));
  gap: 12px;
}

.folder-card {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 15px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.folder-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.folder-card:active {
  transform: translateY(0);
}

.folder-glyph {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}

.folder-glyph svg {
  width: 21px;
  height: 21px;
}

.folder-text {
  min-width: 0;
  flex: 1;
}

.folder-name {
  display: block;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.folder-sub {
  display: block;
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
}

.folder-chevron {
  flex: none;
  color: var(--border-strong);
  transition: transform 0.15s ease, color 0.15s ease;
}

.folder-card:hover .folder-chevron {
  color: var(--accent);
  transform: translateX(2px);
}

.folder-chevron svg {
  width: 16px;
  height: 16px;
}

/* File table -------------------------------------------------------------- */

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

table.files th,
table.files td {
  padding: 0 12px;
  text-align: left;
  vertical-align: middle;
}

table.files thead th {
  height: 38px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
  white-space: nowrap;
}

th.sortable {
  cursor: pointer;
}

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

th .sort-arrow {
  margin-left: 5px;
  opacity: 0;
  font-size: 10px;
}

th.is-sorted .sort-arrow {
  opacity: 1;
  color: var(--accent);
}

.col-check {
  width: 44px;
  padding-left: 16px !important;
}

.col-size {
  width: 110px;
}

.col-date {
  width: 172px;
}

.col-actions {
  width: 92px;
  text-align: right !important;
  padding-right: 16px !important;
}

table.files tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.12s ease;
}

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

table.files tbody tr:hover {
  background: var(--surface-2);
}

table.files tbody tr.is-selected {
  background: var(--accent-soft);
}

table.files tbody td {
  height: 50px;
  font-size: 13.5px;
}

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

.file-glyph {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--c-other);
}

.file-glyph svg {
  width: 16px;
  height: 16px;
}

.k-pdf { color: var(--c-pdf); background: color-mix(in srgb, var(--c-pdf) 12%, transparent); }
.k-doc { color: var(--c-doc); background: color-mix(in srgb, var(--c-doc) 12%, transparent); }
.k-sheet { color: var(--c-sheet); background: color-mix(in srgb, var(--c-sheet) 12%, transparent); }
.k-slide { color: var(--c-slide); background: color-mix(in srgb, var(--c-slide) 12%, transparent); }
.k-image { color: var(--c-image); background: color-mix(in srgb, var(--c-image) 12%, transparent); }
.k-video { color: var(--c-video); background: color-mix(in srgb, var(--c-video) 12%, transparent); }
.k-audio { color: var(--c-audio); background: color-mix(in srgb, var(--c-audio) 12%, transparent); }
.k-archive { color: var(--c-archive); background: color-mix(in srgb, var(--c-archive) 12%, transparent); }
.k-code { color: var(--c-code); background: color-mix(in srgb, var(--c-code) 12%, transparent); }
.k-other { color: var(--c-other); background: color-mix(in srgb, var(--c-other) 12%, transparent); }

.file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-name .ext {
  color: var(--muted);
}

.cell-size,
.cell-date {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.cell-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.14s ease;
}

tr:hover .cell-actions,
tr.is-selected .cell-actions,
.cell-actions:focus-within {
  opacity: 1;
}

.row-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  transition: background 0.12s ease, color 0.12s ease;
}

.row-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.row-btn.primary:hover {
  background: var(--accent);
  color: #fff;
}

[data-theme='dark'] .row-btn.primary:hover {
  color: #04231f;
}

.row-btn svg {
  width: 16px;
  height: 16px;
}

/* Folder rows inside a folder's table -------------------------------------- */

tr.row-folder {
  cursor: pointer;
}

tr.row-folder .file-name {
  font-weight: 550;
}

/* The chevron is the only affordance saying "this opens", so keep it visible. */
tr.row-folder .cell-actions {
  opacity: 1;
}

.glyph-folder {
  color: var(--accent);
  background: var(--accent-soft);
}

.row-note {
  margin-left: 8px;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--muted);
}

/* Back button below the listing -------------------------------------------- */

.back-row {
  display: flex;
  margin-top: 22px;
}

/* Checkboxes -------------------------------------------------------------- */

.check {
  display: inline-grid;
  place-items: center;
  position: relative;
  width: 18px;
  height: 18px;
  flex: none;
}

.check input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.check .box {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  transition: background 0.13s ease, border-color 0.13s ease;
}

.check .box svg {
  width: 12px;
  height: 12px;
  color: #fff;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.13s ease, transform 0.13s ease;
}

[data-theme='dark'] .check .box svg {
  color: #04231f;
}

.check input:checked + .box,
.check input:indeterminate + .box {
  background: var(--accent);
  border-color: var(--accent);
}

.check input:checked + .box svg {
  opacity: 1;
  transform: none;
}

.check input:indeterminate + .box::after {
  content: '';
  width: 9px;
  height: 2px;
  border-radius: 2px;
  background: #fff;
}

[data-theme='dark'] .check input:indeterminate + .box::after {
  background: #04231f;
}

.check input:focus-visible + .box {
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* Empty / loading states -------------------------------------------------- */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 64px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.state svg {
  width: 34px;
  height: 34px;
  color: var(--muted);
}

.state h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.state p {
  margin: 0;
  max-width: 420px;
  color: var(--muted);
  font-size: 13.5px;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* Skeleton ----------------------------------------------------------------- */

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(212px, 1fr));
  gap: 12px;
}

.sk {
  height: 72px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

/* Selection bar ----------------------------------------------------------- */

.selection-bar {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 11px 13px 11px 20px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
  transform: translateX(-50%);
  animation: pop 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.selection-info {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13.5px;
  white-space: nowrap;
}

.selection-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Toasts ------------------------------------------------------------------ */

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-md);
  font-size: 13.5px;
  animation: slide-in 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.warn {
  border-left-color: var(--warn);
}

.toast.leaving {
  animation: slide-out 0.18s ease forwards;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: none; }
}

@keyframes slide-out {
  to { opacity: 0; transform: translateX(16px); }
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .topbar-inner {
    padding: 0 14px;
    gap: 8px;
  }

  .search input {
    width: 44px;
    padding-right: 0;
    cursor: pointer;
  }

  .search input:focus {
    width: 150px;
    padding-right: 12px;
  }

  .brand span:last-child {
    display: none;
  }

  .crumbs,
  .main {
    padding-left: 14px;
    padding-right: 14px;
  }

  .folder-grid,
  .skeleton-grid {
    grid-template-columns: 1fr;
  }

  .col-date,
  .cell-date {
    display: none;
  }

  .col-size {
    width: 84px;
  }

  .cell-actions {
    opacity: 1;
  }

  .selection-bar {
    left: 14px;
    right: 14px;
    bottom: 14px;
    transform: none;
    justify-content: space-between;
    gap: 10px;
  }

  @keyframes pop {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
  }

  .toasts {
    left: 14px;
    right: 14px;
    bottom: 84px;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
