*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ────────────────────────────────────────── */
/* The accent follows the space being viewed, so the page always shows
   whether an action affects the shared space or a personal one. */
:root {
  --bg:        #F5F6F8;
  --surface:   #FFFFFF;
  --surface-2: #F0F2F4;
  --border:    #E2E5E9;
  --border-strong: #CDD2D8;
  --text:      #15181D;
  --muted:     #5D6570;
  --danger:    #C62828;
  --danger-bg: #FDECEC;
  --success:   #1E7A46;
  --inverse:   #15181D;
  --inverse-text: #FFFFFF;
  --shared:    #0E7490;
  --personal:  #C2410C;
  --on-accent: #FFFFFF;
  --shadow-lg: 0 18px 48px rgba(16, 22, 30, 0.14), 0 2px 6px rgba(16, 22, 30, 0.06);
  --radius-sm: 8px;
  --radius:    10px;
  --radius-lg: 16px;
  --font: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Segoe UI', 'Malgun Gothic', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0E1014;
    --surface:   #16191E;
    --surface-2: #1E2228;
    --border:    #2A2F37;
    --border-strong: #3A404A;
    --text:      #E9EBEE;
    --muted:     #9BA2AD;
    --danger:    #F47171;
    --danger-bg: #3A1C1E;
    --success:   #5CCB8A;
    --inverse:   #E9EBEE;
    --inverse-text: #15181D;
    --shared:    #3CC3D9;
    --personal:  #FB8C4E;
    --on-accent: #0E1014;
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.5);
  }
}

/* Set on body, not :root: the derived colors must be computed from the
   space's accent, and a custom property resolves where it is declared. */
body {
  --accent: var(--shared);
  --accent-soft: color-mix(in srgb, var(--accent) 10%, var(--surface));
  --accent-ring: color-mix(in srgb, var(--accent) 45%, transparent);
}
body[data-scope="personal"] { --accent: var(--personal); }

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* Korean wraps between words, not inside them; long names still wrap. */
  word-break: keep-all;
  overflow-wrap: break-word;
}

.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

svg { flex-shrink: 0; }

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

/* ── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

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

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

.btn-primary,
.btn-blue {
  background: var(--accent);
  border-color: transparent;
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled),
.btn-blue:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 88%, var(--text));
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
}

.btn-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  background: transparent;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-bg);
}

.btn-danger-solid {
  background: #C62828;
  border-color: transparent;
  color: #FFFFFF;
}

.btn-danger-solid:hover:not(:disabled) {
  background: #A82020;
}

.btn-icon {
  width: 40px;
  padding: 0;
}

.btn-sm {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
  height: 46px;
  font-size: 15px;
}

/* ── Forms ─────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

.form-group.modal-field {
  margin-top: 14px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  height: 46px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0 14px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.form-input::placeholder,
.search-input::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.password-field {
  position: relative;
}

.password-field .form-input {
  padding-right: 48px;
}

/* Edge draws its own reveal button inside password inputs. */
.password-field .form-input::-ms-reveal {
  display: none;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 38px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

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

.password-toggle:focus-visible {
  outline-offset: -2px;
}

.password-toggle .eye-slash {
  display: none;
}

.password-toggle[aria-pressed="true"] .eye-slash {
  display: inline;
}

.error-box {
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 14px;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

/* ── Auth / Login View ─────────────────────────────── */
.auth-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

.auth-cancel {
  margin-top: 8px;
  color: var(--muted);
}

.auth-note {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  word-break: keep-all;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--inverse);
  color: var(--inverse-text);
}

.auth-title {
  margin: 28px 0 6px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-desc {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 24px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 24px;
}

.auth-tab {
  height: 38px;
  background: transparent;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(16, 22, 30, 0.12);
}

/* ── Main App Header ───────────────────────────────── */
header.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.space-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.space-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* ── Quota ─────────────────────────────────────────── */
.quota-box {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 180px;
  padding: 0 4px;
}

.quota-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.quota-track {
  height: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.quota-fill {
  width: 0;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.quota-fill.warn { background: #D97706; }
.quota-fill.danger { background: var(--danger); }

/* ── Content ───────────────────────────────────────── */
.main-container {
  max-width: 1160px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 24px 120px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  font-size: 13px;
}

.crumb-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

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

.crumb-btn:first-child {
  margin-left: -6px;
}

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

.page-title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.25;
  word-break: break-all;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

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

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 1 300px;
  min-width: 180px;
}

.search-box svg {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0 12px 0 38px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}

.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6 6 18'/%3E%3C/svg%3E") center / contain no-repeat;
  cursor: pointer;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* ── Upload Queue ──────────────────────────────────── */
.upload-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 70;
  width: 360px;
  max-width: calc(100% - 24px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

/* Clear of the selection bar. */
body.selecting .upload-panel { bottom: 92px; }

.upload-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px 6px 16px;
}

.upload-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  background: none;
  border: none;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  text-align: left;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.upload-toggle svg {
  color: var(--muted);
  transition: transform 0.15s ease;
}

.upload-panel.collapsed .upload-toggle svg { transform: rotate(180deg); }
.upload-panel.collapsed .upload-list { display: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  cursor: pointer;
}

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

.upload-overall {
  height: 3px;
  background: var(--surface-2);
}

.upload-overall-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s ease;
}

.upload-list {
  list-style: none;
  max-height: 288px;
  overflow-y: auto;
  padding: 4px 0;
}

.upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px 7px 16px;
}

.upload-row .file-icon { width: 22px; height: 22px; }
.upload-row .file-icon svg { width: 18px; height: 18px; }

.upload-info {
  flex: 1;
  min-width: 0;
}

.upload-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-status {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.upload-row.done .upload-status { color: var(--success); }
.upload-row.error .upload-status { color: var(--danger); }
.upload-row.canceled .upload-name { color: var(--muted); }

.upload-track {
  height: 3px;
  margin-top: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.upload-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.1s linear;
}

.upload-row .upload-action {
  flex-shrink: 0;
  height: 28px;
  padding: 0 9px;
  font-size: 12px;
}

.upload-row.paused .upload-status { color: var(--muted); }

.upload-cancel {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--muted);
  cursor: pointer;
}

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

.fab { display: none; }

.search-status {
  margin-top: -6px;
  font-size: 13px;
  color: var(--muted);
}

/* ── File Table ────────────────────────────────────── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

table.file-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.file-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
  background: none;
  border: none;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
}

.sort-btn:hover,
.sort-btn.active {
  color: var(--text);
}

.sort-btn::after {
  width: 10px;
  font-size: 11px;
}

.sort-btn[data-dir="asc"]::after { content: '↑'; }
.sort-btn[data-dir="desc"]::after { content: '↓'; }


.file-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

.file-table tbody tr {
  transition: background-color 0.1s ease;
}

/* Touch screens would keep a tapped row "hovered". */
@media (hover: hover) {
  .file-table tbody tr:hover {
    background: var(--surface-2);
  }

  .file-link:hover .file-name {
    color: var(--accent);
  }
}

.file-table tbody tr.selected,
.file-table tbody tr.selected:hover {
  background: var(--accent-soft);
}

.file-table .col-select {
  width: 44px;
  padding-right: 0;
}

.file-table .col-size { width: 110px; }
.file-table .col-mod { width: 160px; }
.file-table .col-actions { width: 170px; text-align: right; }

.col-select input {
  width: 17px;
  height: 17px;
  vertical-align: middle;
  accent-color: var(--accent);
  cursor: pointer;
}

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

.file-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  color: color-mix(in srgb, var(--muted) 80%, var(--surface));
}

.file-icon svg { width: 21px; height: 21px; }
.file-icon[data-kind="folder"] { color: var(--accent); }
.file-icon[data-kind="folder"] svg { width: 26px; height: 26px; }

.file-link {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}

.file-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.file-name {
  overflow-wrap: anywhere;
}

.file-sub {
  display: none;
  margin-top: 1px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}


.file-meta {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.file-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.file-actions .btn {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
}

.file-actions .btn:hover:not(:disabled) {
  background: var(--border);
  color: var(--text);
}

.file-actions .btn-more {
  width: 32px;
  padding: 0;
}

.file-location {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 56px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.empty-state svg {
  color: var(--border-strong);
}

/* ── Selection Bar ─────────────────────────────────── */
.selection-bar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 16px;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 8px 8px 8px 20px;
  border-radius: 999px;
  background: var(--inverse);
  color: var(--inverse-text);
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
}

.selection-actions {
  display: flex;
  gap: 6px;
}

.selection-bar .btn {
  height: 38px;
  border-radius: 999px;
}

.selection-count {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.selection-bar .btn:not(.btn-danger-solid) {
  border-color: transparent;
  background: color-mix(in srgb, var(--inverse-text) 14%, var(--inverse));
  color: var(--inverse-text);
}

.selection-bar .btn:not(.btn-danger-solid):hover:not(:disabled) {
  background: color-mix(in srgb, var(--inverse-text) 24%, var(--inverse));
}

.selection-bar .btn-clear {
  width: 38px;
  padding: 0;
}

/* ── Drag & Drop Overlay ───────────────────────────── */
.drop-overlay {
  position: fixed;
  inset: 12px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px dashed var(--accent);
  border-radius: 20px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.drop-overlay svg {
  color: var(--accent);
}

.drop-overlay-title {
  font-size: 20px;
  font-weight: 700;
}

.drop-overlay-sub {
  font-size: 14px;
  color: var(--muted);
}

/* ── Modal ─────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(10, 12, 16, 0.45);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.modal-wide { max-width: 640px; }

.modal-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}

.modal-desc {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 18px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

.modal-footer .footer-start { margin-right: auto; }

.conflict-list {
  list-style: none;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
  font-size: 13px;
  max-height: 160px;
  overflow-y: auto;
}

.conflict-list li { overflow-wrap: anywhere; }

.move-crumbs { margin-bottom: 8px; }

.move-list {
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: min(300px, 45dvh);
  overflow-y: auto;
}

.move-list li + li { border-top: 1px solid var(--border); }

.move-folder {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: none;
  border: none;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.move-folder span:last-child { overflow-wrap: anywhere; }
.move-folder:hover:not(:disabled) { background: var(--surface-2); }
.move-folder:disabled { opacity: 0.4; cursor: not-allowed; }

.move-empty,
.trash-empty {
  padding: 22px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.move-hint {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}

.trash-list {
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: min(420px, 55dvh);
  overflow-y: auto;
}

.trash-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 14px;
}

.trash-row + .trash-row { border-top: 1px solid var(--border); }

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

.trash-name {
  font-size: 14px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.trash-sub {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.btn.trash-purge { color: var(--danger); }
.btn.trash-purge:hover:not(:disabled) { background: var(--danger-bg); }

/* ── Item Menu ─────────────────────────────────────── */
.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 130;
}

.context-menu {
  position: fixed;
  z-index: 131;
  display: flex;
  flex-direction: column;
  min-width: 210px;
  max-width: 280px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}

.menu-title { display: none; }

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  height: 36px;
  padding: 0 10px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: var(--surface-2);
  outline: none;
}

.menu-item.danger { color: var(--danger); }

.menu-hint {
  font-family: inherit;
  font-size: 12px;
  color: var(--muted);
}

.menu-sep {
  height: 1px;
  margin: 5px 4px;
  background: var(--border);
}

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

.viewer {
  position: fixed;
  inset: 0;
  z-index: 140;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  /* Opaque: page text showing through would compete with the photo. */
  background: #0D0E11;
  color: #F2F3F5;
}

.viewer-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 12px 10px 20px;
}

.viewer-heading {
  flex: 1;
  min-width: 0;
}

.viewer-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-count {
  font-size: 12px;
  color: rgba(242, 243, 245, 0.6);
  font-variant-numeric: tabular-nums;
}

.viewer-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.viewer-btn:hover { background: rgba(255, 255, 255, 0.1); }

.viewer-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0 80px 28px;
  touch-action: pan-y;
}

