:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --border: #e0e0e0;
  --text: #333333;
  --muted: #6b7280;
  --accent: #ff8c00;
  --accent-hover: #f57c00;
  --link: #4299e1;
  --link-hover: #2b6cb0;
  --danger: #dc2626;
  --ok: #2e7d32;
  --radius: 10px;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.08);
  --font: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background-color: var(--bg);
}

body { direction: rtl; }

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

.shell {
  width: min(920px, calc(100% - 24px));
  margin: 0 auto;
  padding: 20px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.brand {
  font-weight: 700;
  font-size: 1.2rem;
  color: #111;
}

.brand span {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  margin-top: 2px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 24px 16px;
}

.login-card {
  width: min(420px, 100%);
  margin-top: 12px;
}

.brand-bar {
  width: 100%;
  box-sizing: border-box;
  background-color: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 14px;
  text-align: center;
  line-height: 1.35;
  font-size: 1.28em;
  font-weight: 700;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 1.35rem;
  text-align: center;
}

.login-card p.lead {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
  text-align: center;
  font-size: 0.95rem;
}

label {
  display: block;
  font-size: 0.92rem;
  margin: 0 0 6px;
  color: #4b5563;
  font-weight: 600;
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="number"],
input[type="search"],
select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: var(--text);
  font: inherit;
  margin-bottom: 12px;
}

select {
  cursor: pointer;
}

input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.35);
  border-color: #2563eb;
}

.password-field {
  position: relative;
  margin-bottom: 12px;
}

.password-field input {
  margin-bottom: 0;
  padding-inline-end: 44px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  inset-inline-end: 6px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  color: #4b5563;
  display: grid;
  place-items: center;
  padding: 0;
}

.password-toggle:hover {
  background: #f3f4f6;
  color: #111827;
}

.password-toggle[aria-pressed="true"] {
  color: #e65100;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 6px;
  padding: 11px 15px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: background-color 0.2s, transform 0.1s;
}

.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.65; cursor: not-allowed; }

