/* ==========================================================================
   Documa - App Dashboard
   Layers dashboard-only components on the shared tokens in landing.css.
   Load landing.css first.
   ========================================================================== */

body.app { background: var(--bg); padding: 0 0 64px; }

.app-shell { max-width: 1340px; margin: 0 auto; padding: 26px 22px 0; }

/* ---------- Header ---------------------------------------------------- */

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 26px;
}
.app-header__brand { display: flex; align-items: center; gap: 12px; }
.app-header__h1 { margin: 0; line-height: 0; flex: none; }
.app-header__logo { height: 30px; width: auto; transition: opacity .18s ease; }
.app-header__brand:hover .app-header__logo { opacity: .82; }
.app-header__meta { min-width: 0; }
.app-header__actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

/* ---------- KPI row --------------------------------------------------- */

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
.kpi {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px 22px;
}
.kpi__k { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-4); margin: 0; }
.kpi__v { font-family: var(--mono); font-size: 27px; font-weight: 500; letter-spacing: -.03em; margin: 8px 0 4px; color: var(--ink); }
.kpi__s { font-size: 11.5px; color: var(--ink-4); margin: 0; }

.kpi--ok  { background: var(--ok-dim);  border-color: rgba(126,224,168,.26); }
.kpi--ok  .kpi__v, .kpi--ok  .kpi__s, .kpi--ok  .kpi__k { color: var(--ok); }
.kpi--bad { background: var(--bad-dim); border-color: rgba(255,128,128,.26); }
.kpi--bad .kpi__v, .kpi--bad .kpi__s, .kpi--bad .kpi__k { color: var(--bad); }
.kpi--info .kpi__v { color: var(--info); }

@media (max-width: 900px) { .kpis { grid-template-columns: 1fr; } }

/* ---------- Workspace grid -------------------------------------------- */

.workspace { display: grid; grid-template-columns: 5fr 7fr; gap: 18px; align-items: start; }
@media (max-width: 1080px) { .workspace { grid-template-columns: 1fr; } }

.col { display: flex; flex-direction: column; gap: 18px; }

.panel-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 22px;
}
.panel-card__h {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}
.panel-card__t { font-size: 13.5px; font-weight: 600; letter-spacing: -.01em; margin: 0; }
.panel-card__meta { font-family: var(--mono); font-size: 10.5px; color: var(--ink-4); }

/* ---------- Dropzone -------------------------------------------------- */

.dropzone {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 30px 20px;
  text-align: center;
  cursor: pointer;
  background: rgba(255,255,255,.015);
  transition: border-color .18s ease, background .18s ease;
}
.dropzone:hover { border-color: var(--ink-3); background: rgba(255,255,255,.04); }
.dropzone__icon { font-size: 21px; color: var(--ink-3); line-height: 1; }
.dropzone__t { font-size: 13px; font-weight: 500; margin: 11px 0 4px; }
.dropzone__s { font-size: 11.5px; color: var(--ink-4); margin: 0; }
.is-hidden { display: none; }

/* ---------- Scenario presets ------------------------------------------ */

.presets { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.preset {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease;
}
.preset:hover { border-color: var(--line-strong); background: var(--surface-3); }
.preset__l { display: flex; align-items: center; gap: 11px; min-width: 0; }
.preset__i {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 12px;
  background: var(--surface-3); color: var(--ink-2);
}
.preset__i--ok   { background: var(--ok-dim);   color: var(--ok); }
.preset__i--warn { background: var(--warn-dim); color: var(--warn); }
.preset__i--bad  { background: var(--bad-dim);  color: var(--bad); }
.preset__i--info { background: var(--info-dim); color: var(--info); }
.preset__t { font-size: 12.5px; font-weight: 500; margin: 0; }
.preset__s { font-size: 11px; color: var(--ink-4); margin: 2px 0 0; }
.preset__v { font-family: var(--mono); font-size: 12px; color: var(--ink-2); white-space: nowrap; }

/* ---------- Document preview ------------------------------------------ */

.doc-preview {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg-alt);
  padding: 8px;
  overflow: hidden;
}
.doc-preview img { border-radius: 7px; width: 100%; }

.doc-empty {
  display: grid; place-items: center; gap: 2px;
  padding: 54px 20px; text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: 7px;
  background: rgba(255, 255, 255, .012);
}
.doc-empty__glyph { font-size: 26px; color: var(--ink-4); line-height: 1; margin-bottom: 6px; }
.doc-empty__t { font-size: 13px; font-weight: 500; color: var(--ink-2); margin: 0; }
.doc-empty__s { font-size: 11.5px; color: var(--ink-4); margin: 0; }
.scan-laser {
  position: absolute; left: 0; right: 0; top: 0; height: 2px; z-index: 2;
  background: linear-gradient(90deg, transparent, var(--ok), transparent);
  box-shadow: 0 0 14px 2px rgba(126,224,168,.5);
  animation: scan 2.8s ease-in-out infinite;
}
@keyframes scan { 0%,100% { top: 2%; } 50% { top: 96%; } }