.viewer-media {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.viewer-image {
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
}

.viewer-video { width: 100%; height: 100%; }
.viewer-audio { width: min(480px, 100%); }

.viewer-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  font-size: 14px;
  text-align: center;
  color: rgba(242, 243, 245, 0.75);
}

.viewer .btn {
  border-color: transparent;
  background: rgba(255, 255, 255, 0.14);
  color: #F2F3F5;
}

.viewer-nav {
  position: absolute;
  top: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin-top: -24px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #F2F3F5;
  cursor: pointer;
}

.viewer-nav:hover { background: rgba(255, 255, 255, 0.2); }
.viewer-nav.prev { left: 16px; }
.viewer-nav.next { right: 16px; }
.viewer-nav:disabled { visibility: hidden; }

/* ── Toast ─────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 72px;
  right: 20px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: 420px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--inverse);
  color: var(--inverse-text);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.18s ease-out;
}

.toast::before {
  content: '';
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--inverse-text) 50%, transparent);
}

.toast.has-action {
  align-items: center;
  pointer-events: auto;
}

.toast.has-action::before { margin-top: 0; }

.toast-action {
  margin-left: auto;
  padding: 4px 2px 4px 10px;
  background: none;
  border: none;
  font: inherit;
  font-weight: 700;
  color: var(--inverse-text);
  white-space: nowrap;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.toast.success::before { background: #3DDC84; }
.toast.error::before { background: #FF6B6B; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* ── Title Row, Sort and View ──────────────────────── */
.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.view-btn {
  flex-shrink: 0;
  gap: 4px;
  color: var(--muted);
}

