/* Visual inspirado no WMS PWA TOTVS (Ionic Material): cabeçalho petróleo, cards brancos com sombra suave. */
:root {
  --primary: #00445B;
  --primary-ink: #ffffff;
  --secondary: #009CC3;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #ECF1F8;
  --line: #d9e1ea;
  --text: #091A22;
  --muted: #74859A;
  --accent: #00445B;
  --accent-ink: #ffffff;
  --ok: #107048;
  --ok-bg: #e2f2ea;
  --warn: #8a6500;
  --warn-bg: #fdf3d6;
  --warn-strong: #efba2a;
  --bad: #be3e37;
  --bad-bg: #f9e4e2;
  --info-bg: #e3f3f8;
  --focus: #009CC3;
  --radius: 4px;
  --shadow: 0 3px 1px -2px rgba(0,0,0,.2), 0 2px 2px 0 rgba(0,0,0,.14), 0 1px 5px 0 rgba(0,0,0,.12);
  --mono: "Roboto Mono", ui-monospace, Consolas, monospace;
  --sans: "TOTVS", Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d1a20; --surface: #13252d; --surface-2: #1b313b; --line: #2a4450; --text: #e7eef3;
  --muted: #9bb0c0; --secondary: #3cc4e6; --accent: #3cc4e6; --accent-ink: #062029; --ok: #5fd39b; --ok-bg: #12352a;
  --warn: #f2cf6a; --warn-bg: #3a2f10; --bad: #ff8f87; --bad-bg: #3d1c1a; --info-bg: #123342; --focus: #3cc4e6;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
body { min-height: 100dvh; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Cabeçalho (ion-toolbar) */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px;
  height: 56px; padding: 0 8px 0 4px; background: var(--primary); color: var(--primary-ink);
  box-shadow: 0 2px 4px -1px rgba(0,0,0,.2), 0 4px 5px 0 rgba(0,0,0,.14), 0 1px 10px 0 rgba(0,0,0,.12);
}
.brand {
  background: none; border: 0; color: inherit; cursor: pointer; padding: 0 8px;
  font-size: 18px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.spacer { flex: 1; }
.who { font-size: 13px; opacity: .85; margin-right: 4px; }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  background: transparent; border: 0; color: inherit; cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }

main { padding: 0 0 24px; outline: none; }
main > *:not(.greeting):not(.cards) { margin-left: auto; margin-right: auto; }
main > * { max-width: 1280px; }
main > :not(.greeting) { margin-left: 16px; margin-right: 16px; }
@media (min-width: 1312px) { main > :not(.greeting) { margin-left: auto; margin-right: auto; } }
main > :first-child:not(.greeting) { margin-top: 16px; }

h1 { font-size: 20px; font-weight: 600; margin: 4px 0 14px; }
h2 { font-size: 15px; font-weight: 700; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* Saudação da tela inicial */
.greeting { max-width: none; padding: 10px 16px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.greeting h1 { font-size: 24px; font-weight: 400; margin: 0; }

/* Login */
.login { max-width: 400px; margin: 10vh auto 0 !important; background: var(--surface); border-radius: var(--radius); padding: 28px 24px; box-shadow: var(--shadow); }
.login h1 { margin-top: 0; color: var(--primary); font-size: 22px; }
:root[data-theme="dark"] .login h1 { color: var(--secondary); }

/* Cards (ion-card) */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 930px; margin: 8px auto 0 !important; padding: 0 12px; }
@media (max-width: 560px) { .cards { grid-template-columns: 1fr; } }
.card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  cursor: pointer; min-height: 100px; padding: 14px; background: var(--surface); border: 0; border-radius: var(--radius);
  box-shadow: var(--shadow); transition: box-shadow .15s, background .15s;
}
.card:hover { background: var(--surface-2); }
.card:active { box-shadow: none; }
.card-icon { color: var(--primary); display: grid; place-items: center; }
:root[data-theme="dark"] .card-icon { color: var(--secondary); }
.card .t { font-size: 14px; font-weight: 700; }

/* Campos (ion-input, estilo outline) */
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 12px 0 4px; }
input.in, select.in {
  width: 100%; min-height: 48px; padding: 10px 12px; background: var(--surface); border: 1px solid #b7c3cf; border-radius: var(--radius);
}
input.in:focus, select.in:focus { outline: none; border-color: var(--secondary); box-shadow: 0 0 0 1px var(--secondary); }
input.in.scan { font-size: 18px; }
input.in.ok { border-color: var(--ok); background: var(--ok-bg); }
input.in.bad { border-color: var(--bad); background: var(--bad-bg); }
input.in:disabled { opacity: .5; background: var(--surface-2); }

