/* ============================================================
   App layout — shell, sidebar, header, pages, auth, responsive
   ============================================================ */

/* ---------- App shell ---------- */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; grid-template-rows: var(--header-h) 1fr; grid-template-areas: "sidebar header" "sidebar main"; height: 100vh; }

/* ---------- Header ---------- */
.app-header {
  grid-area: header; z-index: var(--z-header);
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-5); background: var(--surface); border-bottom: 1px solid var(--border);
}
.app-header .page-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.app-header .breadcrumb { font-size: var(--fs-xs); color: var(--text-muted); }
.header-menu-btn { display: none; }

/* ---------- Sidebar ---------- */
.app-sidebar {
  grid-area: sidebar; z-index: var(--z-sidebar);
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: var(--sp-3); height: var(--header-h); padding: 0 var(--sp-5); border-bottom: 1px solid var(--border); flex: none; }
.brand-logo { width: 34px; height: 34px; border-radius: 8px; background: var(--brand); display: flex; align-items: center; justify-content: center; color: #fff; flex: none; }
.brand-logo svg { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; overflow: hidden; }
.brand-name { font-weight: var(--fw-bold); font-size: var(--fs-md); letter-spacing: 0.2px; white-space: nowrap; }
.brand-sub { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; white-space: nowrap; }

.nav { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-3) var(--sp-3); }
.nav-section { font-size: 10px; font-weight: var(--fw-bold); letter-spacing: 1px; text-transform: uppercase; color: var(--text-muted); padding: var(--sp-4) var(--sp-3) var(--sp-2); }
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  height: 40px; padding: 0 var(--sp-3); margin-bottom: 2px;
  border-radius: var(--radius-sm); color: var(--text-secondary); font-weight: var(--fw-medium);
  cursor: pointer; border-left: 3px solid transparent; text-decoration: none;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item:hover { background: var(--neutral-bg); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--brand-subtle); color: var(--brand); font-weight: var(--fw-semibold); border-left-color: var(--brand); }
.nav-item .icon { width: 18px; height: 18px; flex: none; }
.nav-item .nav-label { flex: 1 1 auto; }
.nav-item .nav-badge { font-size: 10px; font-weight: var(--fw-bold); color: var(--brand); background: var(--surface); border: 1px solid var(--brand-border); border-radius: 999px; padding: 1px 7px; }

.sidebar-foot { flex: none; padding: var(--sp-3); border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2); border-radius: var(--radius-sm); }
.user-chip .meta { overflow: hidden; }
.user-chip .u-name { font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.user-chip .u-role { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- Main / content ---------- */
.app-main { grid-area: main; overflow-y: auto; background: var(--bg-app); }
.page { max-width: var(--content-max); margin: 0 auto; padding: var(--sp-6) var(--sp-6) var(--sp-12); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.page-head h1 { font-size: var(--fs-xl); }
.page-head .sub { color: var(--text-secondary); font-size: var(--fs-sm); margin-top: 2px; }

/* ---------- Stat tiles ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-6); }
.stat { display: flex; flex-direction: column; gap: var(--sp-1); padding: var(--sp-4) var(--sp-5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.stat .stat-label { font-size: var(--fs-xs); color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.stat .stat-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: var(--fs-2xl); font-weight: var(--fw-semibold); color: var(--text); }
.stat .stat-foot { font-size: var(--fs-xs); color: var(--text-muted); }
.stat .stat-icon { align-self: flex-end; margin-top: -34px; width: 30px; height: 30px; color: var(--brand-border); }

/* ---------- Toolbar (filters above tables) ---------- */
.toolbar { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.search { position: relative; flex: 1 1 240px; max-width: 360px; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-muted); }
.search .input { padding-left: 34px; }

/* ---------- Folder navigator ---------- */
.folder-nav { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.folder-nav-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; font-size: var(--fs-sm); min-width: 0; }
.crumb { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: var(--radius-sm); color: var(--text-secondary); cursor: pointer; border: none; background: transparent; font: inherit; }
.crumb:hover { background: var(--neutral-bg); color: var(--text); }
.crumb.current { color: var(--brand); font-weight: var(--fw-semibold); cursor: default; }
.crumb.current:hover { background: transparent; }
.crumb-sep { color: var(--text-muted); }
.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--sp-2); padding: var(--sp-4); }
.folder-card { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; text-align: left; font: inherit; color: var(--text); transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease); min-width: 0; }
.folder-card:hover { border-color: var(--brand); background: var(--brand-subtle); }
.folder-card > .icon { width: 20px; height: 20px; color: var(--brand); flex: none; }
.folder-card .fname { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-menu { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0; border: none; background: transparent; color: var(--text-muted); border-radius: var(--radius-sm); cursor: pointer; }
.folder-menu:hover { background: var(--surface); color: var(--text); }
.folder-menu .icon { width: 16px; height: 16px; }
.folder-card.selected { border-color: var(--brand); background: var(--brand-subtle); box-shadow: inset 0 0 0 1px var(--brand); }
.ffile.selected { background: var(--brand-subtle); }
.sel-check { flex: none; width: 16px; height: 16px; cursor: pointer; accent-color: var(--brand); margin: 0; }
.folder-card .sel-check, .ffile .sel-check { margin-right: 2px; }

/* Selection action bar (library multi-select) */
.sel-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-2) var(--sp-4); background: var(--brand-subtle); border-bottom: 1px solid var(--border); }
.sel-bar .sel-count { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text); }
.sel-bar .sel-count .icon { width: 16px; height: 16px; color: var(--brand); }
.sel-bar .sel-count b { color: var(--brand); }

