/* ---------------------------------------------------------------------------
   NetMed360 PACS portal -- application shell
   ------------------------------------------------------------------------- */

:root {
  --app-sidebar-width: 240px;
  --app-topbar-height: 60px;
  --app-sidebar-bg: #1f2a37;
  --app-sidebar-fg: #cbd5e1;
  --app-sidebar-fg-muted: #94a3b8;
  --app-sidebar-active-bg: rgba(255, 255, 255, 0.08);
  --app-sidebar-section-fg: #64748b;
  /* --app-primary and --app-accent are emitted inline by _Layout.cshtml so each
     tenant's Branding colors flow through to the whole portal. */
  --app-primary: #0d6efd;
  --app-accent: #6c757d;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
}

/* ----- Application shell -------------------------------------------------- */

.app-shell {
  display: grid;
  grid-template-columns: var(--app-sidebar-width) 1fr;
  grid-template-rows: 100vh;
  min-height: 100vh;
}

.app-main {
  display: flex;
  flex-direction: column;
  min-width: 0;            /* lets long table rows wrap inside the grid column */
  background-color: var(--bs-body-bg);
}

.app-content {
  flex: 1;
  padding: 1.5rem 2rem 3rem;
  overflow-x: auto;
}

@media (max-width: 767.98px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform 200ms ease;
  }
  .app-sidebar.is-open {
    transform: translateX(0);
  }
  .app-content {
    padding: 1rem 1rem 2rem;
  }
}

/* ----- Sidebar ----------------------------------------------------------- */

.app-sidebar {
  background-color: var(--app-sidebar-bg);
  color: var(--app-sidebar-fg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(0, 0, 0, 0.2);
  overflow-y: auto;
}

.app-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 1.25rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.app-sidebar-brand .bi {
  font-size: 1.4rem;
  color: var(--app-primary);
}

.app-sidebar-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.app-sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0;
}

.app-sidebar-section {
  padding: 1rem 1.25rem 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--app-sidebar-section-fg);
}

.app-nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1.25rem;
  color: var(--app-sidebar-fg);
  text-decoration: none;
  font-size: 0.95rem;
  border-left: 3px solid transparent;
  transition: background 100ms ease, color 100ms ease;
}

.app-nav-link:hover {
  background-color: var(--app-sidebar-active-bg);
  color: #fff;
}

.app-nav-link.active {
  background-color: var(--app-sidebar-active-bg);
  color: #fff;
  border-left-color: var(--app-primary);
}

.app-nav-link .bi {
  font-size: 1.05rem;
  width: 1.2em;
  text-align: center;
  color: var(--app-sidebar-fg-muted);
}

.app-nav-link.active .bi,
.app-nav-link:hover .bi {
  color: var(--app-primary);
}

/* ----- Topbar ------------------------------------------------------------ */

.app-topbar {
  height: var(--app-topbar-height);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--bs-border-color);
  background-color: var(--bs-body-bg);
}

.app-sidebar-toggle {
  font-size: 1.4rem;
  text-decoration: none;
  color: var(--bs-body-color);
  padding: 0.25rem 0.5rem;
}

.app-topbar-center {
  flex: 1;
  min-width: 0;
}

.app-center-pill {
  border: 1px solid var(--bs-border-color);
  background-color: var(--bs-tertiary-bg);
  padding: 0.35rem 0.85rem;
  font-size: 0.92rem;
}

.app-center-pill:focus { box-shadow: none; }

.app-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.app-theme-toggle, .app-user-button {
  text-decoration: none;
  color: var(--bs-body-color);
  padding: 0.4rem 0.6rem;
}

.app-theme-toggle:focus, .app-user-button:focus { box-shadow: none; }

.theme-icon-light { display: none; }
[data-bs-theme="dark"] .theme-icon-dark { display: none; }
[data-bs-theme="dark"] .theme-icon-light { display: inline; }

/* ----- Anonymous shell (login / access denied / error) ------------------ */

.app-anonymous-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 4rem 1rem 2rem;
  background:
      radial-gradient(circle at top right, color-mix(in srgb, var(--app-primary) 15%, transparent), transparent 60%),
      var(--bs-body-bg);
}

