/* ExpSoR web app. A record-centric layout in the style of Salesforce Lightning:
   global header, object tabs, cards, list views, record pages and Setup.
   Author: Chris Hoback */

:root {
  --brand: #0176d3;
  --brand-dark: #014486;
  --text: #181818;
  --muted: #5c5c5c;
  --border: #e5e5e5;
  --page: #f3f3f3;
  --card: #fff;
  --danger: #ba0517;
  --success: #2e844a;
  --warning: #a96404;
  --radius: 0.25rem;
  --shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--page);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1rem; }

/* Global header */
.global-header {
  display: flex; align-items: center; gap: 1rem;
  height: 3rem; padding: 0 1rem;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1rem; color: var(--text); }
.brand-mark {
  display: inline-grid; place-items: center; width: 1.75rem; height: 1.75rem;
  border-radius: 50%; background: var(--brand); color: #fff; font-size: 0.75rem;
}
.header-spacer { flex: 1; }
.header-user { color: var(--muted); }
/* Phones: the user's address gives way, so the header's links and Sign out stay on screen. */
@media (max-width: 600px) {
  .global-header { gap: 0.75rem; padding: 0 0.75rem; }
  .header-user { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 0 1 auto; }
  .global-header .header-user { max-width: 5.5rem; }
}

