:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #eef3fb;
  --text: #17212b;
  --muted: #667582;
  --line: #dce4ea;
  --primary: #0428af;
  --primary-2: #234fd4;
  --accent: #3867f0;
  --success: #17875f;
  --warning: #b7791f;
  --danger: #c2413b;
  --shadow: 0 18px 45px rgba(18, 36, 48, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Tajawal", system-ui, sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

body.dark {
  --bg: #101820;
  --surface: #16232c;
  --surface-soft: #1a253d;
  --text: #edf4f7;
  --muted: #a7b7c1;
  --line: #2c424e;
  --primary: #8fa8ff;
  --primary-2: #6f8df5;
  --accent: #9ab2ff;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px;
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  display: block;
  width: 112px;
  max-width: 100%;
  height: auto;
  object-fit: contain;
}

body.dark .brand-logo {
  filter: brightness(1.35) saturate(1.1);
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.section-label,
.stat-card span,
.stat-card small,
.activity-item small,
.file-meta,
.user-role,
.security-card p,
.feature-panel p,
.drop-zone span {
  color: var(--muted);
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: right;
  padding: 13px 14px;
  border-radius: 8px;
  transition: 0.18s ease;
}

.nav-item.active,
.nav-item:hover {
  color: var(--primary);
  background: var(--surface-soft);
}

.security-card {
  margin-top: auto;
  display: flex;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.status-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  margin-top: 8px;
  border-radius: 50%;
  background: var(--primary-2);
  box-shadow: 0 0 0 5px rgba(4, 40, 175, 0.12);
}

.main-content {
  padding: 24px;
  min-width: 0;
}

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

.mobile-menu {
  display: none;
}

.page-title span,
.section-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary-2);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 3vw, 2.25rem);
}

h2 {
  font-size: 1.16rem;
}

.top-actions,
.workspace-toolbar,
.panel-heading,
.modal-header,
.login-form {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.ghost-button,
.text-button,
.icon-button,
.login-form button,
.segmented-control button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 16px;
}

.primary-button,
.login-form button {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.ghost-button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.text-button {
  background: transparent;
  color: var(--primary-2);
  font-weight: 700;
}

.icon-button {
  width: 42px;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
}

.icon-button.compact {
  width: 36px;
  min-height: 36px;
}

.login-panel,
.panel,
.stat-card,
.file-row,
.user-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  margin-bottom: 18px;
}

.login-form {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
}

.login-form input,
.workspace-toolbar input,
.workspace-toolbar select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  padding: 18px;
}

.stat-card strong {
  display: block;
  margin: 8px 0;
  font-size: 2rem;
}

.dashboard-grid,
.files-layout,
.security-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 16px;
}

.activity-list,
.recent-files,
.file-table,
.users-grid,
.upload-preview {
  display: grid;
  gap: 10px;
}