/* ---------- Agent pipeline -------------------------------------------- */

.agent {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
}
.agent + .agent { margin-top: 8px; }
.agent__l { display: flex; align-items: center; gap: 11px; min-width: 0; }
.agent__n {
  width: 24px; height: 24px; border-radius: 7px; flex: none;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 11px;
  background: var(--surface-3); color: var(--ink-2);
}
.agent__t { font-size: 12.5px; font-weight: 500; margin: 0; }
.agent__s { font-family: var(--mono); font-size: 10.5px; color: var(--ink-4); margin: 2px 0 0; }

/* ---------- Audit header ---------------------------------------------- */

.audit-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 18px; flex-wrap: wrap;
  padding-bottom: 18px; margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.audit-head__id { font-size: 16px; font-weight: 600; letter-spacing: -.02em; margin: 0; }
.audit-head__vendor { font-family: var(--mono); font-size: 11px; color: var(--ink-4); margin: 7px 0 0; }
.audit-head__total { font-family: var(--mono); font-size: 23px; font-weight: 500; letter-spacing: -.03em; margin: 4px 0 0; }

/* ---------- Output blocks --------------------------------------------- */

.md-box {
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 15px 17px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.75;
  color: var(--ink-2);
  white-space: pre-wrap;
  max-height: 250px;
  overflow-y: auto;
}
.feed {
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px 15px;
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.9;
  color: var(--ok);
  max-height: 150px;
  overflow-y: auto;
}
.feed p { margin: 0; }

.signoff {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--line);
}
.signoff__l { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; color: var(--warn); }

.btn--danger  { background: var(--bad-dim);  color: var(--bad);  border-color: rgba(255,128,128,.3); }
.btn--danger:hover  { background: rgba(255,128,128,.2); }
.btn--confirm { background: var(--ok-dim);   color: var(--ok);   border-color: rgba(126,224,168,.3); }
.btn--confirm:hover { background: rgba(126,224,168,.2); }

/* ---------- Modal ----------------------------------------------------- */

.modal {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(4,4,6,.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid; place-items: center;
  padding: 22px;
}
.modal[hidden] { display: none; }
.modal__box {
  width: 100%; max-width: 620px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  padding: 26px;
}
.modal__h {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding-bottom: 16px; margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.modal__t { font-size: 15px; font-weight: 600; margin: 0; }
.modal__x { background: none; border: 0; color: var(--ink-4); font-size: 20px; cursor: pointer; line-height: 1; padding: 0 4px; }
.modal__x:hover { color: var(--ink); }

.step { border: 1px solid var(--line); border-radius: 11px; padding: 15px 17px; background: var(--surface-2); }
.step + .step { margin-top: 11px; }
.step__t { font-size: 12.5px; font-weight: 600; margin: 0 0 5px; }
.step__d { font-family: var(--mono); font-size: 11px; color: var(--ink-4); margin: 0; line-height: 1.6; }
.step code { color: var(--info); }

/* ---------- Dialog ---------------------------------------------------- */

.dialog {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 22px;
  background: rgba(4, 4, 6, .78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: dlg-fade .16s ease;
}
.dialog[hidden] { display: none; }
@keyframes dlg-fade { from { opacity: 0; } }

.dialog__box {
  width: 100%; max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  padding: 26px;
  animation: dlg-rise .2s cubic-bezier(.2, .8, .3, 1);
}
@keyframes dlg-rise { from { opacity: 0; transform: translateY(8px) scale(.985); } }

.dialog__eyebrow {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--ink-4); margin: 0 0 14px;
}
.dialog__rule { flex: 1; height: 1px; background: var(--line); }
.dialog__t { font-size: 17px; font-weight: 600; letter-spacing: -.02em; margin: 0 0 9px; }
.dialog__d { font-size: 13px; color: var(--ink-3); margin: 0; line-height: 1.65; }
.dialog__d code { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.dialog__actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 24px; }

.dialog--danger  .dialog__eyebrow { color: var(--bad); }
.dialog--confirm .dialog__eyebrow { color: var(--ok); }

/* ---------- Toasts ---------------------------------------------------- */

.toasts {
  position: fixed; right: 22px; bottom: 22px; z-index: 120;
  display: flex; flex-direction: column-reverse; gap: 10px;
  max-width: calc(100vw - 44px);
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 11px;
  min-width: 280px; max-width: 400px;
  padding: 13px 16px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-left: 2px solid var(--ink-3);
  border-radius: 11px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .55);
  pointer-events: auto;
  animation: toast-in .24s cubic-bezier(.2, .8, .3, 1);
}
.toast.is-leaving { animation: toast-out .2s ease forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateX(14px); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(14px); } }

