/* ============================================================
   up4u.ir — UI styles (PWA + RTL + mobile-first)
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --surface-hover: #f1f3f4;
  --border: #e3e6ea;
  --text: #202124;
  --text-muted: #5f6368;
  --primary: #1a73e8;
  --primary-hover: #1765cc;
  --primary-soft: #e8f0fe;
  --danger: #d93025;
  --danger-soft: #fce8e6;
  --success: #188038;
  --warning: #f9ab00;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-1: 0 1px 3px rgba(60,64,67,.15);
  --shadow-2: 0 4px 12px rgba(60,64,67,.15);
  --shadow-3: 0 12px 32px rgba(60,64,67,.2);
  --sidebar-w: 240px;
  --topbar-h: 64px;
}

html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Vazirmatn', 'Segoe UI', Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px 8px;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
  transition: right .25s ease;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; font-size: 20px; font-weight: 700;
  color: var(--primary); margin-bottom: 12px;
}
.brand svg { width: 28px; height: 28px; }

.sidebar .btn-new {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 0 8px 16px; padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  font-weight: 600; color: var(--text);
  box-shadow: var(--shadow-1);
  transition: box-shadow .15s, background .15s;
  width: calc(100% - 16px);
}
.sidebar .btn-new:hover { box-shadow: var(--shadow-2); background: var(--surface-hover); }

.nav-list { list-style: none; padding: 0; margin: 0; }
.nav-list li a {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 24px;
  color: var(--text); font-weight: 500;
  text-decoration: none;
}
.nav-list li a:hover { background: var(--surface-hover); }
.nav-list li a.active { background: var(--primary-soft); color: var(--primary); }
.nav-list svg { width: 20px; height: 20px; flex-shrink: 0; }

.quota-block { margin: 16px 12px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-hover); }
.quota-block .label { font-size: 12px; color: var(--text-muted); }
.quota-block .value { font-size: 13px; font-weight: 600; margin-top: 4px; }
.quota-bar { height: 6px; background: #e0e0e0; border-radius: 3px; margin-top: 8px; overflow: hidden; }
.quota-bar > div { height: 100%; background: var(--primary); border-radius: 3px; transition: width .3s; }
.quota-bar > div.warn { background: var(--warning); }
.quota-bar > div.danger { background: var(--danger); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.hamburger {
  display: none;
  width: 40px; height: 40px;
  border: none; background: transparent;
  border-radius: 50%;
  color: var(--text);
  place-items: center;
  flex-shrink: 0;
}
.hamburger:hover { background: var(--surface-hover); }

.search {
  flex: 1; max-width: 720px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-hover); border-radius: 8px;
  padding: 0 12px;
  transition: background .15s, box-shadow .15s;
}
.search:focus-within { background: var(--surface); box-shadow: var(--shadow-1); }
.search input {
  flex: 1; border: none; background: transparent;
  padding: 10px 0; outline: none; min-width: 0;
}

.topbar .user {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px; border-radius: 24px;
  margin-right: auto;
}
.topbar .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 600;
  flex-shrink: 0;
}
.user-id { font-weight: 500; }

/* ---------- Content ---------- */
.content { padding: 16px 24px 32px; flex: 1; }

.crumb {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 0 16px; font-size: 22px; font-weight: 600;
  flex-wrap: wrap;
}
.crumb a { color: var(--text); }
.crumb a:hover { color: var(--primary); text-decoration: none; }
.crumb .sep { color: var(--text-muted); font-weight: 400; }

