/* App layout on top of theme.css tokens. Mobile first; sidebar becomes a drawer below 900px,
   the table becomes cards below 640px. */
.app-body { padding: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
a { color: var(--primary-text); }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex: none; background: var(--sidebar); border-right: .5px solid var(--sidebar-border); display: flex; flex-direction: column; justify-content: space-between; padding: 12px 8px calc(12px + var(--sab)); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 12px; border: 0; background: none; border-radius: var(--radius); color: var(--sidebar-foreground); text-decoration: none; cursor: pointer; text-align: left; font-size: 14px; }
.nav-item:hover { background: var(--sidebar-accent); }
.nav-item.active { background: var(--sidebar-accent); color: var(--primary-text); font-weight: 600; }
.nav-ic { width: 18px; text-align: center; color: var(--text-tertiary); font-size: 13px; }
.nav-item.active .nav-ic { color: var(--primary-text); }
.nav-sep { height: .5px; background: var(--sidebar-border); margin: 8px 6px; }
.meter { padding: 12px; font-size: 13px; color: var(--text-secondary); }
.meter-bar { height: 6px; border-radius: 3px; background: var(--muted); overflow: hidden; margin-bottom: 6px; }
.meter-bar span { display: block; height: 100%; width: 0; background: var(--primary); transition: width .3s; }
.meter-bar span.warn { background: var(--destructive); }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 20px calc(24px + var(--sab)); }
.top { display: flex; align-items: center; gap: 10px; padding: 12px 0; position: sticky; top: 0; background: var(--background); z-index: 10; }
.search { flex: 1; min-width: 0; }
.search .input { font-size: 16px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.who { font-size: 13px; color: var(--text-secondary); white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.who b { color: var(--text-heading); font-weight: 600; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 40px; border: 0; background: none; border-radius: var(--radius); color: var(--text-secondary); cursor: pointer; font-size: 16px; }
.icon-btn:hover { background: var(--muted); color: var(--text-heading); }
.btn { white-space: nowrap; transition: transform .1s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-danger { background: var(--destructive); color: var(--destructive-foreground); border-color: transparent; }
.btn-ghost { background: none; border-color: transparent; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.only-sm { display: none; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 4px 0 10px; }
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 16px; font-weight: 600; color: var(--text-heading); min-width: 0; }
.crumbs button { border: 0; background: none; padding: 4px 6px; border-radius: 6px; cursor: pointer; color: var(--text-secondary); font-weight: 500; }
.crumbs button:hover { background: var(--muted); }
.crumbs .sep { color: var(--text-tertiary); }
.tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sel { width: auto; min-height: 36px; padding: 4px 8px; font-size: 16px; max-width: 170px; }
.seg { display: inline-flex; border: .5px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg-btn { border: 0; background: var(--card); min-width: 36px; height: 34px; cursor: pointer; color: var(--text-secondary); }
.seg-btn.on { background: var(--primary); color: var(--primary-foreground); }

.bulkbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 10px; background: var(--card); border: .5px solid var(--primary); border-radius: var(--radius); font-size: 14px; }
.bulkbar .count { font-weight: 600; margin-right: auto; color: var(--text-heading); }

.content { flex: 1; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card); border: .5px solid var(--border); border-radius: var(--radius); overflow: hidden; font-size: 14px; }
.table th { text-align: left; font-weight: 500; font-size: 12px; color: var(--text-tertiary); padding: 10px 10px; border-bottom: .5px solid var(--border); white-space: nowrap; background: var(--surface); }
.table td { padding: 8px 10px; border-bottom: .5px solid var(--border-subtle); vertical-align: middle; color: var(--text-body); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover, .table tbody tr:focus { background: var(--surface); outline: none; }
.table tbody tr.sel { background: var(--sidebar-accent); }
.c-check { width: 36px; }
.c-act { width: 48px; text-align: right; }
.nowrap { white-space: nowrap; }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.name-cell .t { font-weight: 500; color: var(--text-heading); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 380px; }
.name-cell .d { font-size: 12px; color: var(--text-tertiary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 380px; }
.star { color: #8f6300; font-size: 12px; }
.muted2 { color: var(--text-tertiary); font-size: 13px; }
.ficon { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px; font-size: 9px; font-weight: 700; letter-spacing: .02em; color: #fff; background: #5d6473; }
.ficon-pdf { background: #c62b30; } .ficon-image { background: #8e4ec6; } .ficon-doc { background: #1d5fd0; } .ficon-sheet { background: #147a38; }
.ficon-slides { background: #b45309; } .ficon-video { background: #db2777; } .ficon-audio { background: #0b6f8a; } .ficon-archive { background: #a16207; } .ficon-data { background: #475569; }
.ficon-postman { background: #c9491a; }
.folder-ic { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px; background: rgba(14,124,156,.14); color: var(--primary-text); font-size: 18px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--muted); color: var(--text-secondary); white-space: nowrap; }
.badge-private { background: rgba(239,68,68,.12); color: #b02525; } .badge-internal { background: rgba(59,130,246,.12); color: #1d56b8; }
.badge-link { background: rgba(14,124,156,.14); color: #0a647e; } .badge-public { background: rgba(22,163,74,.13); color: #0f6b30; }
.dark .badge-private { color: #f87171; } .dark .badge-internal { color: #7aa7ff; } .dark .badge-link { color: #5ccbe8; } .dark .badge-public { color: #4ade80; }
input[type=checkbox] { accent-color: var(--primary); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.tile { position: relative; background: var(--card); border: .5px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; cursor: pointer; min-width: 0; }
.tile:hover, .tile:focus { border-color: var(--primary); outline: none; }
.tile.sel { border-color: var(--primary); background: var(--sidebar-accent); }
.tile .thumb { height: 96px; border-radius: 8px; background: var(--surface); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.tile .thumb img { max-width: 100%; max-height: 100%; object-fit: cover; }
.tile .t { font-weight: 500; color: var(--text-heading); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .m { font-size: 12px; color: var(--text-tertiary); }
.tile .tile-check { position: absolute; top: 10px; left: 10px; }
.tile .tile-act { position: absolute; top: 6px; right: 6px; }

.state { text-align: center; padding: 56px 16px; color: var(--text-secondary); background: var(--card); border: .5px dashed var(--border-strong); border-radius: var(--radius); }
.state h3 { margin: 0 0 6px; color: var(--text-heading); font-size: 16px; font-weight: 600; }
.state p { margin: 0 0 14px; }
.skel { height: 48px; border-radius: 8px; background: linear-gradient(90deg, var(--muted), var(--surface), var(--muted)); background-size: 200% 100%; animation: sh 1.2s infinite; margin-bottom: 8px; }
@keyframes sh { to { background-position: -200% 0; } }
.pager { display: flex; justify-content: center; align-items: center; gap: 8px; padding: 14px 0; font-size: 14px; color: var(--text-secondary); }

.menu { position: fixed; z-index: 60; min-width: 220px; background: var(--popover); color: var(--popover-foreground); border: .5px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 28px rgba(0,0,0,.16); padding: 4px; animation: fi .12s ease-out; }
.menu button { display: flex; width: 100%; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; border: 0; background: none; border-radius: 6px; cursor: pointer; text-align: left; font-size: 14px; }
.menu button:hover, .menu button:focus { background: var(--muted); outline: none; }
.menu button.danger { color: var(--destructive); }
.menu hr { border: 0; height: .5px; background: var(--border); margin: 4px 0; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fi .15s ease-out; }
.modal { background: var(--card); color: var(--card-foreground); border-radius: 14px; width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 16px 48px rgba(0,0,0,.25); animation: su .18s ease-out; }
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 6px; }
.modal-head h2 { font-size: 16px; margin: 0; color: var(--text-heading); overflow: hidden; text-overflow: ellipsis; }
.modal-body { padding: 8px 16px 12px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px calc(14px + var(--sab)); border-top: .5px solid var(--border-subtle); }
@keyframes fi { from { opacity: 0; } } @keyframes su { from { transform: translateY(12px); opacity: 0; } }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 14px; }
.field > span { color: var(--text-secondary); font-size: 13px; }
.field .input { font-size: 16px; }
textarea.input { min-height: 90px; resize: vertical; }
.hint { font-size: 12px; color: var(--text-tertiary); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; min-height: 36px; }
.radio-list { display: flex; flex-direction: column; gap: 4px; }
.radio-list label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; border: .5px solid var(--border); cursor: pointer; }
.radio-list label small { display: block; color: var(--text-tertiary); font-size: 12px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 14px; margin-bottom: 14px; }
.kv dt { color: var(--text-tertiary); } .kv dd { margin: 0; word-break: break-word; color: var(--text-body); }
.sec-title { font-size: 13px; font-weight: 600; color: var(--text-heading); margin: 14px 0 8px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.row-item { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; border: .5px solid var(--border); border-radius: 8px; font-size: 13px; }
.row-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.hist { font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.hist div { display: flex; gap: 8px; } .hist time { color: var(--text-tertiary); white-space: nowrap; }
.folder-pick { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.folder-pick button { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; min-height: 40px; font-size: 14px; }
.folder-pick button.on { background: var(--sidebar-accent); color: var(--primary-text); font-weight: 600; }
.folder-pick button:disabled { opacity: .4; }

.drop { position: fixed; inset: 0; z-index: 70; background: rgba(32,162,199,.14); display: flex; align-items: center; justify-content: center; padding: 20px; }
.drop-inner { border: 2px dashed var(--primary); border-radius: 18px; padding: 48px 32px; background: var(--card); color: var(--primary-text); font-weight: 600; font-size: 18px; }
.uploads { position: fixed; right: 16px; bottom: calc(16px + var(--sab)); width: 360px; max-width: calc(100vw - 32px); max-height: 50vh; overflow-y: auto; z-index: 40; background: var(--card); border: .5px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.up-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 14px; font-weight: 600; font-size: 14px; border-bottom: .5px solid var(--border-subtle); color: var(--text-heading); }
.up-item { padding: 8px 14px; border-bottom: .5px solid var(--border-subtle); font-size: 13px; }
.up-row { display: flex; align-items: center; gap: 8px; }
.up-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-heading); }
.up-bar { height: 4px; background: var(--muted); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.up-bar span { display: block; height: 100%; background: var(--primary); width: 0; transition: width .15s; }
.up-st { font-size: 12px; color: var(--text-tertiary); } .up-st.err { color: var(--destructive); } .up-st.ok { color: #106b35; }
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + var(--sab)); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text-heading); color: var(--background); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: su .18s ease-out; max-width: 90vw; }
.toast-error { background: var(--destructive); color: #fff; }
.toast.out { opacity: 0; transition: opacity .25s; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 35; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .only-sm { display: inline-flex; }
  .main { padding: 0 12px calc(24px + var(--sab)); }
  .who { display: none; }
  .nav-item { min-height: 44px; }
}
@media (max-width: 640px) {
  .top { flex-wrap: wrap; }
  .search { order: 3; flex-basis: 100%; }
  .top-actions { margin-left: auto; }
  .btn { min-height: 44px; }
  .sel { max-width: 46%; flex: 1; min-height: 44px; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { display: grid; grid-template-columns: 44px 1fr 44px; grid-template-areas: "c n a" "c m a"; padding: 8px 6px; border-bottom: .5px solid var(--border-subtle); }
  .table td { border: 0; padding: 2px 4px; }
  .table td.c-check { grid-area: c; align-self: center; padding: 0; width: 44px; }
  .table td.c-name { grid-area: n; }
  .table td.c-act { grid-area: a; align-self: center; width: auto; }
  .table td.c-meta { grid-area: m; display: block; }
  .table td.c-hide-sm { display: none; }
  .name-cell .t, .name-cell .d { max-width: 62vw; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .overlay { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 16px 16px 0 0; max-height: 88vh; }
  .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 6px; }
  .uploads { right: 8px; left: 8px; width: auto; max-width: none; }
  .menu { left: 8px !important; right: 8px; bottom: calc(8px + var(--sab)); top: auto !important; min-width: 0; }
  .menu button { min-height: 44px; }
  .icon-btn { min-width: 44px; height: 44px; }
  .seg-btn { min-width: 44px; height: 44px; }
  .btn-sm { min-height: 44px; }
  .crumbs button { min-height: 44px; }
  .folder-pick button { min-height: 44px; }
  .check { min-height: 44px; }
  .radio-list label { min-height: 44px; }
}
@media (min-width: 641px) { .table td.c-meta { display: none; } }
