/* Shared styling for the document archive app - fixed header, profile
   dropdown, and general page layout. Plain CSS, no build step. */

:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --bg: #f9fafb;
  --surface: #ffffff;
  --success: #2e9e5b;
  --warning: #c98a2d;
  --danger: #c94f3d;
  --header-height: 60px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Fixed header ---- */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 28px;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}

.app-header .brand img {
  height: 28px;
  width: 28px;
  border-radius: 6px;
}

/* Search bar takes the remaining space, pushing nav + icons to the right. */
.header-search {
  flex: 1;
  min-width: 0;
  max-width: 560px;
  display: flex;
  align-items: stretch;
  height: 36px;
}

.header-search-field-wrap {
  position: relative;
  flex-shrink: 0;
  width: 118px;
}
.header-search-field-wrap select {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 6px 0 0 6px;
  background: var(--bg);
  font-size: 12.5px;
  padding: 0 22px 0 8px;
  color: var(--text-muted);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}
.header-search-field-wrap svg {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* The Select2-enhanced input sits flush against the field selector,
   sharing one visual border so the pair reads as a single control. */
.header-search .select2-container {
  flex: 1;
  min-width: 0;
}
.header-search .select2-selection--single {
  height: 36px !important;
  border-radius: 0 6px 6px 0 !important;
  border-color: var(--border) !important;
  display: flex;
  align-items: center;
}
.header-search .select2-selection__rendered {
  line-height: 34px !important;
  color: var(--text) !important;
}
.header-search .select2-selection__arrow {
  height: 34px !important;
}
/* Replace Select2's default CSS-triangle arrow with a matching
   single-line FA chevron, for visual consistency with the field selector. */
.header-search .select2-selection__arrow b {
  display: none !important;
}
.header-search .select2-selection__arrow::after {
  content: '';
  display: block;
  width: 10px;
  height: 10px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
}

/* Nav sits right-aligned, immediately before the icon cluster - no
   longer pushed flush against the logo now that the search bar owns
   the flexible space. */
.app-header nav {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  margin-left: auto;
}

.app-header nav a {
  padding: 8px 14px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.app-header nav a:hover { background: var(--bg); color: var(--text); }
.app-header nav a.active { color: var(--brand); background: #eff6ff; }

/* ---- Profile menu ---- */
.notif-bell-wrap {
  position: relative;
  flex-shrink: 0;
}

.profile-menu {
  position: relative;
  flex-shrink: 0;
}

.profile-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  border: none;
  overflow: hidden;
  padding: 0;
}

.profile-avatar img {
  width: 100%; height: 100%; object-fit: cover;
}

.profile-dropdown {
  display: none;
  position: absolute;
  top: 46px; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  min-width: 180px;
  padding: 6px;
  z-index: 200;
}

.profile-dropdown.open { display: block; }

.profile-dropdown .dropdown-name {
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.profile-dropdown a, .profile-dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  border: none;
  background: none;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.profile-dropdown a:hover, .profile-dropdown button:hover { background: var(--bg); }

/* ---- Page shell ---- */
.page-container {
  width: 100%;
  margin: 0;
  padding: calc(var(--header-height) + 28px) 32px 40px;
  flex: 1;
}

.page-title { font-size: 20px; font-weight: 600; margin: 0 0 20px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

input[type="text"], input[type="password"], input[type="file"], input:not([type]) {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
}

button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}

button:hover { background: var(--bg); }

button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}

button.primary:hover { background: var(--brand-dark); }

button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- File row hover-reveal actions (Gmail-style) ---- */
.file-row {
  transition: background 0.1s ease;
}
.file-row:hover {
  background: #fafbfc;
}
.file-row .file-actions {
  opacity: 0;
  transition: opacity 0.12s ease;
}
.file-row:hover .file-actions {
  opacity: 1;
}
.icon-btn {
  border: none;
  background: none;
  color: #9ca3af;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  padding: 0;
}
.icon-btn-lg {
  width: 38px;
  height: 38px;
  font-size: 17px;
}
.icon-btn:hover {
  background: #f3f4f6;
  color: #374151;
}
.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.text-action-btn {
  border: none;
  background: none;
  color: #6b7280;
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.text-action-btn:hover {
  background: #f3f4f6;
  color: #1f2937;
}
.text-action-btn.danger:hover {
  background: #fef2f2;
  color: #c94f3d;
}

/* ---- Footer ---- */
.app-footer {
  text-align: center;
  padding: 28px 20px;
  margin-top: 40px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.app-footer a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
}
.app-footer a:hover {
  color: var(--brand);
}

/* ---- Dark mode ----
   Covers the app-wide chrome (header, page background, cards, buttons,
   inputs) via the same CSS variables everything already uses. Content
   generated dynamically in JS with hardcoded inline colors (search
   results rows, activity/backup tables) will NOT fully adapt - that
   would need those inline styles converted to CSS classes, a separate
   follow-up if it matters in practice. */
[data-theme="dark"] {
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --border: #374151;
  --bg: #0f172a;
  --surface: #1e293b;
  /* Tells the browser to render native form controls (checkboxes,
     radios, date-picker calendar, scrollbars) in dark-appropriate
     style automatically - CSS alone can't restyle a checkbox's
     internals, this is the actual fix for that. */
  color-scheme: dark;
}
[data-theme="dark"] body {
  background: var(--bg);
  color: var(--text);
}
[data-theme="dark"] .app-header {
  background: var(--surface);
  border-color: var(--border);
}
[data-theme="dark"] .card {
  background: var(--surface);
  border-color: var(--border);
}
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input:not([type]),
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background: #111827 !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
}
/* Autofilled inputs ignore normal background/color CSS entirely -
   browsers force their own (light) autofill styling that can only be
   overridden via this box-shadow trick, not by any direct property. */
[data-theme="dark"] input:-webkit-autofill,
[data-theme="dark"] input:-webkit-autofill:hover,
[data-theme="dark"] input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0px 1000px #111827 inset;
  box-shadow: 0 0 0px 1000px #111827 inset;
  transition: background-color 5000s ease-in-out 0s;
}
[data-theme="dark"] input[type="checkbox"] {
  accent-color: var(--brand);
}
[data-theme="dark"] button {
  background: #1f2937;
  border-color: var(--border);
  color: var(--text);
}
[data-theme="dark"] button:hover {
  background: #374151;
}
[data-theme="dark"] button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}
[data-theme="dark"] .app-header nav a {
  color: var(--text-muted);
}
[data-theme="dark"] .app-header nav a.active {
  color: #93c5fd;
  background: rgba(37, 99, 235, 0.18);
}
[data-theme="dark"] .profile-dropdown,
[data-theme="dark"] .notif-dropdown {
  background: var(--surface);
  border-color: var(--border);
}