/* Object tabs */
.tab-bar {
  display: flex; align-items: stretch; gap: 0.25rem;
  padding: 0 1rem; height: 2.5rem;
  background: var(--card); border-bottom: 3px solid var(--brand);
  overflow-x: auto;
}
.tab-bar a {
  display: flex; align-items: center; padding: 0 0.75rem;
  color: var(--text); border-bottom: 3px solid transparent; margin-bottom: -3px;
  white-space: nowrap;
}
.tab-bar a:hover { background: #f3f3f3; text-decoration: none; }
.tab-bar a.active { border-bottom-color: var(--brand-dark); font-weight: 700; }
.tab-bar .app-name { font-weight: 700; font-size: 1rem; padding-right: 1rem; display: flex; align-items: center; }

/* Page layout */
main { padding: 0.75rem; display: grid; gap: 0.75rem; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.card-header h2 { flex: 1; }
.card-body { padding: 0.75rem 1rem; }
.page-header { display: flex; align-items: center; gap: 0.75rem; padding: 1rem; }
.page-header .titles { flex: 1; }
.object-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.object-icon {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: var(--radius);
  background: #7f8de1; color: #fff; font-weight: 700;
}
.muted { color: var(--muted); }
.count { color: var(--muted); font-weight: 400; }

/* Buttons */
button, .button {
  font: inherit; cursor: pointer; padding: 0.375rem 1rem; border-radius: var(--radius);
  border: 1px solid #c9c9c9; background: #fff; color: var(--brand); line-height: 1.25;
}
button:hover { background: #f3f3f3; }
button.brand { background: var(--brand); border-color: var(--brand); color: #fff; }
button.brand:hover { background: var(--brand-dark); }
button.destructive { background: var(--danger); border-color: var(--danger); color: #fff; }
button:disabled { opacity: 0.5; cursor: default; }
button.link { border: 0; background: none; padding: 0; color: var(--brand); }
button.link:hover { text-decoration: underline; background: none; }
.button-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Tables (list views) */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.75rem; color: var(--muted); font-weight: 700; padding: 0.5rem; border-bottom: 1px solid var(--border); background: #fafaf9; white-space: nowrap; }
th button.sort { padding: 0; border: 0; background: none; color: inherit; font-weight: 700; }
td { padding: 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:hover td { background: #f3f3f3; }
.empty { padding: 1rem; color: var(--muted); }

/* Record detail */
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); gap: 0 2rem; }
.field { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.field-label { font-size: 0.75rem; color: var(--muted); }
.field-value { min-height: 1.25rem; padding-top: 0.125rem; overflow-wrap: anywhere; }
.layout-2col { display: grid; grid-template-columns: 2fr 1fr; gap: 0.75rem; align-items: start; }
@media (max-width: 900px) { .layout-2col { grid-template-columns: 1fr; } }

/* Forms */
form.record-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); gap: 0.75rem 2rem; }
.control { display: grid; gap: 0.25rem; }
.control label { font-size: 0.75rem; color: var(--muted); }
.inline-control { display: flex; align-items: center; gap: 0.375rem; }
label.inline { font-size: 0.875rem; color: var(--text); }
input, select, textarea {
  font: inherit; color: var(--text); padding: 0.375rem 0.5rem;
  border: 1px solid #c9c9c9; border-radius: var(--radius); background: #fff;
}
input[type="checkbox"] { width: 1rem; height: 1rem; }
textarea { min-height: 6rem; font-family: ui-monospace, Consolas, monospace; }
.required::after { content: " *"; color: var(--danger); }
.form-actions { grid-column: 1 / -1; display: flex; gap: 0.5rem; justify-content: flex-end; padding-top: 0.5rem; border-top: 1px solid var(--border); }
.fieldset-row { display: flex; gap: 0.75rem; align-items: end; flex-wrap: wrap; }

/* Messages */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); background: #fef1ee; border: 1px solid #f3b7a9; color: var(--danger); }
.notice { padding: 0.75rem 1rem; border-radius: var(--radius); background: #eef4ff; border: 1px solid #b0c7ee; }
.badge { display: inline-block; white-space: nowrap; padding: 0.125rem 0.5rem; border-radius: 1rem; font-size: 0.75rem; background: #e5e5e5; }
.badge.applied { background: #cdefc4; color: var(--success); }
.badge.pending { background: #fff1d6; color: var(--warning); }
.badge.failed, .badge.rejected { background: #fddde3; color: var(--danger); }
.badge.standard { background: #e3f3ff; color: #014486; }
.badge.platform { background: #ece1f9; color: #5a1ba9; }
.badge + .badge { margin-left: 0.25rem; }
.nowrap { white-space: nowrap; }
.role-description { margin: 0.25rem 0; }
/* Role help: a "?" whose tooltip shows on hover or keyboard focus. */
.help { position: relative; display: inline-block; margin-left: 0.25rem; }
.help-icon { width: 1.125rem; height: 1.125rem; padding: 0; border-radius: 50%; font-size: 0.6875rem; line-height: 1; color: var(--muted); }
.help .tooltip { display: none; position: absolute; z-index: 20; right: -0.5rem; top: 1.5rem; width: 18rem; padding: 0.5rem 0.625rem; border-radius: 0.25rem; background: #032d60; color: #fff; font-size: 0.75rem; font-weight: normal; line-height: 1.35; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); }
.help:hover .tooltip, .help-icon:focus + .tooltip { display: block; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 0.375rem 0; border-bottom: 1px solid var(--border); }
pre.code { margin: 0; padding: 0.5rem; background: #f8f8f8; border-radius: var(--radius); overflow-x: auto; }

/* Setup: a menu grouped into sections, with Quick Find at the top */
.setup-layout { display: grid; grid-template-columns: 15rem 1fr; gap: 0.75rem; align-items: start; }
.setup-nav { padding-bottom: 0.5rem; }
.quick-find-wrap { padding: 0.75rem; border-bottom: 1px solid var(--border); }
.quick-find { width: 100%; }
.setup-section { padding-top: 0.5rem; }
.setup-section-label { padding: 0.25rem 1rem; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.setup-group summary { padding: 0.375rem 1rem; cursor: pointer; font-weight: 700; }
.setup-group a { padding-left: 2rem; }
.setup-nav a { display: block; padding: 0.375rem 1rem; color: var(--text); }
.setup-nav a.active { background: #e8f4fd; border-left: 3px solid var(--brand); font-weight: 700; }
@media (max-width: 800px) { .setup-layout { grid-template-columns: 1fr; } }

/* Toasts */
/* Toasts: Salesforce-style, at the top of the window, full width on phones. */
.toasts { position: fixed; top: 0.5rem; left: 50%; transform: translateX(-50%); display: grid; gap: 0.5rem; z-index: 40; width: min(36rem, calc(100vw - 1rem)); }
.toast { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 0.75rem 0.75rem 1rem; border-radius: var(--radius); color: #fff; background: #706e6b; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); animation: toast-in 0.2s ease-out; }
.toast.success { background: #2e844a; }
.toast.error { background: #ba0517; }
.toast.warning { background: #fe9339; color: #181818; }
.toast.info { background: #706e6b; }
.toast-icon { display: inline-grid; place-items: center; flex: none; width: 1.5rem; height: 1.5rem; border: 2px solid currentColor; border-radius: 50%; font-size: 0.75rem; font-weight: 700; }
.toast-message { flex: 1; line-height: 1.4; }
.toast-close { flex: none; width: 2rem; height: 2rem; padding: 0; border: 0; background: transparent; color: inherit; font-size: 1.25rem; line-height: 1; }
@keyframes toast-in { from { transform: translateY(-0.5rem); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
/* A field the API says is wrong. */
.invalid, .invalid:focus { border-color: #ba0517 !important; box-shadow: 0 0 0 1px #ba0517; outline-color: #ba0517; }
.field-error { margin-top: 0.25rem; color: #ba0517; font-size: 0.75rem; }

/* Permission grids (a role on one object) */
table.grid td, table.grid th { text-align: center; }
table.grid td:first-child, table.grid th:first-child { text-align: left; }
.hint { display: block; font-size: 0.75rem; color: var(--muted); }
.tag { display: inline-block; margin-left: 0.25rem; padding: 0 0.375rem; border-radius: 0.5rem; font-size: 0.6875rem; background: #f3f2f2; color: var(--muted); }
.warning-list { margin: 0.5rem 0 0; padding-left: 1.25rem; color: var(--warning); }
.breadcrumb { font-size: 0.75rem; color: var(--muted); }

/* Setup */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 0.75rem; }
.stat { padding: 0.5rem 0.75rem; border-left: 3px solid var(--brand); background: #f8fbff; }
.stat-value { font-size: 1.25rem; font-weight: 700; }
fieldset.role-list { border: 1px solid var(--border); border-radius: var(--radius); display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 0.25rem 1rem; }
fieldset.role-list legend { font-size: 0.75rem; color: var(--muted); }
th[scope="row"] { color: var(--text); font-weight: 400; background: none; }

/* App Launcher */
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 0.75rem; }
.app-tile .card-body { display: grid; gap: 0.5rem; align-content: start; height: 100%; }
.app-tile-head { display: flex; align-items: center; gap: 0.5rem; }
.app-tile .button { justify-self: start; text-decoration: none; }
a.button.brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.small { font-size: 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Sign-in screen */
.sign-in { max-width: 24rem; margin: 6rem auto; text-align: center; }
.sign-in .card-body { display: grid; gap: 1rem; padding: 2rem; }

/* Modal */
.backdrop { position: fixed; inset: 0; background: rgba(8, 7, 7, 0.6); display: grid; place-items: center; }
.modal { width: min(28rem, 92vw); }

/* Design guide: sections on the left, the chosen one rendered on the right. */
.guide { display: grid; grid-template-columns: minmax(10rem, 14rem) 1fr; gap: 1.5rem; }
.guide-nav a { display: block; padding: 0.25rem 0.5rem; border-radius: 0.25rem; }
.guide-nav a[aria-current="page"] { background: #e3f3ff; font-weight: 600; }
.markdown h2 { font-size: 1.25rem; margin: 0 0 0.75rem; }
.markdown h3, .markdown h4 { margin: 1rem 0 0.5rem; }
.markdown p, .markdown ul, .markdown ol { margin: 0 0 0.75rem; line-height: 1.5; }
.markdown code { background: #f3f2f2; padding: 0 0.25rem; border-radius: 0.25rem; }
.markdown blockquote { margin: 0 0 0.75rem; padding-left: 0.75rem; border-left: 3px solid #c9c9c9; color: var(--muted); }
.file-view { max-height: 24rem; overflow: auto; }
@media (max-width: 700px) { .guide { grid-template-columns: 1fr; } }

/* Inline editing on record pages: a pencil per editable field (on hover; always on touch screens),
   and a Save / Cancel bar that slides up and stays at the bottom of the window. */
.field.editable { position: relative; padding-right: 2rem; }
.field.editable .field-value { cursor: text; }
.inline-edit { position: absolute; right: 0; bottom: 0.25rem; width: 1.75rem; height: 1.75rem; padding: 0; border: 0; background: transparent; color: var(--muted); opacity: 0; }
.field.editable:hover .inline-edit, .inline-edit:focus { opacity: 1; }
.field.editable .field-value input, .field.editable .field-value select, .field.editable .field-value textarea { width: 100%; box-sizing: border-box; }
@media (hover: none) { .inline-edit { opacity: 1; width: 2.75rem; height: 2.75rem; } }
.edit-bar-spacer { height: 6rem; }
.edit-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.5rem 1rem; padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom)); background: #f3f3f3; border-top: 1px solid #c9c9c9; box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.12); transform: translateY(100%); transition: transform 0.2s ease-out; }
.edit-bar.open { transform: none; }
.edit-bar-actions { display: flex; gap: 0.5rem; }
.edit-bar-message:empty { display: none; }
.edit-bar-message .alert { margin: 0; }
@media (prefers-reduced-motion: reduce) { .edit-bar { transition: none; } }
@media (max-width: 700px) {
  .edit-bar { flex-direction: column; align-items: stretch; }
  .edit-bar-actions button { flex: 1; min-height: 44px; }
}

/* Loading skeletons (a soft shimmer) and the in-place message when loading failed. */
.skeleton { display: inline-block; height: 0.75rem; border-radius: 0.25rem; background: linear-gradient(90deg, #ecebea 25%, #f8f8f8 50%, #ecebea 75%); background-size: 200% 100%; animation: skeleton 1.2s ease-in-out infinite; }
.skeleton-block { display: grid; gap: 0.75rem; padding: 0.25rem 0; }
.skeleton-block .skeleton { display: block; }
@keyframes skeleton { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
.load-failed { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; padding: 1rem; color: #ba0517; }
.load-failed p { margin: 0; }

/* Maintenance: the overlay framing the instance's page, and its preview in Setup. */
.maintenance-overlay { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: var(--bg, #f3f3f3); }
.maintenance-overlay iframe { flex: 1; width: 100%; border: 0; }
.maintenance-note { margin: 0; padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom)); text-align: center; font-size: 0.875rem; color: var(--muted); background: var(--card); border-top: 1px solid var(--border); }
.maintenance-preview { width: 100%; height: 22rem; border: 1px solid var(--border); border-radius: var(--radius); }
