/* Petramax Portal design system.
   Tokens + component classes translated from the design handoff prototype
   (design/petramax-portal-prototype.dc.html). Two themes: steel (light,
   default) and field (dark), switched by setting data-theme on <html>. */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Open Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--app-bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
input, select, textarea, button { font-family: inherit; }
::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

@keyframes pmxIn   { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pmxSlide{ from { transform: translateX(28px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pmxFade { from { opacity: 0; } to { opacity: 1; } }

:root, [data-theme="steel"] {
  --app-bg: #eceff3; --panel: #ffffff; --panel-2: #f6f8fa;
  --sidebar: #16283b; --sidebar-text: #aebccb; --sidebar-active-bg: #223c58; --sidebar-active-text: #ffffff;
  --text: #1a2733; --text-muted: #5c6b7a; --text-faint: #9aa8b6;
  --primary: #2e6da4; --primary-dark: #235784; --primary-soft: #e5eef6;
  --border: #dde3ea; --border-strong: #cdd6e0; --scroll: #c3ccd6;
  --ok: #2f8f5b; --ok-soft: #e3f2ea; --warn: #b7791f; --warn-soft: #f7eed8; --bad: #c0483b; --bad-soft: #f6e2df;
  --shadow: 0 1px 2px rgba(16,32,48,.06), 0 4px 16px rgba(16,32,48,.05); --shadow-lg: 0 12px 40px rgba(16,32,48,.18);
}
[data-theme="field"] {
  --app-bg: #161c24; --panel: #212a35; --panel-2: #1a222c;
  --sidebar: #0e131a; --sidebar-text: #90a1b3; --sidebar-active-bg: #1c2530; --sidebar-active-text: #ffffff;
  --text: #e7eef5; --text-muted: #93a2b3; --text-faint: #667585;
  --primary: #3d8fd6; --primary-dark: #2f79ba; --primary-soft: #1a2f43;
  --border: #303b48; --border-strong: #3c4956; --scroll: #3c4956;
  --ok: #46b477; --ok-soft: #16321f; --warn: #d69a3a; --warn-soft: #332714; --bad: #d9695c; --bad-soft: #331c1a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.28); --shadow-lg: 0 16px 50px rgba(0,0,0,.5);
}

.mono { font-family: 'IBM Plex Mono', monospace; }
[x-cloak] { display: none !important; }

/* ---------- App frame ---------- */
.pmx-app { min-height: 100vh; display: flex; }
.pmx-aside {
  width: 236px; flex: 0 0 236px; background: var(--sidebar);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.pmx-brand { padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.pmx-brand-mark {
  width: 34px; height: 34px; border-radius: 7px; background: var(--primary);
  display: flex; align-items: center; justify-content: center; flex: 0 0 34px;
}
.pmx-wordmark { font-family: 'Barlow Semi Condensed', sans-serif; font-weight: 700; letter-spacing: .06em; color: #fff; font-size: 18px; line-height: 1; }
.pmx-tagline { font-size: 10px; letter-spacing: .14em; color: var(--sidebar-text); text-transform: uppercase; margin-top: 3px; }
.pmx-nav { flex: 1; padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; }
.pmx-nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; cursor: pointer; transition: background .12s;
  color: var(--sidebar-text); background: transparent;
}
.pmx-nav-item:hover { color: #fff; }
.pmx-nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
.pmx-nav-item .pmx-ico { display: flex; align-items: center; justify-content: center; width: 20px; height: 20px; }
.pmx-nav-item .pmx-label { flex: 1; }
.pmx-nav-badge { font-family: 'IBM Plex Mono', monospace; font-size: 11px; background: var(--primary); color: #fff; border-radius: 10px; padding: 1px 7px; }
.pmx-footer { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 10px; }
.pmx-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex: 0 0 32px; }
.pmx-footer .name { color: #fff; font-size: 13px; font-weight: 600; }
.pmx-footer .role { color: var(--sidebar-text); font-size: 11px; }

.pmx-mainwrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pmx-topbar {
  height: 62px; flex: 0 0 62px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 26px; position: sticky; top: 0; z-index: 20;
}
.pmx-title { font-family: 'Barlow', sans-serif; font-weight: 700; font-size: 19px; line-height: 1; }
.pmx-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.pmx-spacer { flex: 1; }
.pmx-search { position: relative; width: 280px; max-width: 34vw; }
.pmx-search .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; display: flex; }
.pmx-search input { width: 100%; height: 38px; border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--text); border-radius: 8px; padding: 0 12px 0 34px; font-size: 13px; }
.pmx-theme-btn { height: 38px; border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--text-muted); border-radius: 8px; padding: 0 12px; font-size: 12px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.pmx-theme-btn .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); display: inline-block; }
.pmx-content { flex: 1; overflow: auto; padding: 26px; }
.pmx-view { animation: pmxIn .35s ease both; }

/* ---------- Cards / KPI ---------- */
.pmx-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.pmx-card.pad { padding: 18px; }
.pmx-card.clip { overflow: hidden; }
.pmx-card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.pmx-card-title { font-family: 'Barlow', sans-serif; font-weight: 700; font-size: 16px; }
.pmx-kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.pmx-kpi { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px 18px 16px; box-shadow: var(--shadow); }
.pmx-kpi .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.pmx-kpi .value { font-family: 'Barlow', sans-serif; font-weight: 700; font-size: 32px; line-height: 1.1; margin-top: 8px; }
.pmx-kpi .sub { font-size: 12px; margin-top: 6px; font-weight: 600; }

/* ---------- Tables ---------- */
.pmx-tablewrap { overflow: auto; }
.pmx-table { width: 100%; border-collapse: collapse; }
.pmx-table thead tr { text-align: left; background: var(--panel-2); }
.pmx-table th { padding: 12px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 700; white-space: nowrap; }
.pmx-table th.first, .pmx-table td.first { padding-left: 18px; }
.pmx-table th.last, .pmx-table td.last { padding-right: 18px; }
.pmx-table th.num, .pmx-table td.num { text-align: right; }
.pmx-table th.sortable { cursor: pointer; }
.pmx-table tbody tr { border-top: 1px solid var(--border); }
.pmx-table tbody tr.click { cursor: pointer; }
.pmx-table tbody tr.click:hover { background: var(--panel-2); }
.pmx-table td { padding: 11px 12px; font-size: 13px; }
.pmx-table td.muted { color: var(--text-muted); }
.pmx-table td.id { font-family: 'IBM Plex Mono', monospace; font-size: 12.5px; color: var(--primary); font-weight: 600; }
.pmx-table td.mono { font-family: 'IBM Plex Mono', monospace; font-size: 12.5px; }
.pmx-sub { font-size: 11.5px; color: var(--text-muted); }

/* ---------- Pills ---------- */
.pmx-pill { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; letter-spacing: .02em; }
.pmx-pill.ok   { background: var(--ok-soft);   color: var(--ok); }
.pmx-pill.warn { background: var(--warn-soft); color: var(--warn); }
.pmx-pill.bad  { background: var(--bad-soft);  color: var(--bad); }

/* ---------- Controls ---------- */
.pmx-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.pmx-count { font-size: 13px; color: var(--text-muted); }
.pmx-select, .pmx-date { height: 38px; border: 1px solid var(--border-strong); background: var(--panel); color: var(--text); border-radius: 8px; padding: 0 12px; font-size: 13px; }
.pmx-input { height: 38px; border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--text); border-radius: 8px; padding: 0 12px; font-size: 13px; }
.pmx-btn { height: 38px; border: 1px solid var(--border-strong); background: var(--panel); color: var(--text); border-radius: 8px; padding: 0 14px; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.pmx-btn:hover { border-color: var(--primary); }
.pmx-btn.primary { border: none; background: var(--primary); color: #fff; }
.pmx-btn.primary:hover { background: var(--primary-dark); }
.pmx-btn.accent { border: 1px solid var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.pmx-btn.ok { border: none; background: var(--ok); color: #fff; font-weight: 700; }
.pmx-btn[disabled] { opacity: .5; cursor: not-allowed; }
.pmx-iconbtn { border: none; background: transparent; color: var(--text-faint); cursor: pointer; font-size: 16px; line-height: 1; padding: 0; }
.pmx-iconbtn:hover { color: var(--bad); }

/* ---------- Grids (dashboard / bulk / trends) ---------- */
.pmx-dash-grid { display: grid; grid-template-columns: 1.7fr 1fr; gap: 16px; }
.pmx-stack { display: flex; flex-direction: column; gap: 16px; }
.pmx-bulk-grid { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.pmx-trend-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.pmx-trend-stat { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; box-shadow: var(--shadow); }
.pmx-trend-stat .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.pmx-trend-stat .value { font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 20px; margin-top: 6px; }

/* delivery bars */
.pmx-bar-row { margin-bottom: 14px; }
.pmx-bar-head { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 5px; }
.pmx-bar-track { height: 8px; border-radius: 5px; background: var(--panel-2); overflow: hidden; }
.pmx-bar-fill { height: 100%; border-radius: 5px; }

/* quick actions */
.pmx-qa { text-align: left; border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--text); border-radius: 9px; padding: 12px 14px; cursor: pointer; font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 10px; width: 100%; }
.pmx-qa .lead { color: var(--primary); }

/* empty state */
.pmx-empty { padding: 40px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ---------- Report drawer ---------- */
.pmx-drawer-backdrop { position: fixed; inset: 0; background: rgba(10,20,32,.5); z-index: 60; animation: pmxFade .2s ease both; display: flex; justify-content: flex-end; }
.pmx-drawer { width: 520px; max-width: 94vw; height: 100%; background: var(--panel); box-shadow: var(--shadow-lg); overflow: auto; animation: pmxSlide .28s cubic-bezier(.2,.8,.2,1) both; }
.pmx-drawer-head { padding: 22px 26px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; justify-content: space-between; position: sticky; top: 0; background: var(--panel); z-index: 2; }
.pmx-drawer-kicker { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.pmx-drawer-id { font-family: 'Barlow', sans-serif; font-weight: 700; font-size: 22px; margin-top: 3px; }
.pmx-drawer-close { border: none; background: var(--panel-2); color: var(--text-muted); width: 34px; height: 34px; border-radius: 8px; font-size: 20px; cursor: pointer; }
.pmx-drawer-body { padding: 22px 26px; }
.pmx-meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; margin-bottom: 22px; }
.pmx-meta .k { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.pmx-meta .v { font-size: 14px; margin-top: 3px; }
.pmx-meta .v.id { font-family: 'IBM Plex Mono', monospace; color: var(--primary); font-weight: 600; }
.pmx-elem-list { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 22px; }
.pmx-elem-row { display: flex; justify-content: space-between; align-items: center; padding: 11px 15px; border-top: 1px solid var(--border); }
.pmx-elem-row:first-child { border-top: none; }
.pmx-elem-row.odd { background: var(--panel-2); }
.pmx-elem-row.critical { background: var(--warn-soft); border-left: 3px solid var(--warn); }
.pmx-elem-label { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 8px; }
.pmx-elem-val { font-family: 'IBM Plex Mono', monospace; font-size: 13.5px; font-weight: 600; }
.pmx-elem-row.critical .pmx-elem-val { font-weight: 700; color: var(--warn); }
.pmx-tag { font-size: 9.5px; font-weight: 700; letter-spacing: .04em; color: var(--warn); background: var(--panel); padding: 1px 6px; border-radius: 10px; border: 1px solid var(--warn); }
.pmx-note { font-size: 11.5px; color: var(--text-faint); text-align: center; margin-top: 12px; }
.pmx-banner { padding: 12px 14px; background: var(--ok-soft); color: var(--ok); border-radius: 8px; font-size: 13px; font-weight: 600; }

/* ---------- Locations editable table ---------- */
.pmx-loc-table td { padding: 0; }
.pmx-loc-cell { width: 100%; border: none; background: transparent; color: var(--text); padding: 11px 14px; font-size: 13px; }
.pmx-loc-cell.id { font-family: 'IBM Plex Mono', monospace; color: var(--primary); font-weight: 600; }
.pmx-loc-cell:focus { outline: 2px solid var(--primary); outline-offset: -2px; background: var(--panel-2); }
.pmx-th-flex { display: inline-flex; align-items: center; gap: 6px; }

/* import panel */
.pmx-import { border-color: var(--primary); padding: 20px; margin-bottom: 18px; animation: pmxIn .25s ease both; }
.pmx-textarea { width: 100%; height: 120px; border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--text); border-radius: 8px; padding: 11px 12px; font-family: 'IBM Plex Mono', monospace; font-size: 12.5px; resize: vertical; }
.pmx-map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-bottom: 16px; }
.pmx-map-card { border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; background: var(--panel-2); }

/* charts */
.pmx-chart { width: 100%; height: auto; display: block; overflow: visible; }

/* ---------- Responsive: sidebar -> bottom tab bar (<760px) ---------- */
@media (max-width: 759px) {
  .pmx-aside {
    width: auto; flex: none; flex-direction: row; position: fixed; bottom: 0; left: 0; right: 0;
    top: auto; height: auto; z-index: 50; border-top: 1px solid rgba(255,255,255,.1);
  }
  .pmx-brand, .pmx-footer { display: none; }
  .pmx-nav { flex-direction: row; padding: 6px 4px; gap: 2px; }
  .pmx-nav-item { flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 7px 4px; font-size: 9.5px; flex: 1; text-align: center; line-height: 1.1; }
  .pmx-nav-item .pmx-label { flex: none; }
  .pmx-topbar { height: 56px; flex-basis: 56px; gap: 10px; padding: 0 14px; }
  .pmx-titlewrap, .pmx-spacer { display: none; }
  .pmx-search { width: auto; flex: 1; min-width: 0; max-width: none; }
  .pmx-content { padding: 16px; padding-bottom: 88px; }
  .pmx-kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 18px; }
  .pmx-dash-grid { grid-template-columns: 1fr; gap: 14px; }
  .pmx-bulk-grid { grid-template-columns: 1fr; gap: 14px; }
  .pmx-trend-stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}
