/* =============================================================================
   UChicago SSCS — Integration Portal
   Design language shared with the SSD Falcon (Apollo) inventory portal.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* UChicago brand */
  --maroon:        #800000;
  --maroon-dark:   #5c0000;
  --maroon-light:  #a6192e;
  --maroon-50:     #fff5f5;
  --maroon-100:    #ffe1e1;

  /* Neutrals */
  --bg:            #f9fafb;
  --surface:       #ffffff;
  --surface2:      #f3f4f6;
  --border:        #e5e7eb;
  --border-strong: #d1d5db;
  --text:          #111827;
  --text-soft:     #374151;
  --muted:         #6b7280;

  /* Service accents */
  --box-color:      #0061d5;
  --gh-color:       #1a7f37;
  --grouper-color:  #4f46e5;
  --jira-color:     #1868db;

  --radius:      8px;
  --radius-lg:   12px;
  --header-h:    56px;
  --rail-w:      64px;
  --rail-open-w: 248px;

  --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
  --shadow:    0 1px 3px rgba(16,24,40,.10), 0 1px 2px rgba(16,24,40,.06);
  --shadow-lg: 0 10px 15px -3px rgba(16,24,40,.10), 0 4px 6px -4px rgba(16,24,40,.10);
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* =============================================================================
   Header
   ========================================================================== */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1001;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--maroon);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  flex-shrink: 0;
}

.brand-mark img { width: 100%; height: 100%; object-fit: contain; }

.brand-text {
  border-left: 2px solid var(--border-strong);
  padding-left: 12px;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--maroon);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}

/* User menu */
.user-menu { position: relative; }

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 6px 8px;
  font-family: inherit;
  transition: background .15s;
}

.user-menu-trigger:hover { background: var(--surface2); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--maroon);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .02em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-menu-trigger .user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-trigger svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }

.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 248px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 30;
}

.user-dropdown-head { padding: 12px 14px; border-bottom: 1px solid var(--border); }

.user-dropdown-head .user-name { font-size: 13px; font-weight: 600; color: var(--text); }

.user-dropdown-head .user-email {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-dropdown-body { padding: 6px; }

.logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  color: #b91c1c;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s;
}

.logout-btn:hover { background: #fef2f2; }
.logout-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Backdrop that closes the dropdown on outside click */
.menu-backdrop { position: fixed; inset: 0; z-index: 20; }

/* =============================================================================
   Sidebar — icon rail that expands on hover
   ========================================================================== */
.sidebar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  bottom: 0;
  width: var(--rail-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 10px 8px;
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 1000;
  transition: width .22s ease, box-shadow .22s ease;
}

.sidebar:hover { width: var(--rail-open-w); box-shadow: var(--shadow-lg); }

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 10px 8px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .18s;
}

.sidebar:hover .nav-section-label { opacity: 1; }

.nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  border-radius: var(--radius);
  color: var(--text-soft);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 11px 0;
  margin-bottom: 3px;
  text-align: left;
  transition: background .15s, color .15s, padding .22s ease;
}

.sidebar:hover .nav-item { padding: 11px 12px; }

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin: 0 auto;
  transition: margin .22s ease;
}

.sidebar:hover .nav-item svg { margin: 0 12px 0 0; }

/* Collapsed: the label must take zero width, or it shifts the icon off-centre */
.nav-item span {
  white-space: nowrap;
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition: opacity .18s;
}

.sidebar:hover .nav-item span { opacity: 1; width: auto; }

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--maroon); color: #fff; }
.nav-item.active:hover { background: var(--maroon-dark); color: #fff; }

/* =============================================================================
   Layout shell
   ========================================================================== */
.app-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-top: var(--header-h);
  margin-left: var(--rail-w);
}

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 48px;
  max-width: 1100px;
  width: 100%;
}

.panel.hidden { display: none !important; }

/* Footer */
.app-footer {
  margin-top: auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px 32px;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  max-width: 1100px;
}

.footer-brand { display: flex; align-items: center; gap: 12px; }
.footer-brand img { width: 30px; height: 30px; object-fit: contain; }
.footer-title { font-size: 12px; font-weight: 700; color: var(--maroon); line-height: 1.3; }
.footer-sub   { font-size: 11px; color: var(--muted); line-height: 1.3; }
.footer-copy  { font-size: 11px; color: var(--muted); }

/* =============================================================================
   Panel header
   ========================================================================== */
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.panel-title-row { display: flex; align-items: center; gap: 14px; }