.folder-empty { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); padding: var(--sp-6); text-align: center; color: var(--text-muted); font-size: var(--fs-sm); }
.folder-empty .icon { width: 34px; height: 34px; color: var(--border-strong); }

/* files inside the current folder (upload navigator) */
.folder-files { display: flex; flex-direction: column; border-top: 1px solid var(--border); }
.ffile { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); border-bottom: 1px solid var(--border); }
.ffile:last-child { border-bottom: none; }
.ffile-info { flex: 1 1 auto; min-width: 0; }
.ffile-info .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.dest-bar { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); background: var(--brand-subtle); font-size: var(--fs-sm); }
.dest-bar .icon { width: 16px; height: 16px; color: var(--brand); }
.dest-bar b { color: var(--brand); }

/* ---------- Uploader (dropzone) ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-3);
  padding: var(--sp-10) var(--sp-6); text-align: center;
  background: var(--surface); border: 2px dashed var(--border-strong); border-radius: var(--radius-lg);
  cursor: pointer; transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.dropzone:hover { border-color: var(--brand); background: var(--brand-subtle); }
.dropzone.dragover { border-color: var(--brand); background: var(--brand-subtle); box-shadow: inset 0 0 0 3px var(--brand-subtle); }
.dropzone .dz-icon { width: 46px; height: 46px; color: var(--brand); }
.dropzone .dz-title { font-weight: var(--fw-semibold); font-size: var(--fs-md); }
.dropzone .dz-sub { font-size: var(--fs-sm); color: var(--text-secondary); }

/* Stated upload limits, under the dropzone */
.up-limits {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  margin-top: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  background: var(--brand-subtle); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: var(--fs-sm);
}
.up-limits > .icon { width: 18px; height: 18px; flex: none; color: var(--brand); margin-top: 1px; }
.up-limits-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.up-limits-row .sep { color: var(--text-muted); }
.up-limits b { font-family: var(--font-mono); color: var(--brand); }
.up-limits .hint { margin-top: 2px; }

.file-list { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-4); }
.file-path { display: flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--brand); margin-top: 1px; }
.file-path .icon { width: 12px; height: 12px; flex: none; }

/* Upload: destination picker hint + chosen-destination path bar */
.pick-hint {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  margin-bottom: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  background: var(--brand-subtle); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: var(--fs-sm); color: var(--text-secondary);
}
.pick-hint > .icon { width: 18px; height: 18px; flex: none; color: var(--brand); margin-top: 1px; }
.dest-path {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2);
  margin-bottom: var(--sp-4); padding: var(--sp-3) var(--sp-4);
  background: var(--brand-subtle); border: 1px solid var(--border); border-radius: var(--radius);
}
.dest-path > .icon { width: 18px; height: 18px; flex: none; color: var(--brand); }
.dest-path-label { color: var(--text-secondary); font-size: var(--fs-sm); }
.dest-path-crumbs { display: flex; align-items: center; gap: 6px; font-weight: var(--fw-semibold); color: var(--brand); min-width: 0; flex-wrap: wrap; }
.dest-path-crumbs .crumb-sep { color: var(--text-muted); font-weight: 400; }
.dest-path #changeDest { margin-left: auto; }

