:root {
  --navy: #14213d;
  --navy-2: #1f3260;
  --ink: #1c2333;
  --muted: #6b7385;
  --line: #e4e7ee;
  --bg: #f6f7fa;
  --card: #ffffff;
  --accent: #2f5bd3;
  --danger: #c0392b;
  --ok: #1e8e5a;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); font-size: 15px; }
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c9cede; background: #fafbfd; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.icon-btn { background: none; border: 0; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 18px; color: var(--muted); line-height: 1; }
.icon-btn:hover { background: #eef0f5; color: var(--ink); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 91, 211, .12); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.error { color: var(--danger); font-size: 13px; margin: 8px 0; min-height: 1em; }

/* App layout */
body.app { display: flex; }
.sidebar { width: 236px; flex-shrink: 0; background: var(--navy); color: #dfe5f3; display: flex; flex-direction: column; height: 100vh; position: sticky; top: 0; }
.brand { padding: 22px 20px 18px; font-weight: 700; font-size: 16px; color: #fff; letter-spacing: .2px; }
.brand img { max-width: 100%; max-height: 54px; display: block; background: #fff; border-radius: 6px; padding: 6px; }
.sidebar nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; }
.sidebar nav a { color: #c9d2e8; padding: 9px 12px; border-radius: 8px; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 16px 20px; font-size: 13px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot .link { color: #aebce0; margin-right: 12px; font-size: 13px; }
.me { margin-top: 10px; }
.me-name { color: #fff; font-weight: 600; display: block; margin-bottom: 4px; }
main { flex: 1; min-width: 0; padding: 26px 32px 80px; }
h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

.topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.crumbs { flex: 1; font-size: 20px; font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 200px; }
.crumbs a { color: var(--muted); font-weight: 600; }
.crumbs a:hover { color: var(--ink); }
.crumbs .sep { color: #b6bccb; font-weight: 400; }
.search { width: 280px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--line); }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr:hover { background: #fafbfd; }
.name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.name-cell a, .name-cell .nm { color: var(--ink); overflow-wrap: anywhere; }
.name-cell a:hover { color: var(--accent); }
.ficon { width: 30px; height: 30px; flex-shrink: 0; border-radius: 6px; display: grid; place-items: center; font-size: 10px; font-weight: 700; color: #fff; background: #8a93a8; }
.ficon.folder { background: #e9b949; }
.ficon.pdf { background: #d6453d; } .ficon.img { background: #3a9d6e; } .ficon.doc { background: #2f5bd3; }
.ficon.xls { background: #1e7d4a; } .ficon.zip { background: #6c5ce7; } .ficon.vid { background: #b4458f; }
.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 99px; background: #eaf0ff; color: var(--accent); font-weight: 600; margin-left: 6px; }
.badge.gray { background: #eef0f5; color: var(--muted); }
.badge.red { background: #fdecea; color: var(--danger); }
.muted { color: var(--muted); font-size: 13px; }
.right { text-align: right; }
.empty { padding: 50px 20px; text-align: center; color: var(--muted); }
.col-hide { }

/* Drag & drop */
.drop-overlay { position: fixed; inset: 0; background: rgba(20, 33, 61, .55); color: #fff; display: grid; place-items: center; font-size: 22px; font-weight: 600; z-index: 50; pointer-events: none; }
.drop-overlay div { border: 3px dashed #fff; border-radius: 16px; padding: 50px 70px; }

/* Upload panel */
.upload-panel { position: fixed; right: 20px; bottom: 20px; width: 340px; max-height: 50vh; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 40px rgba(20,33,61,.18); z-index: 40; }
.upload-panel header { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; font-weight: 600; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.up-item { padding: 8px 14px; font-size: 13px; border-bottom: 1px solid var(--line); }
.up-item .bar { height: 4px; background: #eef0f5; border-radius: 4px; margin-top: 6px; overflow: hidden; }
.up-item .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up-item.done .bar i { background: var(--ok); }
.up-item.fail { color: var(--danger); }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(15, 22, 40, .45); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal h2 { font-size: 18px; margin: 0; padding: 20px 22px 0; }
.modal .body { padding: 16px 22px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 22px 20px; }
.sheet-btn { display: block; width: 100%; text-align: left; padding: 12px 14px; background: none; border: 0; border-radius: 8px; cursor: pointer; font-size: 15px; }
.sheet-btn:hover { background: #f2f4f8; }
.sheet-btn.danger { color: var(--danger); }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-size: 13px; }
.tree { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.tree button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.tree button:hover { background: #f2f4f8; }
.tree button.sel { background: #eaf0ff; color: var(--accent); font-weight: 600; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 70; }
#toast.show { opacity: 1; }

/* Auth & public pages */
body.center { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 32px 30px; box-shadow: 0 10px 30px rgba(20,33,61,.06); }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand img { max-height: 64px; max-width: 220px; }
.auth-brand .txt { font-weight: 700; font-size: 20px; color: var(--navy); }
.auth-card h1 { font-size: 18px; text-align: center; margin-bottom: 18px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 11px; }

.pub-header { background: #fff; border-bottom: 1px solid var(--line); padding: 14px 28px; display: flex; align-items: center; gap: 14px; }
.pub-header img { max-height: 40px; }
.pub-header .txt { font-weight: 700; color: var(--navy); font-size: 17px; }
.pub-main { max-width: 1000px; margin: 0 auto; padding: 28px 20px 60px; }
.pub-foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }

@media (max-width: 760px) {
  body.app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { padding: 12px 16px; }
  .brand img { max-height: 36px; }
  .sidebar nav { flex-direction: row; padding: 0 8px 8px; width: 100%; overflow-x: auto; order: 3; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 10px 16px; }
  .sidebar-foot #usage, .me-name { display: none; }
  .me { margin: 0; }
  main { padding: 18px 14px 80px; }
  .search { width: 100%; }
  .col-hide { display: none; }
  .toolbar .btn { flex: 1 1 auto; justify-content: center; }
  .upload-panel { left: 10px; right: 10px; width: auto; }
  .pub-header { padding: 12px 16px; }
}

/* View-only document viewer */
.viewer-back { position: fixed; inset: 0; background: #1b2233; z-index: 80; display: flex; flex-direction: column; user-select: none; -webkit-user-select: none; }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px; background: var(--navy); color: #fff; }
.viewer-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-body { flex: 1; overflow: auto; padding: 16px 12px 40px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.viewer-page { background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.35); max-width: 100%; }
.viewer-img { max-width: 100%; height: auto; box-shadow: 0 4px 18px rgba(0,0,0,.35); pointer-events: none; }
.viewer-mark { position: fixed; inset: 60px 0 0 0; pointer-events: none; display: grid; place-items: center; font-size: 34px; font-weight: 700; color: rgba(20,33,61,.13); transform: rotate(-28deg); white-space: nowrap; }
@media print { body.viewing * { display: none !important; } }
.viewer-bar .btn { color: var(--ink); }