.select-all-label { display: none; }
.account-btn { display: none; }

.menu-item.checked { color: var(--accent); font-weight: 600; }
.menu-item.checked::after { content: '✓'; margin-left: auto; padding-left: 12px; }

/* ── Thumbnails and the Picture Grid ───────────────── */
.file-icon.has-thumb img {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-2);
}

.file-table.grid { display: block; }
/* Only "select all" is left of the header, and only while selecting. */
body:not(.selecting) .file-table.grid thead { display: none; }
.file-table.grid thead { display: block; }
.file-table.grid thead tr { display: flex; align-items: center; gap: 10px; padding: 12px 14px 0; }
.file-table.grid thead th { display: none; padding: 0; border: none; }
.file-table.grid thead .col-select,
.file-table.grid thead .col-name { display: block; position: static; width: auto; }
.file-table.grid .sort-btn { display: none; }
.file-table.grid .select-all-label { display: inline; font-size: 13px; font-weight: 600; color: var(--text); }
.file-table.grid tbody {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px;
}
.file-table.grid tbody tr {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.file-table.grid td { display: block; padding: 0; border: none; }
.file-table.grid .file-meta { display: none; }
.file-table.grid .col-select {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  width: auto;
}
.file-table.grid .file-name-cell { display: block; }
.file-table.grid .file-link { flex-direction: column; align-items: stretch; gap: 0; width: 100%; }
/* The parent folder card has its name without the text box around it. */
.file-table.grid .file-link > .file-name { padding: 8px 10px 10px; font-size: 13px; }
.file-table.grid .file-icon {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  background: var(--surface-2);
}
.file-table.grid .file-icon svg,
.file-table.grid .file-icon[data-kind="folder"] svg { width: 36%; height: 36%; }
.file-table.grid .file-icon.has-thumb img { width: 100%; height: 100%; border-radius: 0; }
.file-table.grid .file-text { padding: 8px 40px 10px 10px; }
.file-table.grid .file-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
}
.file-table.grid .file-sub { display: block; }
.file-table.grid .share-mark {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px;
  border-radius: 6px;
  background: var(--surface);
}
.file-table.grid td:last-child { position: absolute; right: 2px; bottom: 4px; }
.file-table.grid .btn-download { display: none; }

/* ── Pull to Refresh ───────────────────────────────── */
.pull-indicator {
  position: fixed;
  top: 12px;
  left: 50%;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  box-shadow: var(--shadow-lg);
  transform: translate(-50%, 0);
}
.pull-indicator.ready { color: var(--accent); }
.pull-indicator.spinning { color: var(--accent); animation: pull-spin 0.8s linear infinite; }

@keyframes pull-spin {
  from { transform: translate(-50%, 44px) rotate(0deg); }
  to { transform: translate(-50%, 44px) rotate(360deg); }
}

.share-native { margin-top: 12px; }
.share-qr-toggle { margin-top: 8px; }