.toolbar {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
  margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar .tools { display: flex; gap: 4px; flex-wrap: wrap; }
.toolbar .tool {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 8px; border: none;
  background: transparent; color: var(--text-muted); font-weight: 500;
}
.toolbar .tool:hover { background: var(--surface-hover); color: var(--text); }

.view-toggle {
  display: flex; border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden; margin-right: auto;
}
.view-toggle button {
  padding: 6px 10px; border: none; background: transparent;
  color: var(--text-muted); font-size: 16px;
}
.view-toggle button.active { background: var(--primary-soft); color: var(--primary); }

/* ---------- Empty ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 64px 24px; text-align: center;
  background: var(--surface); border-radius: var(--radius);
  border: 1px dashed var(--border);
}
.empty svg { width: 96px; height: 96px; color: #c5c9d0; margin-bottom: 16px; }
.empty h3 { margin: 0 0 8px; font-size: 18px; }
.empty p { margin: 0; color: var(--text-muted); }

/* ---------- Shared banner ---------- */
.shared-banner {
  background: var(--primary-soft);
  padding: 12px 16px; border-radius: var(--radius-sm);
  margin-bottom: 16px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.shared-banner strong { color: var(--primary); }
.shared-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.shared-chip {
  background: var(--surface); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 16px;
  font-size: 12px; color: var(--text);
}
.shared-chip a { color: var(--primary); }

/* ---------- Table ---------- */
.files-table {
  width: 100%; background: var(--surface);
  border-radius: var(--radius); overflow: hidden;
  border-collapse: collapse; box-shadow: var(--shadow-1);
}
.files-table th, .files-table td {
  padding: 10px 16px; text-align: right;
  border-bottom: 1px solid var(--border);
}
.files-table th {
  font-weight: 600; color: var(--text-muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em;
}
.files-table tr:last-child td { border-bottom: none; }
.files-table tr:hover td { background: var(--surface-hover); }
.files-table tr.selected td { background: var(--primary-soft); }
.files-table .name {
  display: flex; align-items: center; gap: 10px;
  font-weight: 500; color: var(--text);
}
.files-table .name svg { width: 20px; height: 20px; flex-shrink: 0; }
.files-table .name a { color: inherit; text-decoration: none; }
.files-table .name a:hover { color: var(--primary); }
.files-table .muted { color: var(--text-muted); font-size: 13px; }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.row-actions button {
  width: 32px; height: 32px;
  display: inline-grid; place-items: center;
  border: none; background: transparent; border-radius: 50%;
  color: var(--text-muted); font-size: 15px;
}
.row-actions button:hover { background: var(--surface-hover); color: var(--text); }
.row-actions button.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- Grid ---------- */
.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.file-card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
  transition: box-shadow .15s, border-color .15s;
  cursor: pointer; position: relative;
  text-align: center;
}
.file-card:hover { box-shadow: var(--shadow-2); border-color: transparent; }
.file-card .thumb {
  aspect-ratio: 4 / 3;
  background: #fafbfc; border-radius: var(--radius-sm);
  display: grid; place-items: center; overflow: hidden;
}
.file-card .thumb svg { width: 64px; height: 64px; }
.file-card .title {
  font-weight: 500; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.file-card .meta { font-size: 12px; color: var(--text-muted); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(32,33,36,.5);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 24px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 480px; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-3);
  overflow: hidden;
}
.modal-head {
  padding: 20px 24px 8px;
  font-size: 20px; font-weight: 600;
}
.modal-body { padding: 8px 24px 16px; overflow-y: auto; }
.modal-body p { margin: 0 0 12px; color: var(--text); }
.modal-body label {
  display: block; color: var(--text-muted); font-size: 13px;
  margin: 12px 0 6px;
}
.modal-body input,
.modal-body select,
.modal-body textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
  outline: 2px solid var(--primary); outline-offset: -1px;
}
.modal-actions {
  padding: 16px 24px; display: flex; justify-content: flex-end; gap: 8px;
  border-top: 1px solid var(--border);
}

.btn {
  padding: 9px 20px; border-radius: 8px;
  font-weight: 600; border: 1px solid transparent;
  font-size: 14px;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-hover); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.9); }

/* ---------- Snackbar ---------- */
.snackbar-container {
  position: fixed; bottom: 24px; left: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 2000; max-width: 400px;
}
.snackbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 8px;
  background: #323232; color: #fff;
  box-shadow: var(--shadow-2);
  font-size: 13px; min-width: 280px;
  animation: slide-up .3s ease;
}
.snackbar.success { background: var(--success); }
.snackbar.error { background: var(--danger); }
.snackbar.info { background: var(--primary); }
.snackbar button {
  background: transparent; color: #fff; border: none;
  opacity: .8; font-weight: 600; padding: 0 4px;
}
.snackbar button:hover { opacity: 1; }
@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* ---------- Upload panel ---------- */
.upload-panel {
  position: fixed; bottom: 16px; left: 16px;
  width: 360px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow-3);
  z-index: 1500; display: none;
  overflow: hidden;
}
.upload-panel.open { display: block; }
.upload-panel .head {
  padding: 12px 16px; background: var(--primary);
  color: #fff; display: flex;
  justify-content: space-between; align-items: center;
  font-weight: 600;
}
.upload-panel .list { max-height: 320px; overflow-y: auto; }
.upload-panel .item { padding: 10px 16px; border-top: 1px solid var(--border); }
.upload-panel .item .row {
  display: flex; justify-content: space-between; gap: 8px; font-size: 13px;
}
.upload-panel .item .bar {
  height: 4px; border-radius: 2px; background: #e0e0e0;
  margin-top: 6px; overflow: hidden;
}
.upload-panel .item .bar > div {
  height: 100%; background: var(--primary); transition: width .2s;
}
.upload-panel .item.success .bar > div { background: var(--success); }
.upload-panel .item.error .bar > div { background: var(--danger); }