/* ---- Notification bell + dropdown ---- */
.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #c94f3d;
  color: white;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  min-width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  pointer-events: none;
}
.notif-dropdown {
  display: none;
  position: absolute;
  top: 46px;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  width: 320px;
  max-height: 420px;
  overflow-y: auto;
  z-index: 200;
}
.notif-dropdown.open {
  display: block;
}
.notif-item {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  position: relative;
  color: var(--text);
}
.notif-item:first-child {
  border-top: none;
}
.notif-item.unread {
  background: rgba(37, 99, 235, 0.06);
}
.notif-item .notif-mark-one {
  display: none;
}
.notif-item:hover .notif-mark-one {
  display: inline-block;
}

/* ---- Inline button spinner (download/delete in-flight state) ---- */
.btn-spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid #d1d5db;
  border-top-color: #6b7280;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* ---- Search result groups (details/summary) ---- */
#search-panel details > summary { list-style: none; }
#search-panel details > summary::-webkit-details-marker { display: none; }
#search-panel details > summary::marker { display: none; }
#search-panel .caret-icon {
  display: inline-block;
  width: 14px;
  margin-right: 8px;
  color: #9ca3af;
  transition: transform 0.15s ease;
  transform: rotate(-90deg); /* closed = pointing right */
}
#search-panel details[open] > summary .caret-icon {
  transform: rotate(0deg); /* open = pointing down */
}