/* Touch: holding a row selects it, so no text selection or link callout. */
@media (pointer: coarse) {
  .file-table tbody tr {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
  /* iOS zooms into any field under 16px when it is focused. */
  .form-input,
  .search-input { font-size: 16px; }
  /* The page's own pull reloads the folder instead. */
  html, body { overscroll-behavior-y: contain; }
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 640px) {
  .hide-mobile { display: none; }
  /* One row: the space switch, password, trash, links and logout are in
     the menu button, the usage in that menu's title. */
  .header-inner { padding: 8px 10px 8px 14px; flex-wrap: nowrap; }
  .header-left { min-width: 0; flex-wrap: nowrap; }
  .space-badge { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; display: block; line-height: 30px; }
  .header-right > .btn:not(.account-btn),
  .header-right .quota-box { display: none !important; }
  .account-btn { display: inline-flex; flex-shrink: 0; }
  .main-container { padding: 16px 14px 112px; gap: 12px; }
  .page-title { font-size: 24px; }
  .search-box { flex: 1 1 100%; }
  /* New folder and upload are in the floating button, refreshing is a pull. */
  .toolbar-actions { display: none; }
  /* Sorting is in the title row; the header only comes back for selecting. */
  body:not(.selecting) .file-table thead { display: none; }
  .select-all-label { display: inline; font-size: 13px; font-weight: 600; color: var(--text); }
  .file-table.grid tbody { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; padding: 8px; }
  .file-table.grid .file-text { padding: 6px 34px 8px 8px; }
  .file-table.grid .file-actions .btn-more { width: 32px; height: 32px; }
  .file-table th, .file-table td { padding-left: 10px; padding-right: 10px; }
  .file-table .col-select { width: 34px; padding-right: 0; }
  /* Checkboxes appear once a row is held (or picked from its menu). */
  body:not(.selecting) .file-table .col-select { display: none; }
  body.selecting .file-actions { visibility: hidden; }
  .file-sub { display: block; }
  .file-table .col-actions { width: auto; }
  .sort-btn { display: none; }
  .file-actions .btn-download { display: none; }
  .file-actions .btn-more { width: 40px; height: 40px; }
  .file-link { gap: 10px; }
  .toast-container { left: 12px; right: 12px; top: 12px; align-items: stretch; }
  .toast { max-width: none; }

  .selection-bar {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    max-width: none;
    transform: none;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 6px 6px 16px;
  }
  .selection-actions { gap: 4px; }
  .selection-bar .btn { padding: 0 11px; }
  .selection-bar .btn-clear { width: 38px; padding: 0; }

  .upload-panel {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    max-width: none;
  }
  body.selecting .upload-panel { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .upload-list { max-height: 40dvh; }

  .fab {
    position: fixed;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 65;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 58px;
    border: none;
    border-radius: 18px;
    background: var(--accent);
    color: var(--on-accent);
    box-shadow: var(--shadow-lg);
    cursor: pointer;
  }
  body.selecting .fab,
  body.has-uploads .fab { display: none; }

  .menu-backdrop { background: rgba(10, 12, 16, 0.4); }
  .context-menu {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    max-width: none;
    padding: 6px 8px calc(10px + env(safe-area-inset-bottom));
    border-radius: 20px 20px 0 0;
    border-width: 1px 0 0;
    animation: sheet-in 0.18s ease-out;
  }
  .menu-title {
    display: block;
    padding: 12px 12px 10px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .menu-item { height: 50px; font-size: 16px; }
  .menu-hint { display: none; }

  .viewer-stage { padding: 0 0 20px; }
  .viewer-nav { width: 40px; height: 40px; margin-top: -20px; background: rgba(0, 0, 0, 0.35); }
  .viewer-nav.prev { left: 8px; }
  .viewer-nav.next { right: 8px; }

  .modal-backdrop { align-items: flex-end; padding: 12px; }
  .modal-footer-choices { flex-direction: column-reverse; }
  .modal-footer-choices .btn { width: 100%; }
  .modal-footer-choices .footer-start { margin-right: 0; }
}

/* ── Share Dialog ──────────────────────────────────── */
.share-mark {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--accent);
}

.share-link-box { margin-top: 4px; }

.share-link-row {
  display: flex;
  gap: 8px;
}

.share-link-row .form-input {
  flex: 1;
  min-width: 0;
  font-size: 14px;
}

.share-link-row .btn { height: 46px; }

.share-note {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.share-qr-row {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.share-qr {
  flex-shrink: 0;
  width: 148px;
  height: 148px;
  border-radius: var(--radius);
  overflow: hidden;
  /* White in dark mode too: cameras need dark modules on light. */
  background: #fff;
  box-shadow: 0 0 0 1px var(--border);
}

.share-qr svg { display: block; width: 100%; height: 100%; }

.share-qr-side {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}

/* ── Share Link Page ───────────────────────────────── */
.share-kind {
  font-size: 13px;
  color: var(--muted);
}

.share-meta {
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.share-error {
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}

.share-preview {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.share-preview img,
.share-preview video {
  max-width: 100%;
  max-height: 70vh;
  border-radius: var(--radius-sm);
}

.share-preview audio { width: min(480px, 100%); }

.share-toolbar { justify-content: flex-end; margin-bottom: 12px; }

@media (max-width: 640px) {
  .share-page .file-actions .btn.share-row-download { display: inline-flex; }
  .share-download { width: 100%; }
  .share-toolbar .btn { width: 100%; }
}