/* ---------- Context menu ---------- */
.ctx-menu {
  position: fixed; z-index: 3000;
  background: var(--surface); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-3); padding: 6px 0;
  min-width: 200px; display: none;
}
.ctx-menu.open { display: block; }
.ctx-menu button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 16px;
  border: none; background: transparent;
  color: var(--text); font-size: 13px; text-align: right;
}
.ctx-menu button:hover { background: var(--surface-hover); }
.ctx-menu button.danger { color: var(--danger); }
.ctx-menu button.danger:hover { background: var(--danger-soft); }

/* ---------- Auth ---------- */
.auth-page {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, #1a73e8, #6a1b9a);
  padding: 24px;
}
.auth-card {
  background: var(--surface); border-radius: 24px;
  padding: 40px 32px; width: 100%; max-width: 400px;
  box-shadow: var(--shadow-3);
}
.auth-card h1 {
  margin: 0 0 8px; font-size: 26px;
  text-align: center; color: var(--primary);
}
.auth-card .sub {
  text-align: center; color: var(--text-muted); margin-bottom: 24px;
}
.auth-card input {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 12px;
}
.auth-card .btn { width: 100%; padding: 12px; }
.auth-card .msg {
  padding: 10px 12px; border-radius: 8px;
  font-size: 13px; margin-bottom: 12px;
}
.auth-card .msg.error { background: var(--danger-soft); color: var(--danger); }
.auth-card .msg.info { background: var(--primary-soft); color: var(--primary); }
.auth-card .link-back {
  display: block; text-align: center; margin-top: 12px;
  font-size: 13px; color: var(--text-muted);
}

/* ---------- FAB ---------- */
.fab {
  display: none;
  position: fixed; bottom: 24px; left: 24px;
  width: 56px; height: 56px;
  border-radius: 50%; background: var(--primary); color: #fff;
  border: none; box-shadow: 0 6px 16px rgba(26,115,232,.4);
  z-index: 500; place-items: center;
  transition: transform .15s, box-shadow .15s;
}
.fab:hover { transform: scale(1.06); box-shadow: 0 8px 20px rgba(26,115,232,.5); }
.fab:active { transform: scale(.96); }

/* ---------- Sidebar overlay (mobile) ---------- */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 800; display: none;
}
.sidebar-overlay.visible { display: block; }

/* ---------- Groups ---------- */
.group-card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 16px;
  margin-bottom: 12px;
}
.group-card .head {
  display: flex; justify-content: space-between;
  align-items: center; gap: 12px; margin-bottom: 12px;
}
.group-card .head h3 { margin: 0; font-size: 16px; }
.group-card .head .meta { color: var(--text-muted); font-size: 12px; }
.group-members { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.member-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 16px;
  background: var(--surface-hover); font-size: 12px;
}
.member-chip .role {
  font-weight: 600; color: var(--primary); font-size: 11px;
}
.member-chip .remove {
  color: var(--danger); cursor: pointer; font-weight: 700;
  margin-right: 4px;
}
.group-card form.inline {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
}
.group-card form.inline input,
.group-card form.inline select {
  padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px;
}
.group-card form.inline input[name="target_user_id"] { width: 140px; }

