:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-alt: #fafbfc;
  --border: #e4e6eb;
  --border-strong: #d1d5db;
  --text: #14161a;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eef2ff;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 20, 30, 0.05);
  --shadow-md: 0 1px 3px rgba(16, 20, 30, 0.06), 0 10px 24px -8px rgba(16, 20, 30, 0.10);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0e11;
    --panel: #17191e;
    --panel-alt: #1c1f25;
    --border: #292c33;
    --border-strong: #383c45;
    --text: #eef0f3;
    --muted: #9aa0ac;
    --accent: #5b8cf7;
    --accent-hover: #7ba0f9;
    --accent-soft: #1b2436;
    --accent-contrast: #0d0e11;
    --danger: #f87171;
    --danger-soft: #241616;
    --success: #4ade80;
    --success-soft: #142118;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.4), 0 12px 28px -8px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app { max-width: 1040px; margin: 0 auto; padding: 0 24px 72px; }

/* --- Header / brand --- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px 0;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(155deg, var(--accent), var(--accent-hover));
  box-shadow: var(--shadow-sm);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 9px;
  background: var(--accent-contrast);
  -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' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20V10l8-5 8 5v10'/%3E%3Cpath d='M9 20v-7h6v7'/%3E%3C/svg%3E") center / contain no-repeat;
  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' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20V10l8-5 8 5v10'/%3E%3Cpath d='M9 20v-7h6v7'/%3E%3C/svg%3E") center / contain no-repeat;
  opacity: 0.92;
}
.brand-mark-lg { width: 52px; height: 52px; border-radius: 14px; margin-bottom: 18px; }
.brand-mark-lg::after { inset: 13px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
h1 { font-size: 1.05rem; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.78rem; color: var(--muted); }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 6px; }

#user-bar { display: flex; gap: 12px; align-items: center; }
#user-email { color: var(--muted); font-size: 0.85rem; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700; flex: none;
}

/* --- Buttons --- */
button {
  cursor: pointer;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; border-color: var(--border); color: var(--muted); transform: none; }

button.primary {
  background: var(--accent); color: var(--accent-contrast); border-color: var(--accent);
  box-shadow: var(--shadow-sm);
  padding: 10px 18px;
  font-weight: 600;
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }

#logout-btn {
  padding: 6px 12px;
  font-size: 0.78rem;
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}
#logout-btn:hover { color: var(--danger); border-color: var(--border); }

/* --- Login screen --- */
#login-view { display: flex; justify-content: center; padding: 64px 0; }
.login-card {
  display: flex; flex-direction: column; align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 36px 40px;
  max-width: 340px;
}
.login-sub { color: var(--muted); font-size: 0.88rem; margin: 0 0 20px; }

/* --- Tabs --- */
#tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab-btn {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  padding: 10px 4px;
  margin-right: 22px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* --- Panel head (Share links tab) --- */
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; }
.panel-head-actions { display: flex; gap: 8px; align-items: center; }

select {
  padding: 8px 10px;
  font: inherit;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
}
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- Browser panel --- */
.browser {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.breadcrumbs {
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
}
.breadcrumbs a { cursor: pointer; color: var(--accent); text-decoration: none; font-weight: 500; }
.breadcrumbs a:hover { text-decoration: underline; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.select-all {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0 4px;
  cursor: pointer;
}
.select-all:has(.entry-check:disabled) { opacity: 0.5; cursor: default; }

ul.entries { list-style: none; margin: 0; padding: 0; }
ul.entries li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
}
ul.entries li + li { margin-top: 1px; }
ul.entries li:hover { background: var(--panel-alt); }
ul.entries li:hover .entry-actions { opacity: 1; }

.entry-main { display: flex; align-items: center; gap: 8px; min-width: 0; cursor: default; }
.entry-check { flex: none; width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.entry-name { cursor: pointer; font-size: 0.88rem; display: flex; align-items: center; gap: 9px; }
.entry-name::before { content: ""; width: 17px; height: 17px; flex: none; background: var(--muted); opacity: 0.75; }
.entry-name.folder::before {
  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' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z'/%3E%3C/svg%3E") center / contain no-repeat;
  -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' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z'/%3E%3C/svg%3E") center / contain no-repeat;
  background: var(--accent); opacity: 0.85;
}
.entry-name.file::before {
  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' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 2h9l5 5v15H6Z'/%3E%3Cpath d='M14 2v6h6'/%3E%3C/svg%3E") center / contain no-repeat;
  -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' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 2h9l5 5v15H6Z'/%3E%3Cpath d='M14 2v6h6'/%3E%3C/svg%3E") center / contain no-repeat;
}
span.entry-name:not(.folder) { cursor: default; }

.entry-actions { display: flex; gap: 6px; opacity: 0.55; transition: opacity 0.12s ease; }
.entry-actions button { padding: 5px 10px; font-size: 0.76rem; }

.browser > .loading, .browser > .empty-state {
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
  padding: 40px 0;
  margin: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}

/* --- Spinner --- */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Badges --- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--panel-alt); color: var(--muted); border: 1px solid var(--border); }

/* --- Share links table --- */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; background: var(--panel-alt); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--panel-alt); }
table button { padding: 5px 10px; font-size: 0.78rem; }
td a { color: var(--accent); font-weight: 500; }
.link-cell { display: flex; align-items: center; gap: 8px; }

/* --- Toast --- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 11px 20px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  box-shadow: var(--shadow-md);
}

dialog {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 24px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-md);
  width: min(360px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(10, 12, 16, 0.5); backdrop-filter: blur(1px); }
dialog h2 { margin: 0 0 16px; }
dialog form { display: flex; flex-direction: column; gap: 14px; max-width: none; }
#form-dialog-fields { display: flex; flex-direction: column; gap: 14px; }
#form-dialog-fields label { display: flex; flex-direction: column; gap: 5px; font-size: 0.85rem; color: var(--muted); }
#form-dialog-fields input { width: 100%; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.link-dialog-row { display: flex; gap: 8px; margin-bottom: 4px; }
.link-dialog-row input { flex: 1; min-width: 0; font-size: 0.82rem; color: var(--muted); }

#picker-dialog { width: min(420px, calc(100vw - 32px)); }
.picker-list-wrap {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  background: var(--panel-alt);
}
.picker-list-wrap .entries { padding: 4px; }
.picker-list-wrap ul.entries li { padding: 0; border-radius: var(--radius-sm); }
.picker-list-wrap .entry-name { padding: 9px 10px; width: 100%; }
.picker-empty { padding: 24px; text-align: center; color: var(--muted); font-size: 0.85rem; }

@media (max-width: 480px) {
  #app { padding: 0 16px 56px; }
  header { padding: 16px 0; flex-wrap: wrap; gap: 12px; }
  .login-card { padding: 28px 24px; }
  #tabs { overflow-x: auto; }
  .toolbar { flex-direction: column; align-items: stretch; }
  ul.entries li { flex-direction: column; align-items: flex-start; gap: 8px; }
  .entry-actions { opacity: 1; }
  .panel-head { flex-wrap: wrap; gap: 10px; }
}