.activity-item,
.recent-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.activity-item strong,
.activity-item small {
  display: block;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(4, 40, 175, 0.1);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.workspace-toolbar {
  flex-wrap: wrap;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.search-box {
  flex: 1 1 280px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  padding: 0;
  background: transparent;
}

.files-layout {
  grid-template-columns: 320px minmax(0, 1fr);
}

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

.tree {
  max-height: 620px;
  overflow: auto;
  padding-left: 4px;
}

.tree ul {
  margin-right: 16px;
  border-right: 1px solid var(--line);
}

.tree-node {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: right;
  padding: 9px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tree-node:hover,
.tree-node.open {
  background: var(--surface-soft);
}

.tree-node.selected {
  color: var(--primary);
  background: rgba(4, 40, 175, 0.1);
  font-weight: 800;
}

.company-node {
  margin-top: 6px;
  color: var(--primary);
  font-weight: 800;
}

.tree-arrow,
.tree-spacer {
  display: inline-grid;
  place-items: center;
  width: 18px;
  flex: 0 0 18px;
  color: var(--primary-2);
}

.tree-node:not(.open) .tree-arrow {
  transform: rotate(90deg);
}

.segmented-control {
  display: flex;
  padding: 4px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.segmented-control button {
  min-height: 34px;
  background: transparent;
  color: var(--muted);
}

.segmented-control .active {
  background: var(--surface);
  color: var(--primary);
}

.file-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(4, minmax(90px, auto)) minmax(210px, auto);
  align-items: center;
  gap: 12px;
  padding: 14px;
  box-shadow: none;
}

.file-name strong,
.file-name span {
  display: block;
}

.file-meta {
  font-size: 0.9rem;
}

.file-actions {
  display: flex;
  gap: 8px;
}

.danger-action {
  color: var(--danger);
}

.file-table.grid-view {
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}

.file-table.grid-view .file-row {
  grid-template-columns: 1fr;
  align-items: stretch;
}

.file-table.grid-view .file-actions {
  margin-top: 4px;
}

.empty-state {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
}

.users-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.user-card {
  padding: 16px;
  box-shadow: none;
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin-bottom: 12px;
  border-radius: 8px;
  color: #fff;
  background: var(--primary-2);
  font-weight: 800;
}

.user-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.small-action {
  flex: 1;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-soft);
}

.security-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.feature-panel {
  min-height: 160px;
}

.feature-panel h2 {
  color: var(--primary-2);
  margin-bottom: 12px;
}

.upload-modal {
  width: min(640px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: auto;
}

.upload-modal::backdrop {
  background: rgba(13, 26, 36, 0.45);
}

.upload-modal form {
  padding: 18px;
}

.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 180px;
  margin: 16px 0;
  border: 1.5px dashed var(--primary-2);
  border-radius: 8px;
  background: var(--surface-soft);
  text-align: center;
}

.drop-zone.dragging {
  outline: 4px solid rgba(4, 40, 175, 0.16);
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.preview-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.file-preview-box {
  min-height: 220px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.file-preview-image {
  display: block;
  max-width: 100%;
  max-height: 65dvh;
  margin: auto;
  border-radius: 8px;
}

.file-preview-frame {
  width: 100%;
  height: 65dvh;
  border: 0;
  border-radius: 8px;
  background: var(--surface);
}

.generated-preview {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 220px;
  text-align: center;
  color: var(--muted);
}

.generated-preview strong {
  color: var(--text);
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.progress span {
  display: block;
  height: 100%;
  width: var(--progress, 0%);
  background: var(--success);
  transition: width 0.3s ease;
}

.full-width {
  width: 100%;
}

.auth-screen {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(135deg, rgba(245, 247, 250, 0.96), rgba(229, 238, 243, 0.96));
}

body.dark .auth-screen {
  background: linear-gradient(135deg, rgba(16, 24, 32, 0.96), rgba(25, 40, 48, 0.96));
}

.auth-screen.hidden {
  display: none;
}

.auth-card {
  width: min(460px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-logo {
  width: min(212px, 70vw);
  margin-bottom: 16px;
}

.auth-card h1 {
  margin: 4px 0 10px;
}

.auth-card p {
  color: var(--muted);
}

.auth-form,
.password-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.auth-form label,
.password-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-form input,
.password-form input,
.password-form select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

.check-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.check-row input {
  width: 18px;
  height: 18px;
  min-height: auto;
}

.form-message {
  min-height: 22px;
  color: var(--danger);
  font-weight: 700;
}

.demo-users {
  display: grid;
  gap: 7px;
  margin-top: 18px;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
}

.demo-users strong {
  color: var(--text);
}

.session-badge {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--primary);
  font-weight: 800;
  white-space: nowrap;
}

.permission-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.permission-mini {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.small-action:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

@media (max-width: 1100px) {
  .stats-grid,
  .users-grid,
  .security-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .files-layout {
    grid-template-columns: 1fr;
  }

  .folder-tree {
    order: 2;
  }
}

@media (max-width: 780px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 10;
    inset-block: 0;
    inset-inline-end: 0;
    width: min(310px, 86vw);
    height: 100dvh;
    overflow-y: auto;
    transform: translateX(110%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    padding: 16px;
  }

  .mobile-menu {
    display: inline-grid;
    place-items: center;
    width: 42px;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
  }

  .topbar,
  .login-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .login-form {
    justify-content: stretch;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .session-badge {
    grid-column: 1 / -1;
    justify-content: center;
    white-space: normal;
    text-align: center;
  }

  .top-actions > *,
  .login-form label,
  .login-form button,
  .workspace-toolbar > * {
    flex: 1 1 auto;
  }

  .file-row {
    grid-template-columns: 1fr;
  }

  .file-actions {
    flex-wrap: wrap;
  }

  .permission-strip {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .stats-grid,
  .users-grid,
  .security-grid {
    grid-template-columns: 1fr;
  }

  .panel-heading,
  .modal-header {
    align-items: stretch;
    flex-direction: column;
  }

  .auth-screen {
    align-items: start;
    overflow-y: auto;
  }

  .auth-card {
    padding: 20px;
  }

  .workspace-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .search-box {
    flex-basis: auto;
  }

  .user-actions {
    flex-direction: column;
  }

  .activity-item,
  .recent-file,
  .preview-item {
    align-items: stretch;
    flex-direction: column;
    display: flex;
  }
}

@media (max-width: 420px) {
  .main-content {
    padding: 12px;
  }

  .top-actions {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .ghost-button,
  .text-button,
  .login-form button,
  .segmented-control button {
    width: 100%;
  }

  .panel,
  .stat-card,
  .login-panel {
    padding: 14px;
  }

  .segmented-control {
    width: 100%;
  }
}