/* ---------- Admin ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px; margin: 16px 0;
}
.card {
  background: var(--surface); padding: 16px;
  border-radius: var(--radius); border: 1px solid var(--border);
}
.card span { display: block; color: var(--text-muted); font-size: 13px; margin-bottom: 6px; }
.card b { font-size: 20px; color: var(--primary); }
.audit-list {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); max-height: 400px; overflow-y: auto;
}
.audit-list .row {
  padding: 8px 16px; border-bottom: 1px solid var(--border);
  font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap;
}
.audit-list .row:last-child { border-bottom: none; }
.audit-list .cat {
  background: var(--surface-hover); padding: 1px 6px;
  border-radius: 4px; font-weight: 600;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1024px) {
  :root { --sidebar-w: 220px; }
}

@media (max-width: 768px) {
  .hamburger { display: grid; }
  .fab { display: grid; }

  .sidebar {
    position: fixed;
    top: 0; right: -280px;
    width: 260px; height: 100vh;
    z-index: 900;
    box-shadow: -8px 0 24px rgba(0,0,0,.12);
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { right: 0; }

  .topbar { padding: 0 12px; gap: 8px; height: 56px; }
  .search input { font-size: 16px; }
  .user-id { display: none; }
  .user { padding: 4px; }

  .content {
    padding: 12px 12px calc(80px + env(safe-area-inset-bottom));
  }
  .crumb { font-size: 18px; padding: 4px 0 12px; }
  .toolbar { gap: 8px; padding-bottom: 8px; margin-bottom: 12px; }
  .toolbar .tool span { display: none; }
  .toolbar .tool { padding: 8px; }
  .view-toggle { margin-right: 0; }

  /* Table → cards */
  .files-table thead { display: none; }
  .files-table, .files-table tbody, .files-table tr, .files-table td {
    display: block; width: 100%;
  }
  .files-table tr {
    padding: 12px; border-bottom: 1px solid var(--border);
    position: relative;
  }
  .files-table tr:hover td { background: transparent; }
  .files-table td { border: none; padding: 2px 0; }
  .files-table .name { font-size: 15px; }
  .files-table .name svg { width: 24px; height: 24px; }
  .row-actions { justify-content: flex-start; gap: 0; margin-top: 8px; flex-wrap: wrap; }
  .row-actions button { width: 40px; height: 40px; }

  .files-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .file-card { padding: 10px; }
  .file-card .thumb svg { width: 48px; height: 48px; }
  .file-card .title { font-size: 13px; }

  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    border-radius: 20px 20px 0 0;
    max-width: 100%; max-height: 85vh;
    animation: sheet-up .25s ease;
  }
  @keyframes sheet-up {
    from { transform: translateY(100%); }
    to { transform: none; }
  }
  .modal-body input,
  .modal-body select,
  .modal-body textarea {
    font-size: 16px; padding: 12px;
  }

  .upload-panel { left: 0; right: 0; bottom: 0; width: 100%; border-radius: 16px 16px 0 0; }
  .upload-panel { padding-bottom: env(safe-area-inset-bottom); }

  .snackbar-container { left: 12px; right: 12px; bottom: 90px; max-width: none; }
  .snackbar { min-width: 0; width: 100%; }

  .auth-page { padding: 16px; }
  .auth-card { padding: 28px 20px; border-radius: 20px; }

  .fab { bottom: calc(24px + env(safe-area-inset-bottom)); }
}