.app-anonymous-main {
  width: 100%;
  max-width: 460px;
  background-color: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
}

.app-anonymous-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--bs-body-color);
}

.app-anonymous-brand .bi {
  color: var(--app-primary);
  font-size: 1.6rem;
}

.app-anonymous-logo {
  height: 40px;
  width: auto;
  object-fit: contain;
}

.app-anonymous-footer {
  margin-top: 2rem;
}

/* ----- Bootstrap primary recolor (via tenant CSS custom property) -------- */

.btn-primary {
  --bs-btn-bg: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: color-mix(in srgb, var(--app-primary) 85%, black);
  --bs-btn-hover-border-color: color-mix(in srgb, var(--app-primary) 85%, black);
  --bs-btn-active-bg: color-mix(in srgb, var(--app-primary) 75%, black);
  --bs-btn-active-border-color: color-mix(in srgb, var(--app-primary) 75%, black);
}

.btn-outline-primary {
  --bs-btn-color: var(--app-primary);
  --bs-btn-border-color: var(--app-primary);
  --bs-btn-hover-bg: var(--app-primary);
  --bs-btn-hover-border-color: var(--app-primary);
  --bs-btn-active-bg: var(--app-primary);
  --bs-btn-active-border-color: var(--app-primary);
}

a {
  color: var(--app-primary);
}

a:hover {
  color: color-mix(in srgb, var(--app-primary) 80%, black);
}

/* Inputs honor the focus ring color without overriding default behavior. */
.form-control:focus,
.form-select:focus,
.form-check-input:focus,
.btn:focus,
.btn:active:focus {
  border-color: color-mix(in srgb, var(--app-primary) 60%, transparent);
  box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--app-primary) 25%, transparent);
}

/* ----- Tables & cards (light polish) ------------------------------------ */

.table > :not(caption) > * > * {
  vertical-align: middle;
}

.card {
  border: 1px solid var(--bs-border-color);
}

/* ----- Page header helper used in views -------------------------------- */

.page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--bs-border-color);
}

.page-header > h1 { margin: 0; }
.page-header .actions { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; }

/* ----- User avatars (initial circles) --------------------------------- */

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: color-mix(in srgb, var(--app-primary) 18%, var(--bs-body-bg));
  color: var(--app-primary);
  font-weight: 600;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.user-avatar-lg {
  width: 48px;
  height: 48px;
  font-size: 1.2rem;
}

/* ----- Upload dropzone (Studies/Upload) ------------------------------- */

.upload-dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  padding: 2rem;
  border: 2px dashed var(--bs-border-color);
  border-radius: 10px;
  cursor: pointer;
  background-color: var(--bs-tertiary-bg);
  transition: background-color 100ms ease, border-color 100ms ease;
  text-align: center;
}

.upload-dropzone:hover,
.upload-dropzone.is-dragover {
  border-color: var(--app-primary);
  background-color: color-mix(in srgb, var(--app-primary) 8%, var(--bs-body-bg));
}

.upload-dropzone .bi { color: var(--app-primary); }

.upload-file-summary {
  text-align: center;
  color: var(--bs-body-color);
}

/* ----- Dark mode tweaks ------------------------------------------------- */

[data-bs-theme="dark"] {
  --app-sidebar-bg: #0f172a;
}

[data-bs-theme="dark"] .app-center-pill {
  background-color: var(--bs-secondary-bg);
}

/* ----- Proactive alert toasts (top-right) ------------------------------- */

.alerts-toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1090;            /* above content + sticky header, below modals */
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
  pointer-events: none;     /* container transparent; children re-enable */
}

.alert-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  padding: 0.75rem 0.9rem;
  border-radius: 0.5rem;
  border-left: 4px solid var(--bs-secondary);
  background-color: var(--bs-body-bg);
  box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.18);
}

.alert-toast-body { flex: 1; min-width: 0; }
.alert-toast-danger  { border-left-color: var(--bs-danger); }
.alert-toast-warning { border-left-color: var(--bs-warning); }
.alert-toast-info    { border-left-color: var(--bs-info); }

.btn-close-sm { padding: 0.25rem; background-size: 0.65em; }
