/* app.css — Tenant portal specific overrides. Loaded after main.css. */

/* MKI top nav — tenant name left, theme toggle + logout right (injected at top of <main>). */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 20px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.topbar-brand { font-weight: 700; font-size: 16px; color: var(--text-primary); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-btn { background: transparent; border: 1px solid var(--border); color: var(--text-muted); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.topbar-btn:hover { color: var(--text-primary); border-color: var(--text-muted); }
html.embedded #topbar { display: none; }

/* Section pages — tabbed shells that embed feature pages in iframes. */
.nav-ico { display: inline-block; width: 18px; text-align: center; margin-right: 6px; }
.embed-frame { width: 100%; height: 80vh; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-card); }
.stub-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 32px 28px; text-align: center; color: var(--text-muted); }
.stub-card h3 { color: var(--text-primary); margin: 0 0 6px; }

/* Embedded mode — a feature page rendered inside a section-page tab iframe.
   Hide its own chrome so only the content shows; the section page supplies the sidebar. */
html.embedded #nav { display: none; }
html.embedded .layout { display: block; }
html.embedded main { padding: 0; max-width: none; }
html.embedded #gauge-sticky, html.embedded #build-tag { display: none; }

.step-indicator { display: flex; gap: 8px; margin-bottom: 20px; }
.step { flex: 1; padding: 10px; text-align: center; border-radius: 8px;
  background: var(--bg-secondary); color: var(--text-muted); border: 1px solid var(--border); }
.step.active { border-color: var(--accent); color: var(--text-primary); }

.savings-widget .metric { color: var(--green); }
.go { color: var(--green); font-weight: 600; }
.no-go { color: var(--red); font-weight: 600; }

/* Dashboard AI search bar — sits ABOVE the widgets grid, full width. */
.search-bar { display: flex; gap: 8px; margin: 8px 0 18px; }
.search-bar input { font-size: 16px; padding: 14px 16px; }
.search-result { margin-bottom: 18px; }
.search-result .card { border-color: var(--accent); }
.typing { color: var(--text-muted); }
.typing::after { content: '…'; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* Widget sizing rule (MKI standing rule). */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 16px; }
.widget { min-height: 200px; padding: 18px; border-radius: 12px; background: var(--bg-card); border: 1px solid var(--border); display: flex; flex-direction: column; }

/* Slide-in detail/form panel (settings 3PL, logistics) — same look as admin. */
.panel-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; z-index: 40; }
.panel-overlay.open { display: block; }
.slide-panel { position: fixed; top: 0; right: 0; height: 100vh; width: 460px; max-width: 92vw; background: var(--bg-secondary);
  border-left: 1px solid var(--border); padding: 24px; overflow-y: auto; transform: translateX(100%); transition: transform .2s ease; z-index: 50; }
.slide-panel.open { transform: translateX(0); }
.panel-close { float: right; background: transparent; border: 1px solid var(--border); color: var(--text-muted); border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.panel-close:hover { color: var(--text-primary); border-color: var(--text-muted); }

/* Coast diagram (logistics coast analysis) */
.coast-map { display: flex; gap: 12px; }
.coast-box { flex: 1; border: 1px solid var(--border); border-radius: 12px; padding: 16px; text-align: center; background: var(--bg-secondary); }
.coast-box.has { border-color: var(--accent); }
.var-green { color: var(--green); font-weight: 600; }
.var-yellow { color: var(--yellow); font-weight: 600; }
.var-red { color: var(--red); font-weight: 600; }

/* API fuel gauge */
.gauge-track { width: 100%; height: 14px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin: 10px 0 6px; }
.gauge-fill { height: 100%; width: 0; border-radius: 999px; transition: width .6s ease; background: var(--green); }
.gauge-fill.amber { background: var(--yellow); }
.gauge-fill.red { background: var(--red); }
.gauge-fill.pulse { animation: gaugePulse 1.1s ease-in-out infinite; }
@keyframes gaugePulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
.banner { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.banner-amber { background: rgba(241,196,15,.15); border: 1px solid var(--yellow); }
.banner-red { background: rgba(231,76,60,.15); border: 1px solid var(--red); }
.banner a { color: var(--text-muted); text-decoration: none; }
/* Sticky mini gauge bar (below header on every page) */
#gauge-sticky { position: fixed; top: 0; left: 0; right: 0; height: 4px; z-index: 60; background: var(--bg-primary); }
#gauge-sticky-bar { height: 4px; width: 0; transition: width .6s ease; background: var(--green); }

/* Business card scanner — side-by-side review */
.scan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 760px) { .scan-grid { grid-template-columns: 1fr; } }
.conf-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: 6px; vertical-align: middle; }
.conf-green { background: var(--green); }
.conf-yellow { background: var(--yellow); }
.conf-red { background: var(--red); }
.conf-grey { background: var(--grey); }
.field-verify { color: var(--red); font-size: 11px; }
.field-note { color: var(--text-muted); font-size: 11px; }