@media (max-width: 420px) {
  .files-grid { grid-template-columns: 1fr; }
  .crumb { font-size: 16px; }
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/static/fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Vazirmatn';
  src: url('/static/fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Vazirmatn';
  src: url('/static/fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
/* ============================================================
   Tree, stats, plan, footer
   ============================================================ */
.tree-block {
  margin: 12px 8px 0;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.tree-head {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  padding: 4px 8px; margin-bottom: 4px;
  display: flex; align-items: center; justify-content: space-between;
}
.tree { list-style: none; padding: 0 8px; margin: 0; }
.tree ul { list-style: none; padding: 0 16px; margin: 0; }
.tree li { margin: 1px 0; }
.tree a {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: 6px;
  color: var(--text); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree a:hover { background: var(--surface-hover); text-decoration: none; }
.tree-icon { font-size: 13px; flex-shrink: 0; }
.tree-name { overflow: hidden; text-overflow: ellipsis; }

.stats-block {
  margin: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.stat {
  background: var(--surface-hover);
  padding: 8px 10px;
  border-radius: 8px;
  display: flex; align-items: baseline; gap: 4px;
}
.stat-num { font-weight: 700; font-size: 16px; color: var(--primary); }
.stat-label { font-size: 11px; color: var(--text-muted); }

.plan-block {
  margin: 8px;
  padding: 12px;
  background: linear-gradient(135deg, var(--primary-soft), #f3e8ff);
  border-radius: var(--radius-sm);
}
.plan-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.plan-label { font-size: 12px; color: var(--text-muted); }
.plan-badge {
  background: var(--primary); color: #fff;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
}
.plan-quota { font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.plan-upgrade {
  display: block; text-align: center;
  margin-top: 10px; padding: 6px;
  background: var(--primary); color: #fff;
  border-radius: 6px; font-size: 12px; font-weight: 600;
  text-decoration: none;
}
.plan-upgrade:hover { background: var(--primary-hover); text-decoration: none; }

/* topbar actions */
.topbar-actions { display: flex; gap: 4px; }
.topbar-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%; font-size: 18px;
  color: var(--text-muted);
  text-decoration: none;
}
.topbar-btn:hover { background: var(--surface-hover); text-decoration: none; }

/* footer */
.site-footer {
  margin-top: auto;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
  flex-wrap: wrap; gap: 8px;
}
.site-footer a { color: var(--text-muted); margin: 0 6px; }
.site-footer a:hover { color: var(--primary); }
.footer-left, .footer-right { display: flex; align-items: center; gap: 4px; }
.dot { opacity: .4; }

.main { min-height: 100vh; }
.layout { min-height: 100vh; }
.content { flex: 1 0 auto; }

/* plans page */
.plans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  padding: 8px 0;
}
.plan-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  display: flex; flex-direction: column;
  transition: box-shadow .15s, transform .15s;
}
.plan-card:hover { box-shadow: var(--shadow-2); transform: translateY(-2px); }
.plan-card.current { border-color: var(--primary); border-width: 2px; }
.plan-card h2 { margin: 0 0 8px; font-size: 20px; }
.plan-price { font-size: 24px; font-weight: 700; color: var(--primary); margin-bottom: 16px; }
.plan-price small { font-size: 13px; color: var(--text-muted); font-weight: 400; }
.plan-features { list-style: none; padding: 0; margin: 0 0 20px; flex: 1; }
.plan-features li { padding: 6px 0; font-size: 13px; color: var(--text); border-bottom: 1px solid var(--surface-hover); }
.plan-features li:last-child { border-bottom: 0; }
.plan-card .btn { width: 100%; }

/* mobile */
@media (max-width: 768px) {
  .site-footer { padding: 12px; font-size: 11px; }
  .tree-block { display: none; } /* تو موبایل، درخت تو سایدبار drawer هم جا نمی‌شه؛ ok */
  .tree-block.mobile-visible { display: block; }
}
/* ============================================================
   Share view banner
   ============================================================ */
.share-view-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: linear-gradient(135deg, #fff8e1, #fff3e0);
  border: 1px solid #ffe0b2;
  border-radius: var(--radius);
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.share-view-icon {
  font-size: 28px;
  line-height: 1;
}
.share-view-text { flex: 1; min-width: 200px; }
.share-view-text strong { display: block; font-size: 14px; margin-bottom: 2px; }
.share-view-text small { color: var(--text-muted); font-size: 12px; }
.share-view-exit {
  background: var(--surface);
  border: 1px solid #ffb74d;
  color: #e65100;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}
.share-view-exit:hover {
  background: #ffb74d;
  color: #fff;
  text-decoration: none;
}

/* ============================================================
   Shared section (cards)
   ============================================================ */
.shared-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-1);
}
.shared-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 14px;
  color: var(--text);
}
.shared-count {
  background: var(--primary-soft);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
}

.shared-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.shared-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #fafbfd;
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
.shared-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(26,115,232,.08);
}
.shared-card-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}
.shared-card-body { flex: 1; min-width: 0; }
.shared-card-name {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shared-card-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.perm-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
}
.perm-read   { background: #e8f0fe; color: #1a73e8; }
.perm-write  { background: #e6f4ea; color: #188038; }
.perm-manage { background: #fce8e6; color: #d93025; }

.shared-card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.shared-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s;
}
.shared-btn-open   { background: var(--primary); color: #fff; }
.shared-btn-open:hover { background: var(--primary-hover); color: #fff; text-decoration: none; }
.shared-btn-dl     { background: #e6f4ea; color: #188038; }
.shared-btn-dl:hover { background: #188038; color: #fff; text-decoration: none; }
.shared-btn-revoke { background: transparent; color: var(--danger); font-weight: 700; }
.shared-btn-revoke:hover { background: #fce8e6; text-decoration: none; }

/* ============================================================
   Breadcrumb améliorée
   ============================================================ */
.crumb a.crumb-home {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
}
.crumb a.crumb-home:hover { color: var(--primary); text-decoration: none; }

/* ============================================================
   Toolbar améliorée
   ============================================================ */
.toolbar .tool svg { flex-shrink: 0; }
.toolbar .view-toggle button { font-size: 15px; }

/* ============================================================
   Empty state
   ============================================================ */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}
.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  line-height: 1;
}
.empty h3 { margin: 0 0 8px; font-size: 18px; }
.empty p { margin: 0; color: var(--text-muted); max-width: 400px; }

/* ============================================================
   Table rows
   ============================================================ */
.files-table .file-name { font-weight: 500; }

/* ============================================================
   Mobile
   ============================================================ */
@media (max-width: 768px) {
  .shared-grid { grid-template-columns: 1fr; }
  .shared-card-actions { flex-wrap: wrap; }
  .shared-btn { padding: 6px 10px; font-size: 12px; }
  .share-view-banner { padding: 12px; }
  .share-view-text strong { font-size: 13px; }
}
/* ============================================================
   Guest layout (login/register pages)
   ============================================================ */
.guest-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #fafcff;
}

.guest-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  flex-wrap: wrap;
  gap: 12px;
}
.guest-brand {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #0B63E5, #3B82F6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-decoration: none;
}
.guest-brand:hover { text-decoration: none; }

.guest-nav {
  display: flex;
  gap: 24px;
  align-items: center;
  flex-wrap: wrap;
}
.guest-nav a {
  text-decoration: none;
  font-weight: 500;
  color: #2c3e50;
  transition: color .2s;
}
.guest-nav a:hover { color: #0B63E5; }

.guest-nav .btn-outline-light {
  border: 1px solid #cbd5e1;
  padding: 8px 20px;
  border-radius: 40px;
  background: white;
  font-weight: 600;
}
.guest-nav .btn-outline-light:hover {
  border-color: #0B63E5;
  background: #f0f7ff;
  text-decoration: none;
}
.guest-nav .btn-primary {
  background: #0B63E5;
  padding: 8px 20px;
  border-radius: 40px;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(11,99,229,.2);
}
.guest-nav .btn-primary:hover {
  background: #0954c4;
  text-decoration: none;
}

.guest-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

.guest-footer {
  text-align: center;
  padding: 20px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  color: #5b6e8c;
  font-size: 13px;
}
.guest-footer a { color: #0B63E5; text-decoration: none; }
.guest-footer a:hover { text-decoration: underline; }
.guest-footer p { margin: 4px 0; }

/* Mobile */
@media (max-width: 768px) {
  .guest-header { padding: 14px 20px; }
  .guest-nav { gap: 12px; font-size: 0.9rem; }
  .guest-nav a:not(.btn-outline-light):not(.btn-primary) { display: none; }
  .guest-nav .btn-outline-light,
  .guest-nav .btn-primary { padding: 6px 14px; font-size: 0.85rem; }
}
/* ============================================================
   Error pages
   ============================================================ */
.error-page {
  text-align: center;
  padding: 60px 24px;
  max-width: 500px;
  margin: 0 auto;
}
.error-code {
  font-size: 96px;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(135deg, #1a73e8, #6a1b9a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 8px;
}
.error-page h1 {
  font-size: 26px;
  margin: 8px 0 12px;
  color: var(--text);
}
.error-page p {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 32px;
  line-height: 1.6;
}
.error-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.error-actions .btn {
  text-decoration: none;
  padding: 12px 28px;
  border-radius: 12px;
  font-weight: 600;
}
.error-actions .btn.primary {
  background: var(--primary);
  color: #fff;
}
.error-actions .btn.ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

@media (max-width: 768px) {
  .error-code { font-size: 72px; }
  .error-page h1 { font-size: 22px; }
}
/* ============================================================
   Mobile fixes
   ============================================================ */

/* جلوگیری از اسکرول افقی سراسری */
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* هر عنصری که ممکنه از عرض بیرون بزنه */
*, *::before, *::after {
  max-width: 100%;
}

img, video, pre, table, .files-table, .files-grid, .file-card {
  max-width: 100%;
}

pre {
  overflow-x: auto;
}

@media (max-width: 768px) {

  /* --- سایدبار: کامل مخفی --- */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    right: -100vw !important;
    width: 280px !important;
    max-width: 85vw !important;
    height: 100vh !important;
    z-index: 1000 !important;
    transition: right .25s ease !important;
    box-shadow: none !important;
    visibility: hidden;
  }
  .sidebar.open {
    right: 0 !important;
    visibility: visible;
    box-shadow: -8px 0 24px rgba(0,0,0,.15) !important;
  }

  /* --- layout --- */
  .layout {
    display: block !important;
    width: 100% !important;
    overflow-x: hidden;
  }
  .main {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden;
  }

  /* --- topbar --- */
  .topbar {
    padding: 0 12px !important;
    gap: 8px !important;
    height: 56px !important;
    width: 100% !important;
  }
  .search {
    min-width: 0 !important;
    flex: 1 1 auto !important;
  }
  .search input {
    width: 100% !important;
    min-width: 0 !important;
    font-size: 16px !important;
  }
  .user-id { display: none !important; }
  .topbar-actions { display: none !important; }

  /* --- content --- */
  .content {
    padding: 12px !important;
    padding-bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden;
  }

  /* --- crumb --- */
  .crumb {
    font-size: 16px !important;
    flex-wrap: wrap !important;
    word-break: break-all !important;
  }
  .crumb a, .crumb span {
    max-width: 100%;
  }

  /* --- toolbar --- */
  .toolbar {
    gap: 6px !important;
    flex-wrap: wrap !important;
  }
  .toolbar .tool span { display: none !important; }
  .toolbar .tool { padding: 8px !important; }
  .view-toggle { margin-right: 0 !important; }

  /* --- جدول: کارت‌های عمودی --- */
  .files-table {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    box-shadow: none !important;
    background: transparent !important;
  }
  .files-table thead { display: none !important; }
  .files-table tbody {
    display: block !important;
    width: 100% !important;
  }
  .files-table tr {
    display: block !important;
    width: 100% !important;
    background: var(--surface) !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px !important;
    margin-bottom: 8px !important;
    padding: 10px 12px !important;
    box-sizing: border-box !important;
  }
  .files-table td {
    display: block !important;
    width: 100% !important;
    border: none !important;
    padding: 2px 0 !important;
    box-sizing: border-box !important;
  }
  .files-table td.name {
    font-size: 15px !important;
    margin-bottom: 4px !important;
    word-break: break-all;
  }
  .files-table td.name svg {
    width: 22px !important;
    height: 22px !important;
  }
  .files-table td.muted { font-size: 12px !important; }
  .files-table .row-actions {
    justify-content: flex-start !important;
    flex-wrap: wrap !important;
    margin-top: 6px !important;
  }
  .files-table .row-actions button {
    width: 36px !important;
    height: 36px !important;
  }

  /* --- grid --- */
  .files-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    width: 100% !important;
  }
  .file-card {
    min-width: 0 !important;
    width: 100% !important;
  }
  .file-card .title { font-size: 12px !important; }

  /* --- modal --- */
  .modal-backdrop { padding: 0 !important; align-items: flex-end !important; }
  .modal {
    border-radius: 20px 20px 0 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    max-height: 88vh !important;
  }
  .modal-body input,
  .modal-body select,
  .modal-body textarea {
    font-size: 16px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  /* --- shared section --- */
  .shared-grid { grid-template-columns: 1fr !important; }
  .shared-card { width: 100% !important; box-sizing: border-box !important; }
  .shared-card-name { word-break: break-all; }

  /* --- snackbar --- */
  .snackbar-container {
    left: 8px !important;
    right: 8px !important;
    bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    max-width: none !important;
  }

  /* --- upload panel --- */
  .upload-panel {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    bottom: 0 !important;
    border-radius: 16px 16px 0 0 !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
  }

  /* --- fab --- */
  .fab {
    bottom: calc(20px + env(safe-area-inset-bottom)) !important;
    left: 16px !important;
  }
}

/* --- گوشی خیلی کوچیک --- */
@media (max-width: 400px) {
  .files-grid { grid-template-columns: 1fr !important; }
  .crumb { font-size: 14px !important; }
}
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 999;
  display: none;
}
.sidebar-overlay.visible { display: block; }

/* ﮒﺮﯾﺩ ﭗﯿﺷ<200c>ﻓﺮﺿ ﻢﺨﻔﯾ — ﺕﺍ ﻮﻘﺘﯾ JS ﻉﻮﻀﺷ ﮏﻨﻫ */
#view-grid {
  display: none !important;
}