.service-icon-wrap {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.service-icon { width: 28px; height: 28px; flex-shrink: 0; }

h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--maroon);
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.panel-subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* =============================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--maroon);
  border: 1px solid transparent;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 18px;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
}

.btn:hover:not(:disabled) { background: var(--maroon-dark); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(128,0,0,.25); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Service-tinted primaries keep each integration recognizable */
.btn-box     { background: var(--box-color); }
.btn-box:hover:not(:disabled)     { background: #004ea8; }
.btn-github  { background: var(--gh-color); }
.btn-github:hover:not(:disabled)  { background: #14632b; }
.btn-grouper { background: var(--grouper-color); }
.btn-grouper:hover:not(:disabled) { background: #4338ca; }
.btn-jira    { background: var(--jira-color); }
.btn-jira:hover:not(:disabled)    { background: #1355ad; }

.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-soft);
  font-size: 13px;
  padding: 7px 14px;
}

.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }

.btn-danger {
  background: var(--surface);
  border: 1px solid #fecaca;
  color: #b91c1c;
}

.btn-danger:hover:not(:disabled) { background: #dc2626; border-color: #dc2626; color: #fff; }

.btn-full { width: 100%; }

/* =============================================================================
   Cards
   ========================================================================== */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  margin-bottom: 22px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--maroon);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 36px;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* =============================================================================
   Tabs
   ========================================================================== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 16px;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--maroon); border-bottom-color: var(--maroon); }
.tab-panel.hidden { display: none !important; }

/* =============================================================================
   Forms
   ========================================================================== */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.field { display: flex; flex-direction: column; gap: 6px; }

label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-soft);
  letter-spacing: .06em;
  text-transform: uppercase;
}

input[type="text"],
input[type="email"],
input[type="password"],
select {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 9px 12px;
  width: 100%;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus {
  border-color: var(--maroon);
  box-shadow: 0 0 0 3px rgba(128,0,0,.12);
}

input::placeholder { color: #9ca3af; }

.inline-form { display: flex; gap: 10px; margin-bottom: 20px; }
.inline-form input { flex: 1; }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.toolbar input { width: 280px; }

.advanced-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 10px;
  user-select: none;
}

.advanced-toggle:hover { color: var(--maroon); }

.chevron-inline { display: inline-block; font-size: 10px; transition: transform .2s; }

/* =============================================================================
   Status messages
   ========================================================================== */
.status-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--maroon);
  border-radius: var(--radius);
  color: var(--text-soft);
  padding: 12px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.status-loading::before {
  content: '';
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  border: 2px solid rgba(128,0,0,.18);
  border-top-color: var(--maroon);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.status-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-left: 3px solid #dc2626;
  border-radius: var(--radius);
  color: #991b1b;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-weight: 500;
}

/* =============================================================================
   Results
   ========================================================================== */
.results-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.result-summary { color: var(--muted); font-size: 14px; }
.result-summary strong { color: var(--text); font-weight: 700; }

/* =============================================================================
   Tables
   ========================================================================== */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  overflow-y: hidden;
}

table { width: 100%; border-collapse: collapse; }

thead { background: var(--surface2); }

th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  white-space: nowrap;
}

td { padding: 11px 14px; border-top: 1px solid var(--border); }

tbody tr:hover { background: var(--maroon-50); }

.col-chevron { width: 36px; }
.chevron { font-size: 14px; line-height: 1; color: var(--muted); user-select: none; }

.folder-row { cursor: pointer; transition: background .12s; }
.folder-row.expanded { background: var(--maroon-50); }
.folder-row.expanded .chevron { color: var(--maroon); }

.folder-name { font-weight: 600; color: var(--text); }
.owner-cell  { color: var(--muted); font-size: 13px; }

.login-mono, .mono-cell {
  font-family: 'SFMono-Regular', ui-monospace, Consolas, monospace;
}

.login-mono { font-size: 12px; color: var(--muted); }
.mono-cell  { font-size: 13px; color: var(--text-soft); }

.cell-center { text-align: center; padding: 36px; }
.muted { color: var(--muted); }

/* =============================================================================
   Box collaborators panel
   ========================================================================== */
.collab-row td { padding: 0; background: var(--surface2); border-top: none; }

.collab-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px 12px 48px;
  border-top: 1px solid var(--border);
}

.collab-loading, .collab-empty {
  padding: 12px 14px 14px 48px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}

.collab-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 13px;
}

.collab-name { font-weight: 600; color: var(--text); }

/* =============================================================================
   Badges — light palette matching the Falcon portal
   ========================================================================== */
