/* FileShare - RTL styling */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --muted: #64748b;
  --text: #0f172a;
  --border: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

img, svg, video, canvas { max-width: 100%; height: auto; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

body.guest-page { overflow-x: hidden; }

body:not(.guest-page) { display: flex; flex-direction: column; }
body:not(.guest-page) main.container { flex: 1 0 auto; }

.topbar {
  background: linear-gradient(90deg, #1e293b, #0f172a);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1150px;
  margin: 0 auto;
  padding: 8px 20px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px; display: inline-flex;
  align-items: center; justify-content: center; font-size: 18px;
  background: rgba(255,255,255,.14);
}
img.logo { object-fit: cover; }
.topnav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.menu-toggle {
  display: none; align-items: center; gap: 8px;
  background: rgba(255,255,255,.12); color: #fff; border: 1px solid rgba(255,255,255,.25);
  border-radius: 9px; padding: 8px 12px; font-size: 14px; font-weight: 600; font-family: inherit; cursor: pointer;
}
.menu-toggle:hover { background: rgba(255,255,255,.2); }
.menu-toggle .bars { font-size: 17px; line-height: 1; }
.app-install-btn { cursor: pointer; font-family: inherit; }
.app-install-btn[hidden] { display: none; }
.site-install-btn {
  background: rgba(255,255,255,.12); color: #e2e8f0; border: 1px solid rgba(255,255,255,.25);
  border-radius: 8px; padding: 6px 12px; font-size: 12px; cursor: pointer;
}
.site-install-btn:hover { background: rgba(255,255,255,.2); color: #fff; }
.topnav a.topnav-link {
  color: #cbd5e1; padding: 7px 12px; border-radius: 8px; font-size: 14px; font-weight: 500;
}
.topnav a.topnav-link:hover { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.topnav a.topnav-link.active { background: var(--primary); color: #fff; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #e2e8f0; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
}
.role-badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: rgba(255,255,255,.15); }

.container { width: 100%; max-width: 1150px; margin: 0 auto; padding: 24px 20px 60px; }
.page-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.page-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.action-row { display: flex; gap: 8px; align-items: center; flex-wrap: nowrap; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: 9px; font-size: 14px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; transition: .15s ease; line-height: 1.2;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }
.btn-outline { background: #fff; color: var(--muted); border-color: var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }

.form-group { margin-bottom: 16px; }
label.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #334155; }
.form-control {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 14px; color: var(--text); background: #fff; transition: border .15s, box-shadow .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
textarea.form-control { resize: vertical; min-height: 90px; }
select.form-control { appearance: auto; }
.form-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

.btn-danger-outline { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger); color: #fff; text-decoration: none; }
.btn-success-outline { background: #fff; color: var(--success); border-color: var(--success); }
.btn-success-outline:hover { background: var(--success); color: #fff; text-decoration: none; }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: right; padding: 11px 12px; background: #f8fafc; border-bottom: 2px solid var(--border);
  color: #475569; font-size: 12.5px; white-space: nowrap;
}
.table td { padding: 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; overflow-wrap: anywhere; }
.table tbody tr:hover { background: #f8fafc; }
.table .actions { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
  border-radius: 99px; font-size: 12px; font-weight: 600;
}
.badge-blue { background: var(--primary-light); color: var(--primary-dark); }
.badge-green { background: var(--success-light); color: #15803d; }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-gray { background: #f1f5f9; color: var(--muted); }
.badge-amber { background: var(--warning-light); color: #b45309; }

.file-icon {
  width: 42px; height: 42px; border-radius: 10px; display: inline-flex;
  align-items: center; justify-content: center; font-weight: 800; font-size: 14px; flex-shrink: 0;
}
.ext-image { background: #dcfce7; color: #15803d; }
.ext-pdf { background: #fee2e2; color: #b91c1c; }
.ext-word { background: #dbeafe; color: #1d4ed8; }
.ext-excel { background: #bbf7d0; color: #166534; }
.ext-text { background: #f1f5f9; color: #475569; }
.ext-arch { background: #fef3c7; color: #b45309; }
.ext-other { background: #ede9fe; color: #6d28d9; }

.alert { padding: 12px 16px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: var(--success-light); color: #15803d; border-color: #bbf7d0; }
.alert-error, .alert-danger { background: var(--danger-light); color: #b91c1c; border-color: #fecaca; }
.alert-info { background: var(--primary-light); color: #1d4ed8; border-color: #bfdbfe; }

.error-list { padding: 12px 16px; border-radius: 10px; background: var(--danger-light); border: 1px solid #fecaca; margin-bottom: 14px; }
.error-list ul { padding-right: 18px; color: #b91c1c; font-size: 13.5px; }
.error-list li { margin: 3px 0; }

.flash { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px);} to { opacity: 1; transform: none; } }

.search-form { display: flex; gap: 8px; max-width: 420px; }
.search-form .form-control { flex: 1; }

.empty {
  text-align: center; padding: 48px 20px; color: var(--muted);
}
.empty .empty-icon { font-size: 42px; margin-bottom: 10px; }
.empty h3 { color: var(--text); margin-bottom: 6px; font-size: 16px; }

.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(135deg, #1e293b 0%, #2563eb 100%); width: 100vw; margin-left: calc(50% - 50vw); margin-right: calc(50% - 50vw); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 32px; box-shadow: var(--shadow-lg); }
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 22px; font-size: 20px; font-weight: 800; color: var(--text); }
.auth-card h1 { font-size: 19px; text-align: center; margin-bottom: 6px; }
.auth-sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 22px; }

.upload-drop {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 30px;
  text-align: center; color: var(--muted); transition: .2s; cursor: pointer; background: #fafbfc;
}
.upload-drop:hover, .upload-drop.dragover { border-color: var(--primary); background: var(--primary-light); }
.upload-drop .big { font-size: 40px; margin-bottom: 8px; }
.upload-drop strong { color: var(--text); }

.dropdown-check { display: flex; flex-direction: column; gap: 8px; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; background: #fafbfc; }
.check-row:hover { border-color: #cbd5e1; }
.check-row input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--primary); }
.check-row label { flex: 1; font-size: 14px; font-weight: 500; cursor: pointer; }
.check-sub { font-size: 12px; color: var(--muted); }

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 13px;
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.pagination span.current { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination span.disabled { opacity: .5; }

.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }

.site-footer { background: linear-gradient(90deg, #1e293b, #0f172a); color: #cbd5e1; margin-top: 40px; }
.site-footer-inner { max-width: 1150px; margin: 0 auto; padding: 26px 20px; }
.site-footer-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-bottom: 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.site-footer-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: #fff; }
.site-footer-brand:hover { text-decoration: none; }
.site-footer-brand .logo { width: 32px; height: 32px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; font-size: 17px; background: rgba(255,255,255,.14); }
.site-footer-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.site-footer-nav a { color: #cbd5e1; padding: 6px 10px; border-radius: 8px; font-size: 13px; }
.site-footer-nav a:hover { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.site-footer-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 16px; font-size: 12px; color: #94a3b8; }
.site-footer-bottom a { color: #e2e8f0; font-weight: 600; }
.site-footer-bottom a:hover { color: #fff; }

@media (max-width: 640px) {
  .site-footer-top, .site-footer-bottom { flex-direction: column; text-align: center; }
  .site-footer-nav { justify-content: center; }
}

body.guest-page .site-footer { margin-top: 0; }

.file-meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 12px 0 18px; }
.file-meta span { display: inline-flex; align-items: center; gap: 6px; }

.breadcrumbs { font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.breadcrumbs a { color: var(--primary); }
.breadcrumbs .sep { color: #cbd5e1; margin: 0 6px; }

.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.folder-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  transition: .15s ease;
}
.folder-card:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); text-decoration: none; }
.folder-icon { font-size: 30px; line-height: 1; flex-shrink: 0; }
.folder-info { display: flex; flex-direction: column; min-width: 0; }
.folder-info strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-card-static { flex-direction: column; align-items: stretch; }
.folder-open { display: flex; align-items: center; gap: 12px; color: var(--text); }
.folder-open:hover { text-decoration: none; }
.folder-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }

.new-folder-form { display: flex; gap: 8px; margin-bottom: 16px; max-width: 520px; }
.new-folder-form .form-control { flex: 1; }

/* View mode toggle (grid / rows) */
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: #fff; }
.view-toggle button {
  border: 0; background: #fff; color: var(--muted); cursor: pointer;
  padding: 9px 12px; font-size: 14px; font-weight: 600; line-height: 1;
  display: inline-flex; align-items: center; gap: 6px;
}
.view-toggle button + button { border-inline-start: 1px solid var(--border); }
.view-toggle button:hover { color: var(--primary); }
.view-toggle button.active { background: var(--primary); color: #fff; }

/* Rows mode: folder cards become a compact list */
.browse-view.view-rows .folder-grid { display: flex; flex-direction: column; gap: 8px; }
.browse-view.view-rows .folder-card,
.browse-view.view-rows .folder-card-static { flex-direction: row; align-items: center; justify-content: space-between; padding: 10px 14px; }
.browse-view.view-rows .folder-actions { margin-top: 0; margin-inline-start: auto; }

/* Grid mode: file tables become cards */
.browse-view.view-grid .table-wrap { overflow: visible; }
.browse-view.view-grid table.table { display: block; border-collapse: separate; }
.browse-view.view-grid .table thead { display: none; }
.browse-view.view-grid .table tbody {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr)); gap: 12px;
}
.browse-view.view-grid .table tbody tr {
  display: flex; flex-direction: column; gap: 10px; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--card);
  box-shadow: var(--shadow); transition: .15s ease;
}
.browse-view.view-grid .table tbody tr:hover { background: var(--card); border-color: var(--primary); box-shadow: var(--shadow-lg); }
.browse-view.view-grid .table td { display: block; padding: 0; border: 0; max-width: none !important; font-size: 13px; color: var(--muted); }
.browse-view.view-grid .table td:first-child { color: var(--text); }
.browse-view.view-grid .table td .actions { margin-top: 4px; }

.stat { text-align: center; padding: 18px; }
.stat .value { font-size: 26px; font-weight: 800; color: var(--text); }
.stat .label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.alert-info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

.doc-statusbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 6px 0 10px; flex-wrap: wrap; }
.presence { font-size: 13px; color: var(--muted); }

.doc-toolbar {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; margin-bottom: 10px; position: sticky; top: 64px; z-index: 10;
}
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

.doc-editor {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 28px 32px; min-height: 70vh; line-height: 1.9; font-size: 16px; outline: none;
}
.doc-editor:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.doc-editor h1 { font-size: 26px; margin: 14px 0 10px; }
.doc-editor h2 { font-size: 21px; margin: 12px 0 8px; }
.doc-editor p { margin: 8px 0; }
.doc-editor ul, .doc-editor ol { padding-inline-start: 28px; margin: 8px 0; }
.doc-editor table { border-collapse: collapse; margin: 10px 0; }
.doc-editor table td, .doc-editor table th { border: 1px solid var(--border); padding: 6px 10px; }

.sheet-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.sheet-tab {
  border: 1px solid var(--border); border-bottom: none; background: #f8fafc;
  padding: 6px 14px; border-radius: 8px 8px 0 0; cursor: pointer; font-size: 13px;
}
.sheet-tab.active { background: #fff; font-weight: 700; color: var(--primary); }
.sheet-wrap { overflow: auto; max-height: 72vh; border: 1px solid var(--border); border-radius: 0 10px 10px 10px; background: #fff; }
.sheet-grid { direction: ltr; }
.sheet-table { border-collapse: collapse; font-size: 13px; }
.sheet-table th, .sheet-table td { border: 1px solid #e5e7eb; min-width: 96px; height: 28px; padding: 2px 6px; }
.sheet-colhead, .sheet-rowhead, .sheet-corner { background: #f1f5f9; color: var(--muted); font-weight: 600; text-align: center; min-width: 44px; }
.sheet-colhead { position: sticky; top: 0; z-index: 2; }
.sheet-rowhead, .sheet-corner { position: sticky; inset-inline-start: 0; z-index: 2; }
.sheet-corner { top: 0; left: 0; z-index: 3; }
.sheet-cell { background: #fff; }
.sheet-cell:focus { outline: 2px solid var(--primary); outline-offset: -2px; background: #fffbeb; }
.sheet-cell.active { outline: 2px solid var(--primary); outline-offset: -2px; background: #fffbeb; }
.sheet-cell[contenteditable="false"] { background: #f8fafc; }

/* ============================================================
   Responsive layout — large screens, tablets and phones
   ============================================================ */

/* Large desktop screens: use more of the available width */
@media (min-width: 1400px) {
  .container,
  .topbar-inner,
  .site-footer-inner { max-width: 1320px; }
}

/* Tablets / small laptops: let the header wrap instead of overflow */
@media (max-width: 992px) {
  .topnav { order: 3; width: 100%; justify-content: center; }
  .user-chip { margin-inline-start: auto; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .doc-toolbar { position: static; }
}

/* Phones / small tablets: collapsible mobile menu */
@media (max-width: 768px) {
  .topbar-inner { row-gap: 10px; }
  .menu-toggle { display: inline-flex; }
  .topbar-inner [data-menu-panel] { display: none; }
  .topbar-inner.menu-open [data-menu-panel] { display: flex; }
  .topbar-inner.menu-open .topnav {
    order: 3; width: 100%; flex-direction: column; align-items: stretch; gap: 4px;
    padding-top: 8px; margin-top: 2px; border-top: 1px solid rgba(255,255,255,.14);
  }
  .topbar-inner.menu-open .topnav a.topnav-link { width: 100%; text-align: center; }
  .topbar-inner.menu-open .user-chip {
    order: 4; width: 100%; justify-content: center; flex-wrap: wrap; margin-inline-start: 0;
  }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .container { padding: 18px 16px 44px; }
  .card { padding: 16px; }
  .doc-editor { padding: 22px 20px; }
  .sheet-wrap { max-height: 64vh; }
}

@media (max-width: 640px) {
  .topbar-inner { padding: 10px 16px; }
  .topnav a.topnav-link { padding: 9px 10px; font-size: 13.5px; }
  .container { padding: 16px 14px 40px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .page-head > div:last-child { width: 100%; }
  .page-title { font-size: 20px; }

  /* keep upload file / upload folder / grid / rows on a single row */
  .page-head-actions { width: 100%; }
  .action-row { width: 100%; gap: 6px; }
  .action-row > .btn { flex: 1 1 0; min-width: 0; padding: 8px 6px; font-size: 12px; white-space: nowrap; }
  .action-row > .view-toggle { flex: 1 1 0; min-width: 0; }
  .action-row > .view-toggle button { flex: 1 1 0; min-width: 0; padding: 8px 4px; font-size: 12px; white-space: nowrap; }
  .page-head-actions > .search-form { flex: 1 1 100%; order: 10; }

  .search-form { max-width: 100%; flex-wrap: wrap; }
  .search-form .form-control { flex: 1 1 100%; }
  .search-form .btn { flex: 1 1 auto; }

  .new-folder-form { flex-direction: column; max-width: 100%; }
  .new-folder-form .btn { width: 100%; }

  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }

  .card-title { flex-wrap: wrap; }
  .table th, .table td { padding: 10px 8px; }

  .auth-page { padding: 16px; }
  .auth-card { padding: 24px; border-radius: 14px; }

  .doc-editor { padding: 18px 15px; font-size: 15px; min-height: 60vh; }
  .doc-editor h1 { font-size: 22px; }
  .doc-editor h2 { font-size: 19px; }
  .sheet-table th, .sheet-table td { min-width: 76px; }
}

@media (max-width: 380px) {
  .topnav a.topnav-link { padding: 6px 8px; font-size: 12.5px; }
  .btn { font-size: 13px; padding: 9px 12px; }
}