.btn-ghost {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn-ghost:hover { background: #f8f8f8; }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.msg {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
  display: none;
}

.msg.show { display: block; }
.msg.error { background: #fee2e2; color: #991b1b; }
.msg.ok { background: #e8f5e9; color: #1b5e20; }
.msg.info { background: #e3f2fd; color: #1565c0; }

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: nowrap;
  align-items: stretch;
}

.tab {
  flex: 1 1 0;
  min-width: 0;
  padding: 9px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: #333;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab.active {
  border-color: #ffcc80;
  background: #ffe0b2;
  color: #e65100;
}

.tab-home {
  flex: 0 0 auto;
  margin-inline-start: 0;
  background: #f3f4f6;
  color: #111827;
  font-weight: 600;
  padding-inline: 10px;
}

.tab-home:hover {
  background: #e5e7eb;
}

.tab-short { display: none; }
.tab-full { display: inline; }

@media (max-width: 520px) {
  .tabs { gap: 4px; }
  .tab {
    padding: 8px 4px;
    font-size: 0.78rem;
    border-radius: 8px;
    overflow: visible;
    text-overflow: clip;
  }
  .tab-home {
    padding-inline: 8px;
    font-size: 0.78rem;
  }
  .tab-home .home-label { display: none; }
  .tab-full { display: none; }
  .tab-short { display: inline; }
}

.panel { display: none; }
.panel.active { display: block; }

.grid-2 {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 14px;
}

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.upload-zone {
  border: 1px dashed #ffab91;
  border-radius: var(--radius);
  padding: 18px;
  background: #fff7f5;
  text-align: center;
}

.upload-zone strong {
  display: block;
  margin-bottom: 8px;
  font-size: 1.08rem;
}

.muted { color: var(--muted); font-size: 0.9rem; }

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 12px;
  font-size: 0.92rem;
}

.breadcrumb button {
  background: none;
  border: none;
  color: var(--link);
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.list .meta {
  min-width: 0;
  flex: 1;
}

.list .name {
  font-weight: 600;
  word-break: break-word;
}

.list .sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.actions .btn {
  padding: 8px 10px;
  font-size: 0.85rem;
}

.preview {
  margin-top: 14px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f8fafc;
  min-height: 160px;
  display: grid;
  place-items: center;
}

.preview img,
.preview iframe {
  width: 100%;
  max-height: 70vh;
  border: 0;
  display: block;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.table th,
.table td {
  text-align: right;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table th { color: var(--muted); font-weight: 600; }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #f3f4f6;
}

.badge.owner { background: #ffe0b2; color: #e65100; }
.badge.viewer { background: #e3f2fd; color: #1565c0; }
.badge.admin { background: #eee; color: #333; }
.badge.suspended { background: #fee2e2; color: #991b1b; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

@media (max-width: 700px) {
  .stat-row { grid-template-columns: 1fr; }
}

.stat {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.stat .v {
  font-size: 1.2rem;
  font-weight: 700;
}

.stat .k {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 4px;
}

.quota-bar {
  height: 8px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 4px;
}

.quota-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.quota-bar.warn > span { background: #f59e0b; }
.quota-bar.full > span { background: var(--danger); }

.hidden { display: none !important; }

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.switch input { width: auto; margin: 0; }

.remember-row {
  margin: 4px 0 14px;
  font-size: 0.9rem;
  color: #4b5563;
  font-weight: 500;
}

.files-toolbar {
  margin-bottom: 12px;
  min-height: 0;
}

.bottom-bar .btn-back {
  background: #e8eaed !important;
  color: #111827 !important;
  border-color: #d1d5db !important;
}

.bottom-bar .btn-back:hover {
  background: #dde0e4 !important;
  color: #111827 !important;
}

.shell-with-bottom {
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
}

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: center;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  background: #ffffff;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}

.bottom-bar .btn {
  width: 100%;
  min-width: 0;
  margin: 0;
}

.bottom-bar .btn.is-slot-hidden {
  visibility: hidden;
  pointer-events: none;
}

.list li.file-row {
  align-items: flex-start;
}

.file-check {
  margin: 6px 0 0;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.select-all-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  font-size: 0.95rem;
  font-weight: 600;
  color: #111827;
  cursor: pointer;
  user-select: none;
}

.select-all-row.hidden {
  display: none !important;
}

.select-all-row .file-check {
  margin: 0;
}

.thumb-wrap {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f3f4f6;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-wrap .pdf-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: #b91c1c;
}

.bottom-bar .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#header-back-btn {
  display: none !important;
}

.btn-back {
  background: #e8eaed !important;
  color: #111827 !important;
  border: 1px solid #d1d5db !important;
  box-shadow: none;
  font-weight: 600;
}

.btn-back:hover {
  background: #dde0e4 !important;
  color: #111827 !important;
}

.btn-back:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.consent-note {
  margin: 16px 0 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #6b7280;
  text-align: center;
}

.consent-note a {
  color: #4299e1;
  font-weight: 600;
  text-decoration: underline;
}

.terms-shell { max-width: 820px; }
.terms-card h2 {
  margin: 22px 0 10px;
  font-size: 1.15rem;
  color: #111;
}
.terms-card h3 {
  margin: 14px 0 6px;
  font-size: 1rem;
}
.terms-body {
  font-size: 0.92rem;
  line-height: 1.55;
  color: #374151;
}
.terms-body ul { padding-right: 18px; }
.terms-pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
  font-size: 0.86rem;
  line-height: 1.5;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  max-height: 55vh;
  overflow: auto;
  color: #1f2937;
}

.homescreen-tip,
.homescreen-tip.show { display: none !important; }

.home-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 52px;
  padding: 14px 16px;
  font-size: 1.05rem;
  font-weight: 500;
  color: #333;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  text-align: right;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.home-item:hover { background: #f8f8f8; }