.role-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
  background: #f3f4f6;
  color: #374151;
  white-space: nowrap;
}

/* Box roles */
.role-editor    { background: #dcfce7; color: #166534; }
.role-owner     { background: #ede9fe; color: #5b21b6; }
.role-coowner   { background: #f3e8ff; color: #6b21a8; }
.role-viewer    { background: #f3f4f6; color: #374151; }
.role-uploader  { background: #dbeafe; color: #1e40af; }
.role-previewer { background: #fef3c7; color: #92400e; }

/* GitHub permissions */
.badge-admin    { background: #ede9fe; color: #5b21b6; }
.badge-write    { background: #dcfce7; color: #166534; }
.badge-maintain { background: #dbeafe; color: #1e40af; }
.badge-triage   { background: #ffedd5; color: #9a3412; }
.badge-read     { background: #f3f4f6; color: #374151; }

/* Grouper membership types + Jira statuses */
.type-immediate    { background: #e0e7ff; color: #3730a3; }
.type-effective    { background: #fef3c7; color: #92400e; }
.type-composite    { background: #ccfbf1; color: #115e59; }
.type-nonimmediate { background: #f3f4f6; color: #374151; }
.type-enabled      { background: #dcfce7; color: #166534; }
.type-disabled     { background: #fee2e2; color: #991b1b; }

.badge-pending {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 4px;
}

/* Grouper table column sizing */
#gr-body tr td:first-child,
#panel-grouper thead th:first-child {
  max-width: 480px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#gr-body tr td:nth-child(2),
#gr-body tr td:nth-child(3),
#panel-grouper thead th:nth-child(2),
#panel-grouper thead th:nth-child(3) {
  width: 110px;
  white-space: nowrap;
}

/* =============================================================================
   Error block
   ========================================================================== */
.error-block {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: #991b1b;
  padding: 14px 18px;
  font-size: 13px;
}

.error-block ul { padding-left: 18px; margin-top: 6px; }
.error-block li { margin-bottom: 3px; color: #b91c1c; }
.error-block code { font-family: ui-monospace, monospace; color: #7f1d1d; }

/* =============================================================================
   Toasts
   ========================================================================== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  transition: opacity .3s;
}

.toast-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.toast-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* =============================================================================
   Login overlay
   ========================================================================== */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-overlay .login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--maroon);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 44px 48px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 420px;
  width: 100%;
}

.login-shield { width: 60px; height: 60px; object-fit: contain; margin-bottom: 4px; }

.login-overlay h2 { font-size: 21px; font-weight: 700; color: var(--maroon); }
.login-overlay p  { color: var(--muted); font-size: 14px; }

.btn-okta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--maroon);
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 26px;
  text-decoration: none;
  margin-top: 10px;
  transition: background .15s;
}

.btn-okta:hover { background: var(--maroon-dark); }

.login-footnote {
  font-size: 11px;
  color: var(--muted);
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  width: 100%;
}

/* =============================================================================
   Responsive
   ========================================================================== */
@media (max-width: 820px) {
  .brand-text { display: none; }
  .main { padding: 22px 18px 40px; }
  .app-footer { padding: 16px 18px; }
}

@media (max-width: 680px) {
  .sidebar {
    top: var(--header-h);
    width: 100%;
    height: auto;
    bottom: auto;
    display: flex;
    gap: 6px;
    padding: 8px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }

  .sidebar:hover { width: 100%; box-shadow: none; }
  .nav-section-label { display: none; }

  .nav-item {
    width: auto;
    padding: 8px 12px;
    margin-bottom: 0;
  }

  .sidebar:hover .nav-item { padding: 8px 12px; }

  .nav-item svg,
  .sidebar:hover .nav-item svg { margin: 0 8px 0 0; }

  .nav-item span,
  .sidebar:hover .nav-item span { opacity: 1; width: auto; font-size: 13px; }

  .app-body { margin-left: 0; padding-top: calc(var(--header-h) + 53px); }

  .user-menu-trigger .user-name { display: none; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .toolbar input { width: 100%; }
  .results-meta { flex-direction: column; align-items: flex-start; }
  .footer-inner { flex-direction: column; align-items: flex-start; gap: 10px; }
}

/* =============================================================================
   Admin-only controls — hidden for non-admins. The server enforces this too
   (@admin_required); hiding a button is presentation, not authorization.
   ========================================================================== */
.admin-only { display: none !important; }
body.is-admin .admin-only { display: inline-flex !important; }