.toast__i { font-family: var(--mono); font-size: 12px; line-height: 1.5; flex: none; color: var(--ink-3); }
.toast__t { font-size: 12.5px; font-weight: 500; margin: 0; }
.toast__d { font-family: var(--mono); font-size: 11px; color: var(--ink-4); margin: 3px 0 0; line-height: 1.55; word-break: break-word; }

.toast--ok   { border-left-color: var(--ok); }
.toast--ok   .toast__i { color: var(--ok); }
.toast--bad  { border-left-color: var(--bad); }
.toast--bad  .toast__i { color: var(--bad); }
.toast--info { border-left-color: var(--info); }
.toast--info .toast__i { color: var(--info); }

@media (max-width: 560px) {
  .toasts { right: 12px; left: 12px; bottom: 12px; }
  .toast { min-width: 0; max-width: none; }
}

/* ==========================================================================
   Mobile
   ========================================================================== */

/* Grid and flex children default to min-width:auto, so a wide descendant
   (the 640px audit table) stretches its whole column instead of scrolling
   inside .table-wrap. Allowing them to shrink is what actually keeps the
   page within the viewport. */
.workspace > *, .col > *, .panel-card, .audit-head > *, .panel-card__h > * { min-width: 0; }

/* Long values must be able to wrap rather than push the layout wide. */
.md-box, .feed, .feed p { overflow-wrap: anywhere; }
.agent__t, .agent__s, .preset__t, .preset__s, .audit-head__vendor { overflow-wrap: anywhere; }

/* Headers carry a title plus badges plus buttons; let them stack. */
.panel-card__h { flex-wrap: wrap; }

/* ---------- Hamburger ------------------------------------------------- */

.app-header__nav { position: relative; display: flex; align-items: center; gap: 9px; }

.burger {
  display: none;
  width: 38px; height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
  padding: 0;
  place-items: center;
  align-content: center;
  gap: 4px;
  transition: border-color .16s ease, background .16s ease;
}
.burger:hover { border-color: var(--ink-3); background: var(--surface-3); }
.burger span {
  display: block;
  width: 16px; height: 1.5px;
  background: var(--ink-2);
  border-radius: 2px;
  transition: transform .2s ease, opacity .16s ease;
}
.burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(5.5px) rotate(45deg); }
.burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-5.5px) rotate(-45deg); }

@media (max-width: 820px) {
  .burger { display: grid; }

  /* The header actions become a dropdown panel anchored under the burger. */
  .app-header__actions {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 80;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    min-width: 210px;
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 13px;
    box-shadow: 0 18px 44px rgba(0, 0, 0, .6);
    animation: menu-in .16s ease;
  }
  .app-header__actions.is-open { display: flex; }
  .app-header__actions .btn { justify-content: center; width: 100%; }
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-5px); } }

/* ---------- Layout at phone widths ------------------------------------ */

@media (max-width: 820px) {
  .app-shell { padding: 18px 14px 0; }

  .app-header { gap: 14px; padding-bottom: 18px; margin-bottom: 20px; flex-wrap: nowrap; }
  .app-header__brand { gap: 10px; min-width: 0; }
  .app-header__brand > div { min-width: 0; }
  .app-header__brand .row { flex-wrap: wrap; gap: 7px; }
  .app-header__logo { height: 25px; }

  .panel-card { padding: 17px 15px; }
  .kpi { padding: 17px 16px; }
  .kpi__v { font-size: 24px; }

  .workspace, .col { gap: 14px; }
  .kpis { gap: 12px; margin-bottom: 16px; }

  /* Badges may wrap onto their own line rather than force the row wide. */
  .badge { white-space: normal; }
  .audit-head { gap: 12px; }
  .audit-head > div:last-child { text-align: left !important; }

  .dialog__box { padding: 22px 19px; }
  .dialog__actions { flex-direction: column-reverse; }
  .dialog__actions .btn { width: 100%; justify-content: center; }

  .md-box { max-height: 210px; }
}

@media (max-width: 480px) {
  /* Below this the brand row wraps and strands the mark beside a second line.
     Drop the static model badge; the live Cloud Run pill is the one that matters. */
  .badge--meta { display: none; }
}

@media (max-width: 420px) {
  .app-shell { padding: 14px 11px 0; }
  .panel-card, .kpi { padding: 15px 13px; }
  .preset { padding: 11px 12px; }
  .preset__v { font-size: 11px; }
  .audit-head__id { font-size: 15px; }
  .audit-head__total { font-size: 20px; }
}
