/* =====================================================================
   WMS Web - UI layer (loaded inline on every app page, so it can never be missed in an upload).
   Consistent spacing, cards, stacked form fields, toggle switches, tabs and a tidier top bar.
   ===================================================================== */
:root { --ring: 0 0 0 3px rgba(37,99,235,.18); }
body { -webkit-font-smoothing: antialiased; }
.content { padding: 1.5rem 2rem 3rem; max-width: 1240px; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; margin: 0 0 .3rem; }
h2 { font-size: 1.02rem; margin: 1.6rem 0 .7rem; }
h3 { font-size: .95rem; }
.muted { color: var(--slate-500); } .small { font-size: .8rem; } .block { display: block; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin: 0 0 1.2rem; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 .15rem; } .page-head p { margin: 0; }
p { margin: 0 0 .9rem; }

/* ---- top bar ---- */
.topbar { padding: .7rem 1.5rem; gap: .75rem; box-shadow: 0 1px 0 var(--slate-200); }
.site-chip { display: inline-flex; align-items: center; gap: .4rem; background: var(--slate-100); border: 1px solid var(--slate-200); color: var(--navy-800); padding: .3rem .75rem; border-radius: 999px; font-size: .8rem; font-weight: 600; max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-chip svg { width: 14px; height: 14px; flex-shrink: 0; color: var(--blue-600); }
@media (min-width: 901px) { .topbar .page-title { display: none; } }
@media (max-width: 700px) { .site-chip { display: none; } }

/* ---- menu ---- */
.nav-group { padding: 1rem 1.15rem .35rem; font-size: .64rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #64748b; }
.side-nav .nav-group:first-child { padding-top: .4rem; }

/* ---- cards, notices, flash messages ---- */
.card { background: #fff; border: 1px solid var(--slate-200); border-radius: 12px; box-shadow: var(--shadow-sm); padding: 1rem 1.25rem; margin: 0 0 1.25rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0 0 .5rem; }
.card-head h2 { margin: 0; font-size: 1rem; }
.card-tools { display: inline-flex; gap: .4rem; }
.card .table-scroll { margin: 0 -1.25rem; }
.card table.grid { border: none; box-shadow: none; border-radius: 0; margin: 0; }
.notice { background: var(--amber-50); border: 1px solid #fde68a; color: #92400e; border-radius: 10px; padding: .65rem .95rem; margin: 0 0 1rem; }
p.ok, p.error { padding: .65rem .95rem; border-radius: 10px; margin: 0 0 1rem; border: 1px solid; }
p.ok { background: var(--green-50); color: #166534; border-color: #bbf7d0; }
p.error { background: var(--red-50); color: #991b1b; border-color: #fecaca; }
.hint { background: var(--blue-50) !important; border: 1px solid #bfdbfe !important; color: #1e3a8a !important; border-radius: 10px !important; padding: .7rem 1rem !important; max-width: none !important; margin: .3rem 0 1rem !important; }
.action-bar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin: 1rem 0 1.5rem; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }

/* ---- buttons ---- */
button, .btn { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font-weight: 600; text-decoration: none; cursor: pointer; border-radius: 8px; }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-sm { min-height: 30px; padding: .2rem .65rem; font-size: .8rem; }
td.row-actions .mode-view, td.row-actions .mode-edit { display: inline-flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
td.row-actions .mode-edit { display: none; } tr.editable-row.editing td.row-actions .mode-edit { display: inline-flex; } tr.editable-row.editing td.row-actions .mode-view { display: none; }

/* ---- forms: label ABOVE the field, one tidy grid, nothing ragged ---- */
input[type=text], input[type=password], input[type=number], input[type=email], input[type=date], input[type=file], select, textarea { min-height: 38px; }
textarea { padding: .55rem .7rem; border: 1px solid var(--slate-300); border-radius: 8px; font: inherit; resize: vertical; }
.form-card { display: grid !important; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem 1.25rem; align-items: start; background: #fff; border: 1px solid var(--slate-200); border-radius: 12px; padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm); margin: 0 0 1.25rem; max-width: none !important; }
.form-card.flat { border: none; border-top: 1px solid var(--slate-100); box-shadow: none; border-radius: 0; padding: 1rem 0 0; margin: .5rem 0 0; }
.form-card.stack { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.form-card label:not(.is-check) { display: flex !important; flex-direction: column; gap: .35rem; margin: 0; font-size: .72rem; font-weight: 700; color: var(--slate-500); text-transform: uppercase; letter-spacing: .04em; min-width: 0; }
.form-card label small { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: .76rem; }
.form-card label input[type=text], .form-card label input[type=password], .form-card label input[type=number], .form-card label input[type=email], .form-card label input[type=file], .form-card label select, .form-card label textarea { width: 100% !important; max-width: 100%; text-transform: none; letter-spacing: 0; font-size: .9rem; font-weight: 400; color: var(--navy-900); }
.form-card label.is-check { display: flex; align-items: center; gap: .5rem; font-weight: 500; font-size: .88rem; color: var(--navy-800); text-transform: none; letter-spacing: 0; margin: 0; }
.form-card > h2, .form-card > h3, .form-card > p, .form-card > div, .form-card > fieldset, .form-card > .full, .form-card > label.full, .form-card > label.is-check { grid-column: 1 / -1; }
.form-card > button, .form-card > .btn { justify-self: start; align-self: end; }
.form-card label small#price_hint { min-height: 1.1em; }
.form-card fieldset { border: 1px solid var(--slate-200); border-radius: 10px; padding: .8rem 1rem; margin: 0; }
.form-card fieldset legend { padding: 0 .4rem; font-size: .75rem; font-weight: 700; color: var(--slate-500); text-transform: uppercase; letter-spacing: .04em; }
@media (max-width: 700px) { .form-card.stack { grid-template-columns: 1fr; } }
.filter-bar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

/* ---- tables ---- */
.table-scroll { margin: 0 0 1.25rem; }
table.grid { margin: 0 0 1.25rem; }
table.grid th { white-space: nowrap; }
table.grid td { vertical-align: middle; }
.table-scroll + .form-card, table.grid + .form-card { margin-top: 0; }

/* ---- settings screen: title + explanation left, control right ---- */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; padding: .85rem 0; border-bottom: 1px solid var(--slate-100); }
.card .setting-row:last-child { border-bottom: none; padding-bottom: .3rem; }
.setting-text { min-width: 0; }
.setting-text strong { display: block; font-size: .92rem; color: var(--navy-900); font-weight: 600; }
.setting-text small { display: block; color: var(--slate-500); font-size: .8rem; margin-top: .15rem; max-width: 70ch; line-height: 1.4; }
.setting-control { flex-shrink: 0; }
.setting-control input, .setting-control select { width: auto; min-width: 150px; }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; margin: 0 !important; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch .slider { position: absolute; inset: 0; background: var(--slate-300); border-radius: 999px; transition: background .15s; }
.switch .slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + .slider { background: var(--blue-600); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { box-shadow: var(--ring); }
@media (max-width: 700px) { .setting-row { flex-direction: column; align-items: stretch; gap: .6rem; } .setting-row .switch { align-self: flex-start; } .setting-control input, .setting-control select { width: 100%; } }

/* ---- role permissions ---- */
.role-tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin: 0 0 1.1rem; border-bottom: 1px solid var(--slate-200); }
.role-tab { padding: .55rem 1rem; border-radius: 8px 8px 0 0; text-decoration: none; color: var(--slate-500); font-weight: 600; border: 1px solid transparent; border-bottom: none; margin-bottom: -1px; font-size: .88rem; }
.role-tab:hover { color: var(--navy-900); background: var(--slate-100); }
.role-tab.active { background: #fff; color: var(--blue-600); border-color: var(--slate-200); }
.role-tab small { font-size: .62rem; text-transform: uppercase; letter-spacing: .06em; background: var(--slate-100); color: var(--slate-500); padding: .05rem .4rem; border-radius: 999px; margin-left: .3rem; vertical-align: middle; }
.perm-table th.pc, .perm-table td.pc, .perm-table td.pc-na { text-align: center; width: 120px; }
.perm-table td.pc-na { color: var(--slate-300); }
.perm-table td.pc input { width: 18px; height: 18px; accent-color: var(--blue-600); cursor: pointer; }
.perm-table td.pc input:disabled { cursor: not-allowed; opacity: .55; }
.perm-table tr.grp td { background: var(--slate-50); font-size: .68rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--slate-500); padding: .45rem .9rem; }

/* ---- company profile ---- */
.logo-box { display: flex; gap: 1.25rem; align-items: center; padding: 1rem; border: 1px dashed var(--slate-300); border-radius: 10px; background: var(--slate-50); flex-wrap: wrap; }
.logo-preview { width: 150px; height: 92px; display: flex; align-items: center; justify-content: center; background: #fff; border: 1px solid var(--slate-200); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-controls { display: flex; flex-direction: column; gap: .6rem; flex: 1; min-width: 220px; }

/* ---- live weight card ---- */
.wb-card { min-width: 280px; }
.wb-card .status { white-space: nowrap; }
.wb-card .weight { font-variant-numeric: tabular-nums; }

/* ---- phone ---- */
@media (max-width: 700px) {
  .content { padding: 1rem .9rem 2.5rem; }
  .form-card, .card { padding: .9rem; }
  .card .table-scroll { margin: 0 -.9rem; }
  .topbar { padding: .5rem .75rem; }
  .wb-card { min-width: 0; width: 100%; }
}

/* ---- manual weight box: compact fields (the weight is at most 10 digits - it does not need the whole width) ---- */
.manual-fields { border: 1px solid var(--slate-200); border-radius: 10px; padding: .8rem 1rem 1rem; margin: .4rem 0 0; grid-column: 1 / -1; width: 100%; }
.manual-fields legend { padding: 0 .4rem; font-size: .75rem; font-weight: 700; color: var(--slate-500); text-transform: uppercase; letter-spacing: .04em; }
.manual-row { display: flex; flex-wrap: wrap; gap: .9rem 1.2rem; align-items: flex-end; margin-top: .6rem; }
.manual-row label { display: flex; flex-direction: column; gap: .3rem; font-size: .72rem; font-weight: 700; color: var(--slate-500); text-transform: uppercase; letter-spacing: .04em; margin: 0; }
.manual-row .weight-input { width: 13ch !important; max-width: 13ch; font-variant-numeric: tabular-nums; text-align: right; }
.manual-row .pw-input { width: 15rem !important; max-width: 100%; }
.manual-row label.grow { flex: 1 1 16rem; } .manual-row label.grow input { width: 100% !important; max-width: 28rem; }
.narrow-input { width: 9rem !important; max-width: 100%; }
@media (max-width: 700px) { .manual-row label, .manual-row .pw-input { width: 100% !important; } .manual-row .weight-input { width: 13ch !important; } }
.live-top { margin: 0 0 1rem; }
.capture-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem 1.2rem; margin: 1rem 0 1.5rem; }
.capture-bar .to-capture { font-size: 1.05rem; }
.capture-bar button.primary-lg { min-height: 46px; padding: .6rem 1.6rem; font-size: 1rem; }
.inline-field { display: inline-flex; align-items: center; gap: .6rem; font-weight: 600; font-size: .85rem; margin: 0 0 .6rem; }
.inline-field select { min-width: 200px; }
.live-top .wb-cards { margin: 0 0 .5rem; }
.is-hidden { display: none !important; }

/* ---- visible dropdown for type-ahead fields ---- */
input.has-cb, input[type=text].has-cb { padding-right: 2rem !important; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2364748b'%3E%3Cpath d='M5.5 7.5l4.5 4.5 4.5-4.5z'/%3E%3C/svg%3E") !important; background-repeat: no-repeat !important; background-position: right .55rem center !important; background-size: 1rem !important; }
.cb-pop { position: absolute; z-index: 3000; display: none; background: #fff; border: 1px solid var(--slate-300); border-radius: 10px; box-shadow: 0 12px 32px rgba(15,23,42,.2); max-height: 280px; overflow-y: auto; padding: .3rem; font-size: .92rem; max-width: min(92vw, 520px); }
.cb-pop.open { display: block; }
.cb-item { padding: .5rem .7rem; border-radius: 7px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--navy-900); }
.cb-item:hover, .cb-item.active { background: var(--blue-50); color: var(--blue-700); }
.cb-item mark { background: none; font-weight: 700; color: var(--blue-700); }
.cb-empty { padding: .6rem .7rem; color: var(--slate-500); font-size: .84rem; white-space: normal; }
.type-fix { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: center; margin: .2rem 0 1rem; }
.type-fix .inline-field { margin: 0; }
.form-card .is-hidden, .form-card label.is-hidden { display: none !important; }

/* ---- camera photos ---- */
.photo-card { margin: 1rem 0; } .photo-group h4 { margin: .6rem 0 .3rem; font-size: .85rem; color: var(--slate-500); text-transform: uppercase; letter-spacing: .04em; }
.photo-row { display: flex; flex-wrap: wrap; gap: .7rem; } .photo-row figure { margin: 0; width: 170px; }
.photo-row img { width: 170px; height: 100px; object-fit: cover; border-radius: 8px; border: 1px solid var(--slate-200); background: #e2e8f0; display: block; }
.photo-row figcaption { font-size: .75rem; margin-top: .25rem; color: var(--navy-900); }

/* ---- live cameras ---- */
.cam-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; margin-top: 1rem; }
.cam-tile { background: #fff; border: 1px solid var(--slate-200); border-radius: 12px; padding: .6rem; } .cam-tile.cam-big { grid-column: 1 / -1; }
.cam-head { display: flex; gap: .4rem; align-items: baseline; margin-bottom: .4rem; font-size: .9rem; } .cam-state { margin-left: auto; font-size: .75rem; }
.cam-view { position: relative; aspect-ratio: 16 / 9; background: #0f172a; border-radius: 8px; overflow: hidden; cursor: zoom-in; }
.cam-tile.cam-big .cam-view { cursor: zoom-out; }
.cam-view img { width: 100%; height: 100%; object-fit: contain; display: block; } .cam-view img:not([src]) { visibility: hidden; }
.cam-msg { position: absolute; inset: auto 0 0 0; padding: .5rem .7rem; font-size: .8rem; color: #e2e8f0; background: rgba(15, 23, 42, .78); }
.cam-msg.cam-bad { background: rgba(127, 29, 29, .9); color: #fff; font-weight: 600; }
.cam-warn { display: block; margin-top: .25rem; font-size: .75rem; color: #b91c1c; }