/* Botões (ion-button md) */
.btn {
  min-height: 40px; padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--primary); background: transparent;
  color: var(--primary); cursor: pointer; font-weight: 600; font-size: 14px; letter-spacing: .04em; text-transform: uppercase;
}
:root[data-theme="dark"] .btn { color: var(--secondary); border-color: var(--secondary); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: var(--shadow); }
:root[data-theme="dark"] .btn.primary { background: var(--secondary); border-color: var(--secondary); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.12); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.big { width: 100%; min-height: 50px; font-size: 15px; }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 12px; }

/* Painéis e listas (ion-list / ion-item) */
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.list { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item {
  display: grid; gap: 4px; text-align: left; width: 100%; padding: 12px 16px; cursor: pointer;
  background: var(--surface); border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
}
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--surface-2); }
.item .addr { font-weight: 700; font-size: 16px; color: var(--primary); }
:root[data-theme="dark"] .item .addr { color: var(--secondary); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 2px 10px; border-radius: 16px; background: var(--surface-2); color: var(--text); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

.banner { padding: 10px 12px; border-radius: var(--radius); margin: 8px 0; font-weight: 600; border-left: 4px solid transparent; }
.banner.ok { background: var(--ok-bg); color: var(--ok); border-left-color: var(--ok); }
.banner.warn { background: var(--warn-bg); color: var(--warn); border-left-color: var(--warn-strong); }
.banner.bad { background: var(--bad-bg); color: var(--bad); border-left-color: var(--bad); }
.banner.info { background: var(--info-bg); border-left-color: var(--secondary); }

.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0 4px; }
.steps span { height: 4px; border-radius: 2px; background: var(--line); }
.steps span.done { background: var(--ok); }
.steps span.cur { background: var(--secondary); }

.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--secondary); transition: width .2s; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 10px 0; }
.kpi { background: var(--surface-2); border-radius: var(--radius); padding: 8px 10px; }
.kpi b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; color: var(--primary); }
:root[data-theme="dark"] .kpi b { color: var(--secondary); }
.kpi small { color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 700; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.done td { color: var(--muted); }
tr.flash td { background: var(--ok-bg); }
.table-wrap { overflow-x: auto; }

.split { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .split { grid-template-columns: minmax(320px, 420px) 1fr; align-items: start; }
  .split.even { grid-template-columns: 1fr 1fr; }
}
.split .split { margin: 0 !important; }

dialog { border: 0; border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; width: min(560px, calc(100vw - 32px)); max-height: 85vh; box-shadow: 0 11px 15px -7px rgba(0,0,0,.2), 0 24px 38px 3px rgba(0,0,0,.14); }
dialog::backdrop { background: rgba(0,0,0,.32); }

/* Toast (ion-toast) */
.toast-zone { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(520px, calc(100vw - 32px)); }
.toast { padding: 12px 16px; border-radius: var(--radius); font-weight: 500; background: #2D3340; color: #fff; box-shadow: var(--shadow); }
.toast.ok { background: var(--ok); }
.toast.bad { background: var(--bad); }

.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--secondary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 520px) {
  .who { display: none; }
  .brand { font-size: 16px; }
  h1 { font-size: 18px; }
  .panel { padding: 12px; }
}
