.drive { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: calc(100vh - var(--header-h)); }
.drive-details { display: none; }
@media (min-width: 1100px) {
  .drive.with-details { grid-template-columns: 250px minmax(0, 1fr) 310px; }
  .drive.with-details .drive-details { display: block; }
}
.drive-side { border-right: 1px solid var(--border); background: var(--surface); padding: 18px 14px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); overflow-y: auto; }
.drive-side .new { margin-bottom: 16px; width: 100%; height: 44px; font-size: 14.5px; border-radius: 12px; box-shadow: 0 1px 2px rgba(16,24,40,.08), 0 4px 12px -4px color-mix(in srgb, var(--accent) 45%, transparent); }
.drive-nav { display: flex; flex-direction: column; gap: 2px; }
.drive-side .navi { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; color: var(--text-2); font-weight: 500; border: 0; background: none; font: inherit; cursor: pointer; text-align: left; width: 100%; }
.drive-side .navi:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.drive-side .navi.on { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.drive-side .navi.drop { background: var(--accent-soft); outline: 2px dashed var(--accent); }
.side-tools { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.side-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 0 12px 6px; }
.drive-side .meter { margin-top: auto; }
.meter { margin-top: auto; padding: 14px 12px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg); }
.meter .bar { height: 7px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin: 8px 0; }
.meter .bar div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.meter.warning .bar div { background: var(--warning); }
.meter.full .bar div { background: var(--danger); }
.meter small { color: var(--muted); display: block; }
.meter .btn { width: 100%; margin-top: 10px; }
.drive-main { padding: 22px 26px 60px; min-width: 0; position: relative; }
.drive-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.drive-top .crumbs { flex: 1; margin: 0; font-size: 18px; font-weight: 600; color: var(--text); gap: 4px; min-width: 0; flex-wrap: wrap; }
.drive-top .crumbs button { font-size: 18px; font-weight: 600; color: var(--muted); }
.drive-top .crumbs button:last-child { color: var(--text); }
.drive-top .search { width: 280px; }
.drive-list { overflow: auto; }
.drive-viewbar { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; flex-wrap: wrap; }
.drive-viewbar .grow { flex: 1; }
.upload-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.drive-viewbar .details-btn.active { background: var(--accent-soft); color: var(--accent-text); }
@media (max-width: 1099px) { .drive-viewbar .details-btn { display: none; } }
.drive-viewbar .sort-btn { height: 34px; padding: 0 10px; color: var(--text-2); font-weight: 500; gap: 6px; }
.drive-viewbar .select-btn { height: 34px; padding: 0 10px; color: var(--text-2); font-weight: 500; gap: 6px; }
.drive-viewbar .select-btn.active { color: var(--accent-text); }
.layout-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); padding: 2px; background: var(--surface-2); }
.layout-toggle button { width: 34px; height: 28px; border: 0; background: none; border-radius: 6px; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.layout-toggle button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.ftable th .th-sort { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.ftable th .th-sort:hover, .ftable th .th-sort.on { color: var(--text); }
.ftable th.ck, .ftable td.ck { width: 1%; padding-right: 0; }
.ftable .ck input { display: block; margin: 0; cursor: pointer; }
/* Checkboxes stay out of the way with a mouse until you hover or select */
@media (pointer: fine) {
  .drive-list:not(.has-sel):not(.selecting) .ftable tr.item:not(:hover) td.ck input,
  .drive-list:not(.has-sel):not(.selecting) .ftable th.ck input { opacity: 0; }
  .drive-list:not(.has-sel):not(.selecting) .gitem:not(:hover) .selbox { opacity: 0; }
}
.ftable .nm-text { display: flex; flex-direction: column; min-width: 0; }
.ftable .nm-text .sub { display: none; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctx-title { padding: 8px 10px 10px; font-weight: 600; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.i.blank { background: none; }
.picker-top { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.picker-top .picker-crumbs { flex: 1; margin: 0; min-width: 0; }
.picker-top .picker-new { flex: none; height: 32px; padding: 0 10px; color: var(--accent-text); }

/* Grid view */
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; padding: 14px; }
.gitem { position: relative; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; cursor: default; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; transition: border-color .12s, box-shadow .12s; }
.gitem:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.gitem.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.gitem.drop { border-color: var(--accent); background: var(--accent-soft); }
.gthumb { aspect-ratio: 4 / 3; display: grid; place-items: center; background: var(--surface-2); border-bottom: 1px solid var(--border); overflow: hidden; position: relative; }
.gthumb .ficon { width: 56px; height: 56px; border-radius: 12px; }
.gthumb.has-img { background: var(--canvas-bg); place-items: start center; padding-top: 10px; }
.gthumb img { max-width: 82%; max-height: 100%; object-fit: contain; object-position: top; background: #fff; box-shadow: 0 1px 3px rgba(16,24,40,.18); border-radius: 2px; pointer-events: none; }
.gbadge { position: absolute; left: 8px; bottom: 8px; font-size: 10px; font-weight: 700; letter-spacing: .04em; color: #fff; background: #d92d20; border-radius: 4px; padding: 1px 5px; }
.gitem .selbox { position: absolute; top: 8px; left: 8px; margin: 0; width: 20px; height: 20px; cursor: pointer; }
.gmeta { padding: 9px 40px 10px 12px; min-width: 0; }
.gname { display: flex; align-items: center; gap: 6px; font-weight: 500; min-width: 0; }
.gname .i { color: #b45309; }
.gname .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gmeta .sub { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gitem .more { position: absolute; right: 4px; bottom: 6px; }
.ftable { width: 100%; border-collapse: collapse; }
.ftable th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.ftable td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ftable tr.item { cursor: default; }
.ftable tr.item:hover td { background: var(--surface-2); }
.ftable tr.item.drop td { background: var(--accent-soft); }
.ftable .nm { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ftable .nm span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.ftable .nm .sys { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 99px; padding: 0 7px; }
.ftable td.act { width: 1%; white-space: nowrap; text-align: right; }
.ftable td.meta { color: var(--muted); white-space: nowrap; font-size: 13px; }
.dropping::after { content: 'Drop files to upload'; position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 14px; background: color-mix(in srgb, var(--accent-soft) 85%, transparent);
  display: grid; place-items: center; font-size: 18px; font-weight: 600; color: var(--accent-text); z-index: 5; pointer-events: none; }
.uploads { position: fixed; right: 20px; bottom: 20px; width: 320px; z-index: 80; }
.uploads .card { padding: 12px 14px; }
.uploads .u { display: flex; gap: 10px; align-items: center; font-size: 13px; margin-top: 8px; }
.uploads .u .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads .u progress { width: 80px; accent-color: var(--accent); }
.ctx { position: fixed; z-index: 95; min-width: 220px; max-height: calc(100dvh - 16px); overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 6px; }
.ctx button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 6px; color: var(--text-2); font: inherit; text-align: left; cursor: pointer; }
.ctx button:hover { background: var(--surface-2); color: var(--text); }
.ctx button.danger { color: var(--danger); }
.ctx hr { border: 0; border-top: 1px solid var(--border); margin: 5px 0; }
.ctx .sub { display: none; }
.preview-pages { display: flex; flex-direction: column; gap: 12px; align-items: center; background: var(--canvas-bg); padding: 14px; border-radius: var(--radius); max-height: 70vh; overflow: auto; }
.preview-pages canvas, .preview-pages img { max-width: 100%; height: auto; background: #fff; box-shadow: var(--shadow); }
.plan { display: grid; gap: 14px; }
.plan .big { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.plan .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.stepper button { width: 38px; height: 38px; border: 0; background: var(--surface); color: var(--text); cursor: pointer; display: grid; place-items: center; }
.stepper button:hover { background: var(--surface-2); }
.stepper output { min-width: 64px; text-align: center; font-weight: 600; }
.drive-mobile-bar { display: none; }

@media (max-width: 860px) {
  .drive { grid-template-columns: 1fr; min-height: 0; }
  .drive-side { display: none; }
  .drive-main { padding: 12px 12px 96px; }
  .drive-mobile-bar { display: flex; gap: 6px; overflow-x: auto; margin: 0 -12px 12px; padding: 0 12px; scrollbar-width: none; }
  .drive-mobile-bar::-webkit-scrollbar { display: none; }
  .drive-mobile-bar .btn { flex: none; border-radius: 99px; }
  .drive-top { gap: 10px; margin-bottom: 10px; }
  .drive-top .crumbs, .drive-top .crumbs button { font-size: 17px; }
  .drive-top .search { width: 100%; }
  .drive-viewbar { margin: 0 0 8px; }
  .upload-btns, .drive-viewbar .grow { display: none; }
  .drive-viewbar .layout-toggle { margin-left: auto; }
  .drive-list { border-radius: var(--radius-lg); }
  .ftable td { padding: 10px 8px; }
  .ftable td.ck { padding-left: 12px; }
  .ftable .nm { gap: 12px; }
  .ftable .nm .ficon { width: 38px; height: 38px; border-radius: 9px; }

  .fgrid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 10px; }
  .fab { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); width: 56px; height: 56px; border-radius: 18px; z-index: 70; box-shadow: var(--shadow-lg); }
  body.drive-selecting .fab { display: none; }
  .uploads { left: 12px; right: 12px; width: auto; bottom: calc(var(--tabbar-h) + var(--safe-b) + 84px); }
  /* Menus become action sheets */
  .ctx { left: 0 !important; right: 0; top: auto !important; bottom: 0; max-height: 80dvh; border-radius: 16px 16px 0 0; padding: 6px 10px max(12px, var(--safe-b));
    box-shadow: 0 0 0 100vmax rgba(16, 24, 40, .45); animation: sheet-up .22s cubic-bezier(.2,.8,.2,1); z-index: 960; }
  .ctx::before { content: ''; display: block; width: 38px; height: 5px; border-radius: 5px; background: var(--border-strong); margin: 4px auto 8px; }
  .ctx button { min-height: 48px; font-size: 15px; gap: 14px; padding: 10px 12px; }
  .ctx-title { font-size: 14px; padding: 4px 12px 10px; }
}
@media (max-width: 420px) { .fgrid { grid-template-columns: 1fr 1fr; } .gmeta { padding: 8px 36px 9px 10px; } }
@media (min-width: 861px) { .fab { display: none; } }

/* Selection and drag and drop */
.ftable tr.item.sel td { background: var(--accent-soft); }
.ftable tr.item.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.crumbs .linkish.drop { background: var(--accent-soft); outline: 2px dashed var(--accent); outline-offset: 2px; border-radius: 6px; }
.selbar { position: fixed; z-index: 75; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); width: min(720px, calc(100% - 24px));
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); animation: pop .18s ease; }
.selbar:empty { display: none; }
.selbar b { font-size: 14px; white-space: nowrap; }
.selbar .grow { flex: 1; }
.selbar .btn { height: 36px; }
@media (min-width: 861px) { .drive-main .selbar { left: calc(50% + 125px); } }
@media (max-width: 600px) {
  .selbar { width: auto; left: 8px; right: 8px; transform: none; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); padding: 6px; gap: 2px; }
  .selbar .lbl { display: none; }
  .selbar .btn:not(.selall) { width: 44px; padding: 0; }
  .selbar .selall { padding: 0 8px; }
}
.drag-ghost { position: fixed; top: -100px; left: -100px; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font: 600 13px Inter, system-ui, sans-serif; }

/* File type colors */
.ficon.t-img { background: #fce7f6; color: #c11574; }
.ficon.t-doc { background: #dbeafe; color: #1d4ed8; }
.ficon.t-sheet { background: #e0e7ff; color: #4e5ba6; }
.ficon.t-slide { background: #ffedd5; color: #c4320a; }
.ficon.t-zip { background: var(--surface-3); color: var(--text-2); }
.ficon.t-txt { background: var(--accent-soft); color: var(--accent-text); }
:root[data-theme="dark"] .ficon.t-img, :root[data-theme="dark"] .ficon.t-doc, :root[data-theme="dark"] .ficon.t-sheet, :root[data-theme="dark"] .ficon.t-slide, :root[data-theme="dark"] .ficon.folder, :root[data-theme="dark"] .ficon.pdf { background: var(--surface-3); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .ficon:is(.t-img, .t-doc, .t-sheet, .t-slide, .folder, .pdf) { background: var(--surface-3); } }

/* Rows: calmer hover, clear selection */
.ftable tr.item td { transition: background .1s; }
.ftable tbody tr:last-child td { border-bottom: 0; }
.drive-list { border-radius: 14px; }
.ftable th { background: var(--surface); position: sticky; top: 0; z-index: 1; }

/* Empty states */
.drive-empty { padding: 56px 20px 64px; }
.drive-empty .empty-art { margin: 0 auto 8px; width: 180px; }
.drive-empty h3 { color: var(--text); font-size: 17px; margin-bottom: 6px; }
.drive-empty p { max-width: 380px; margin: 0 auto 18px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* Details panel */
.drive-details { border-left: 1px solid var(--border); background: var(--surface); padding: 16px 18px 40px; position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); overflow-y: auto; }
.dt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.dt-head b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dt-preview { aspect-ratio: 4 / 3; border-radius: 12px; background: var(--canvas-bg); display: grid; place-items: center; overflow: hidden; margin-bottom: 14px; border: 1px solid var(--border); }
.dt-preview img { max-width: 78%; max-height: 92%; object-fit: contain; background: #fff; box-shadow: 0 2px 8px rgba(16,24,40,.18); }
.dt-preview .ficon { width: 64px; height: 64px; border-radius: 16px; }
.dt-name { font-size: 16px; word-break: break-word; margin-bottom: 12px; }
.dt-props { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0 0 18px; font-size: 13px; }
.dt-props dt { color: var(--muted); }
.dt-props dd { margin: 0; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.dt-props .linkish { display: inline-flex; align-items: center; gap: 4px; padding: 0; }
.dt-share.on { color: var(--accent-text); display: inline-flex; align-items: center; gap: 5px; font-weight: 500; flex-wrap: wrap; }
.dt-actions { display: grid; gap: 6px; }
.dt-actions .btn { justify-content: flex-start; width: 100%; }
.dt-summary { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.dt-summary .dt-props { flex: 1; margin: 0; }
.dt-big { width: 56px; height: 56px; border-radius: 14px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; flex: none; }
.dt-hint { color: var(--muted); font-size: 13px; background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; }
.dt-keys { margin-top: 22px; display: grid; gap: 7px; font-size: 12.5px; color: var(--text-2); }
.dt-keys .side-label { padding: 0 0 2px; }
.dt-keys > div:not(.side-label) { display: flex; gap: 10px; align-items: center; }
kbd { font: 600 11px var(--font); background: var(--surface-2); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; min-width: 64px; text-align: center; color: var(--text-2); }
.modal .dt-body .dt-actions { grid-template-columns: 1fr 1fr; }
@media (pointer: coarse) { .dt-keys { display: none; } .upload-btns .folder-up { display: none; } }

/* Drag and drop visuals */
.ftable tr.item.drop td { background: var(--accent-soft); box-shadow: inset 0 0 0 9999px color-mix(in srgb, var(--accent) 6%, transparent); }
.ftable tr.item.drop td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.dropping::after { animation: fade .12s; }
tr.item[draggable="true"], .gitem[draggable="true"] { cursor: grab; }
.ftable td:has(> .nm) { max-width: 0; width: 100%; }
.ftable .nm .ficon { flex: none; }
@media (min-width: 1100px) { .drive.with-details .drive-main .selbar { left: calc(50% - 30px); width: min(640px, calc(100% - 600px)); } }
.modal .dt-preview { aspect-ratio: auto; height: 180px; }

@media (max-width: 600px) {
  .ftable thead { display: none; }
  .ftable th.opt, .ftable td.opt { display: none; }
  .ftable .nm-text .sub { display: block; }
}
/* Landscape phones: keep the list visible */
@media (pointer: coarse) and (max-height: 520px) {
  .drive-top { flex-wrap: nowrap; }
  .drive-top .search { width: min(380px, 55%); }
  .drive-mobile-bar { margin-bottom: 8px; }
  .drive-mobile-bar .btn { min-height: 38px; height: 38px; }
}
/* Selection must stand out from hover with a neutral brand */
.ftable tr.item.sel td { background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }

.share-dlg { display: grid; gap: 12px; }
.share-dlg .field { margin: 0; }
.share-dlg .check { align-items: flex-start; line-height: 1.45; }
.share-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.share-row { display: flex; gap: 8px; flex-wrap: wrap; }
.share-seo { display: grid; gap: 10px; padding-top: 10px; border-top: 1px solid var(--border); }

/* Details panel open on mid widths: keep the toolbar on one line */
@media (min-width: 1100px) and (max-width: 1499px) {
  .drive.with-details { grid-template-columns: 220px minmax(0, 1fr) 280px; }
  .drive.with-details .drive-main { padding-left: 20px; padding-right: 20px; }
  .drive.with-details .upload-btns .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .drive.with-details .upload-btns .btn:not(.primary) { width: 36px; padding: 0; }
  .drive.with-details .drive-top .search { width: 220px; }
}
@media (pointer: coarse) { .layout-toggle button { width: 42px; height: 38px; } }
