:root {
  --bg: #F7F4EE;
  --sidebar-bg: #0D0D0D;
  --sidebar-hover: #1C1C1C;
  --sidebar-text: #B9B9B4;
  --accent: #E8622C;
  --accent-light: #FCEBE2;
  --card-bg: #FFFFFF;
  --border: #E9E4D8;
  --text: #1A1A18;
  --text-muted: #8E8B82;
  --danger: #E15353;
  --danger-bg: #FBE3E3;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 18, 14, 0.04), 0 8px 20px rgba(20, 18, 14, 0.04);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Tajawal', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

button, input { font-family: inherit; }

/* ---------- Login ---------- */

.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px 28px 24px;
}

.login-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
}

.login-head h1 {
  font-size: 20px;
  font-weight: 700;
}

.login-head p {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.lock-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.field {
  position: relative;
  display: block;
  margin-bottom: 14px;
}

.field input {
  width: 100%;
  height: 48px;
  padding: 0 42px 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #FCFBF8;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color .15s ease;
}

.field input:focus { border-color: var(--accent); background: #fff; }

.field svg { position: absolute; top: 15px; right: 14px; }

.icon-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
}

.login-error {
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  height: 48px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s ease;
}

.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { filter: brightness(0.95); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-block { width: 100%; }

.login-foot {
  text-align: center;
  margin-top: 22px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  min-height: 100dvh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
}

.sidebar-top { padding: 0 8px 22px; }
.sidebar-top h2 { font-size: 17px; font-weight: 800; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: background .15s ease, color .15s ease;
}

.nav-item svg { color: inherit; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-hover); color: #fff; }

.sidebar-logout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: none;
  border: none;
  color: var(--sidebar-text);
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
}
.sidebar-logout:hover { background: var(--sidebar-hover); color: #fff; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 32px 8px;
}

.topbar h1 { font-size: 22px; font-weight: 800; }
.topbar-spacer { flex: 1; }

.view-root {
  flex: 1;
  padding: 16px 32px 32px;
  overflow-y: auto;
}

.mobile-only { display: none; }

/* ---------- Shared components ---------- */

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  height: 46px;
  margin-bottom: 18px;
}

.search-bar input {
  border: none;
  outline: none;
  background: none;
  flex: 1;
  font-size: 14px;
  color: var(--text);
}

.search-bar svg { color: var(--text-muted); flex-shrink: 0; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.banner {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.banner h3 { font-size: 17px; font-weight: 700; }
.banner p { margin-top: 4px; font-size: 13px; opacity: .9; }

.banner-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.quick-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  border: none;
  text-align: right;
  font-family: inherit;
}

.quick-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.quick-icon.blue { background: #E4EEFB; color: #3B7FD1; }
.quick-icon.green { background: #E3F5EA; color: #2FA362; }

.quick-card h4 { font-size: 14px; font-weight: 700; }
.quick-card span.desc { font-size: 12px; color: var(--text-muted); }

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.list-header h3 { font-size: 15px; font-weight: 700; }

.count-pill {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
}

.row-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  border: none;
  width: 100%;
  text-align: right;
  font-family: inherit;
}

.row-item:active { filter: brightness(0.98); }

.row-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.row-icon.folder { background: var(--accent); }
.row-icon.book { background: #3B7FD1; }

.row-body { flex: 1; min-width: 0; }
.row-title { font-size: 14px; font-weight: 700; margin-bottom: 2px; }
.row-sub { font-size: 12px; color: var(--text-muted); }

.row-chev { color: var(--text-muted); flex-shrink: 0; }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: 12px; opacity: .5; }
.empty-state p { font-size: 14px; }

.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.breadcrumbs button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
}
.breadcrumbs button.current { color: var(--text); font-weight: 700; }
.breadcrumbs button:hover { color: var(--accent); }

.loading-spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Book detail */

.book-detail-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}

.book-detail-card h2 { font-size: 18px; font-weight: 800; margin-bottom: 16px; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 20px;
}

.detail-field label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.detail-field div { font-size: 14px; font-weight: 500; }

.attachment-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.attachment-item .row-body { flex: 1; }
.attachment-item .row-title { font-size: 13px; }

.download-btn {
  background: var(--accent-light);
  color: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.download-btn:disabled { opacity: .5; cursor: wait; }

/* Search tabs */

.tab-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.tab-btn {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
}
.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.snippet {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.6;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .sidebar { display: none; }
  .mobile-only { display: flex; }

  .topbar { padding: 18px 18px 6px; }
  .topbar h1 { font-size: 18px; }
  .view-root { padding: 12px 16px 90px; }

  .quick-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }

  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--sidebar-bg);
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-around;
    z-index: 10;
  }

  .bn-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 11px;
    padding: 6px 14px;
    border-radius: 10px;
  }
  .bn-item.active { color: var(--accent); }
}