/* RFQ 6-tab full-screen drawer. Reuses existing tokens only (no new colors/fonts/radii/shadows);
   overlay tint matches the existing .panel-overlay. Width 85vw per spec. */
.rfq-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
.rfq-drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 85vw; max-width: 85vw;
  background: var(--bg-secondary); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 50; }
.rfq-drawer-head { display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 16px 24px; border-bottom: 1px solid var(--border); }
.rfq-drawer .tabs { padding: 0 24px; margin: 0; }
.rfq-drawer-body { flex: 1; overflow-y: auto; padding: 18px 24px 40px; }
.rfq-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.rfq-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 18px; }
.rfq-econ-layout { display: grid; grid-template-columns: 1.5fr 1fr; gap: 24px; align-items: start; }
.elc-panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; position: sticky; top: 0; }
.elc-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.elc-row.total { font-weight: 700; border-bottom: none; }
.rfq-dropzone { border: 1px dashed var(--border); border-radius: var(--radius); padding: 22px; text-align: center;
  cursor: pointer; background: var(--bg-primary); color: var(--text-primary); }
.rfq-dropzone:hover { border-color: var(--accent); }
@media (max-width: 900px) { .rfq-drawer { width: 100vw; max-width: 100vw; }
  .rfq-econ-layout, .rfq-grid, .rfq-grid-3 { grid-template-columns: 1fr; } }

/* ---------- Factory detail — list sidebar + 6-tab detail (responsive) ---------- */
.fd-wrap { display: flex; gap: 20px; align-items: flex-start; }
.fd-list { width: 260px; flex: 0 0 260px; position: sticky; top: 16px; }
.fd-list #fd-search { width: 100%; margin-bottom: 10px; }
.fd-list-items { max-height: calc(100vh - 130px); overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.fd-list-item { display: block; padding: 8px 12px; border-bottom: 1px solid var(--border); color: var(--text-primary); text-decoration: none; }
.fd-list-item:last-child { border-bottom: none; }
.fd-list-item:hover { background: var(--bg-secondary); }
.fd-list-item.active { background: rgba(123,45,255,.12); border-left: 3px solid var(--accent); }
.fd-detail { flex: 1 1 auto; min-width: 0; }
.fd-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.fd-nav { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.fd-nav .btn[disabled] { opacity: .4; cursor: default; }
@media (max-width: 880px) {
  .fd-wrap { flex-direction: column; }
  .fd-list { width: 100%; flex-basis: auto; position: static; }
  .fd-list-items { max-height: 240px; }
}

/* ---------- Communications — Email inbox (list left, conversation right) ---------- */
.comms-wrap { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; min-height: 62vh; }
.comms-list { width: 320px; flex: 0 0 320px; border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.comms-list #ce-search { margin: 10px; width: calc(100% - 20px); }
.ce-list { overflow-y: auto; flex: 1 1 auto; }
.ce-list.muted { padding: 16px; }
.ce-thread { display: block; padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--text-primary); text-decoration: none; }
.ce-thread:hover { background: var(--bg-secondary); }
.ce-thread.active { background: rgba(123,45,255,.12); border-left: 3px solid var(--accent); }
.ce-thread.unread strong { font-weight: 700; }
.ce-thread.unread::before { content: '●'; color: var(--accent); margin-right: 6px; font-size: 10px; vertical-align: middle; }
.ce-thread-top { display: flex; justify-content: space-between; gap: 8px; }
.ce-thread .ce-when { font-size: 11px; white-space: nowrap; }
.ce-subj { font-size: 13px; margin: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ce-meta { font-size: 12px; }
.comms-detail { flex: 1 1 auto; min-width: 0; padding: 16px 20px; overflow-y: auto; }
.ce-detail-head { border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 12px; }
.ce-msg { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.ce-msg.ce-out { background: rgba(123,45,255,.06); }
.ce-msg-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.ce-msg-head .ce-when { margin-left: auto; font-size: 11px; }
.ce-to { font-size: 12px; margin: 2px 0 6px; }
.ce-body { font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.ce-atts { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 820px) {
  .comms-wrap { flex-direction: column; min-height: 0; }
  .comms-list { width: 100%; flex-basis: auto; border-right: none; border-bottom: 1px solid var(--border); max-height: 260px; }
}
