/* 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 */

/* Layers: the console's element defaults (base) lose to the shared components' (expsor-ui), and
   everything outside a layer (the rest of this file) wins over both. */
@layer base, expsor-ui;

: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);
}

@layer base {
  * { 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; }
  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; }
  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; }
  td { padding: 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
  tr:hover td { background: #f3f3f3; }
  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; }
}

/* 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);
}
.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; }
/* Object tabs in one row; those that don't fit go under More (app.js moreTabs), so the bar never scrolls. */
.object-tabs { display: flex; gap: 0.25rem; flex: 1; min-width: 0; }
.object-tabs a { flex: none; }
.tab-more { position: relative; display: flex; align-items: stretch; }
.tab-more[hidden] { display: none; }
.tab-more-button { display: flex; align-items: center; padding: 0 0.75rem; border: 0; border-bottom: 3px solid transparent; margin-bottom: -3px; border-radius: 0; background: none; color: var(--text); white-space: nowrap; }
.tab-more-button:hover { background: #f3f3f3; }
.tab-more.active .tab-more-button { border-bottom-color: var(--brand-dark); font-weight: 700; }
.tab-more-list { position: absolute; z-index: 30; top: calc(100% + 3px); right: 0; min-width: 12rem; max-height: 60vh; overflow-y: auto; margin: 0; padding: 0.25rem 0; list-style: none; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.tab-more-list[hidden] { display: none; }
.tab-more-list a { display: block; padding: 0.5rem 0.75rem; color: var(--text); white-space: nowrap; }
.tab-more-list a:hover, .tab-more-list a:focus { background: #f3f3f3; text-decoration: none; outline: none; }
.tab-more-list a.active { font-weight: 700; box-shadow: inset 3px 0 0 var(--brand); }

/* Page layout */
main { padding: 0.75rem; display: grid; gap: 0.75rem; }
/* One per navigation (app.js route); its children lay out as main's own. */
.view { display: contents; }
.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-actions { display: flex; align-items: center; gap: 0.5rem; }
.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.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) */
th button.sort { padding: 0; border: 0; background: none; color: inherit; font-weight: 700; }
.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[hidden] { display: none; }
.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); }
.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.site-guest { background: #fef1ee; color: #8c4b02; }
.public-object { border: 1px solid var(--border, #dddbda); border-radius: 0.25rem; margin: 0 0 0.5rem; padding: 0.25rem 0.75rem 0.5rem; }
.public-object legend { padding: 0 0.25rem; }
.public-fields { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }
.public-fields[hidden] { display: none; }
.badge + .badge { margin-left: 0.25rem; }
.nowrap { white-space: nowrap; }
.role-description { margin: 0.25rem 0; }
.field-label .expsor-help, .role-name .expsor-help { margin-left: 0.25rem; vertical-align: middle; }
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-nav .setup-group a { padding-left: 2rem; } /* items under a group sit indented below its name */
.setup-nav a { display: block; padding: 0.375rem 1rem; color: var(--text); }
/* The chosen page: a blue line and background only; its text stays as it was (no bold, no
   underline, no shift). Hovering shades an item instead of underlining it. */
.setup-nav a:hover { text-decoration: none; background: #f3f3f3; }
.setup-nav a.active { background: #e8f4fd; box-shadow: inset 3px 0 0 var(--brand); }
@media (max-width: 800px) { .setup-layout { grid-template-columns: 1fr; } }

/* 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; }
/* Storage used, as a bar; amber from 80%. */
.usage-bar { height: 0.5rem; margin: 0.375rem 0; border-radius: 0.25rem; background: var(--border); overflow: hidden; max-width: 24rem; }
.usage-bar span { display: block; height: 100%; background: var(--brand); }
.usage-bar.high span { background: var(--warning); }
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; }

/* Dialogs: the components' modals, with the console's buttons. */
.expsor-modal-body ul { margin: 0.5rem 0; padding-left: 1.25rem; }

/* 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); }

/* Setup > Error Logs */
.error-log { border-top: 1px solid var(--border); padding: 0.5rem 0; }
.error-log summary { cursor: pointer; }
.traceback { white-space: pre-wrap; overflow-x: auto; font-size: 0.8rem; background: var(--bg, #f6f6f6); padding: 0.5rem; }

/* Setup > Architecture: the diagram (architecture.js). */
.architecture-figure { margin: 0 0 1rem; overflow-x: auto; }
.architecture { width: 100%; min-width: 760px; height: auto; font-family: inherit; }
.architecture text { text-anchor: middle; fill: #181818; }
.architecture .arch-left { text-anchor: start; }
.architecture .arch-zone { fill: #f3f3f3; stroke: #c9c9c9; stroke-dasharray: 6 4; }
.architecture .arch-site { fill: #fff; stroke: #c9c9c9; }
.architecture .arch-console { stroke: #0176d3; stroke-width: 2; }
.architecture .arch-layer { fill: #eef4ff; stroke: #0176d3; stroke-width: 2; }
.architecture .arch-chip { fill: #fff; stroke: #8ab6e8; }
.architecture .arch-core { fill: #fef6e7; stroke: #a96404; stroke-width: 2; }
.architecture .arch-core-item { fill: #fff; stroke: #e2c58f; }
.architecture .arch-mcp { fill: #f3ecfb; stroke: #7526e3; stroke-width: 2; }
.architecture .arch-agent { fill: #fff; stroke: #7526e3; stroke-dasharray: 5 4; }
.architecture .arch-zone-title, .architecture .arch-layer-title, .architecture .arch-core-title { font-size: 19px; font-weight: 700; }
.architecture .arch-box-title, .architecture .arch-chip-title { font-size: 15px; font-weight: 600; }
.architecture .arch-item { font-size: 14px; }
.architecture .arch-note, .architecture .arch-chip-path { font-size: 12.5px; fill: #5c5c5c; }
.architecture .arch-flow { fill: none; stroke: #5c5c5c; stroke-width: 2; }
.architecture .arch-arrowhead { fill: #5c5c5c; }
.architecture .arch-flow-label { font-size: 12.5px; fill: #444; font-style: italic; }
.architecture-layers dt { font-weight: 700; margin-top: 0.75rem; }
.architecture-layers dd { margin: 0.25rem 0 0; }