/* Connection page — setup steps */
.conn-steps summary { cursor: pointer; font-weight: var(--fw-medium); color: var(--text-secondary); }
.conn-steps ol { margin: var(--sp-3) 0 0; padding-left: 1.25rem; display: flex; flex-direction: column; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-secondary); }
textarea.mono { font-family: var(--font-mono); font-size: var(--fs-xs); line-height: 1.5; }
.file-row { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.file-thumb { width: 40px; height: 40px; border-radius: var(--radius-sm); background: var(--brand-subtle); color: var(--brand); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-thumb .icon { width: 20px; height: 20px; }
.file-info { min-width: 0; }
.file-name { font-weight: var(--fw-medium); font-size: var(--fs-sm); }
.file-meta { font-size: var(--fs-xs); color: var(--text-muted); display: flex; gap: var(--sp-2); align-items: center; }
.file-progress { margin-top: 6px; display: flex; align-items: center; gap: var(--sp-3); }
.file-progress .progress { flex: 1; }
.file-progress .pct { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-secondary); min-width: 38px; text-align: right; }
.file-actions { display: flex; gap: var(--sp-1); }

/* ---------- Auth screen ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 0.9fr; }
.auth-hero { background: linear-gradient(160deg, #0A4F8F 0%, #0A6ED1 100%); color: #fff; display: flex; flex-direction: column; justify-content: space-between; padding: var(--sp-12); position: relative; overflow: hidden; }
.auth-hero::after { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px); background-size: 28px 28px; opacity: .6; }
.auth-hero .brand { border: none; background: transparent; padding: 0; height: auto; }
.auth-hero .brand-logo { background: rgba(255,255,255,.16); }
.auth-hero .brand-name, .auth-hero .brand-sub { color: #fff; }
.auth-hero-body { position: relative; z-index: 1; max-width: 420px; }
.auth-hero-body h2 { font-size: 30px; line-height: 1.25; margin-bottom: var(--sp-3); }
.auth-hero-body p { color: rgba(255,255,255,.82); font-size: var(--fs-md); }
.auth-features { position: relative; z-index: 1; display: flex; flex-direction: column; gap: var(--sp-3); }
.auth-feature { display: flex; align-items: center; gap: var(--sp-3); font-size: var(--fs-sm); color: rgba(255,255,255,.9); }
.auth-feature .icon { width: 18px; height: 18px; opacity: .9; }

.auth-panel { display: flex; align-items: center; justify-content: center; padding: var(--sp-8); background: var(--surface); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: var(--fs-2xl); margin-bottom: var(--sp-1); }
.auth-card .auth-desc { color: var(--text-secondary); margin-bottom: var(--sp-6); font-size: var(--fs-sm); }
.auth-form { display: flex; flex-direction: column; gap: var(--sp-4); }
.auth-error { display: none; align-items: center; gap: var(--sp-2); padding: var(--sp-3); background: var(--negative-bg); color: var(--negative); border: 1px solid #EFBCBC; border-radius: var(--radius-sm); font-size: var(--fs-sm); }
.hide-sm { display: inline; }
.auth-error.show { display: flex; }
.auth-foot { margin-top: var(--sp-6); font-size: var(--fs-xs); color: var(--text-muted); text-align: center; }
.lang-switch-auth { position: absolute; top: var(--sp-5); right: var(--sp-5); z-index: 2; }

/* ---------- Language switch ---------- */
.lang-switch { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.lang-switch button { height: 30px; padding: 0 10px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); background: var(--surface); color: var(--text-secondary); border: none; cursor: pointer; }
.lang-switch button.active { background: var(--brand); color: #fff; }

/* ---------- Dropdown menu ---------- */
.menu { position: absolute; min-width: 200px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: var(--sp-1); z-index: var(--z-overlay); }
.menu-item { display: flex; align-items: center; gap: var(--sp-3); height: 36px; padding: 0 var(--sp-3); border-radius: var(--radius-sm); font-size: var(--fs-sm); color: var(--text); cursor: pointer; }
.menu-item:hover { background: var(--neutral-bg); }
.menu-item.danger { color: var(--negative); }
.menu-item .icon { width: 16px; height: 16px; }
.menu-sep { height: 1px; background: var(--border); margin: var(--sp-1) 0; }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-top: var(--sp-4); flex-wrap: wrap; }
.pager .info { font-size: var(--fs-sm); color: var(--text-secondary); }
.pager .controls { display: flex; gap: var(--sp-1); align-items: center; }

/* ---------- Mobile overlay ---------- */
.scrim { position: fixed; inset: 0; background: rgba(27,41,61,.4); z-index: var(--z-overlay); display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 1fr; grid-template-areas: "header" "main"; }
  .app-sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w); transform: translateX(-100%); transition: transform var(--dur) var(--ease); box-shadow: var(--shadow-lg); }
  .app-shell.nav-open .app-sidebar { transform: none; }
  .app-shell.nav-open .scrim { display: block; }
  .header-menu-btn { display: inline-flex; }
}
@media (max-width: 720px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .page { padding: var(--sp-4) var(--sp-4) var(--sp-10); }
  .page-head { align-items: flex-start; }
  .modal { max-width: 100%; }
  .table thead { display: none; }
  .table.responsive tbody td { display: flex; justify-content: space-between; gap: var(--sp-4); padding: var(--sp-2) var(--sp-4); border: none; }
  .table.responsive tbody td::before { content: attr(data-label); font-weight: var(--fw-semibold); color: var(--text-secondary); }
  .table.responsive tbody tr { display: block; padding: var(--sp-2) 0; border-bottom: 1px solid var(--border); }
  .table.responsive .col-actions { justify-content: flex-end; }
  .hide-sm { display: none; }
}
