:root {
  --bg: #f4f6f9; --card: #fff; --line: #e3e7ee; --text: #0f1b2d; --muted: #5d6b7e;
  --primary: #001428; --accent: #0050cc; --accent-soft: #e8efff; --ok: #0f8a4f; --ok-soft: #e6f6ee;
  --warn: #b25e00; --warn-soft: #fff3e3; --danger: #c62828; --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 Inter, system-ui, sans-serif; color: var(--text); background: var(--bg); }
.hidden { display: none !important; }
.ms { font-family: 'Material Symbols Outlined'; font-size: 20px; line-height: 1; vertical-align: middle; font-weight: normal; font-style: normal; letter-spacing: normal; text-transform: none; white-space: nowrap; direction: ltr; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #c5ccd8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0044ad; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 6px; }
.btn:disabled { opacity: .5; cursor: default; }
input, textarea, select { font: inherit; color: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 40px; }
label { display: block; font-weight: 600; font-size: 12px; color: var(--muted); }
label > input, label > textarea, label > select { margin-top: 4px; font-weight: 400; font-size: 14px; color: var(--text); }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 3px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--primary); }
.login-card { width: 100%; max-width: 360px; background: var(--card); padding: 28px; border-radius: 14px; display: grid; gap: 14px; }
.error { color: var(--danger); margin: 0; min-height: 1em; font-size: 13px; }

/* Layout */
.brand { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.brand small { font-weight: 500; font-size: 12px; color: var(--muted); }
.app { display: grid; grid-template-columns: 270px 1fr; height: 100%; }
.sidebar { background: var(--primary); color: #dfe6f3; display: flex; flex-direction: column; padding: 18px 12px; overflow-y: auto; }
.sidebar .brand { color: #fff; padding: 0 8px 16px; }
.sidebar .brand small { color: #8fa3c0; }
.sidebar nav { flex: 1; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7f93b3; padding: 14px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: none; border: 0; color: inherit; padding: 7px 10px; border-radius: 7px; cursor: pointer; font: inherit; }
.nav-item:hover { background: rgba(255,255,255,.07); }
.nav-item.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.nav-item .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { flex-shrink: 0; font-size: 11px; background: rgba(255,255,255,.12); padding: 1px 7px; border-radius: 10px; }
.nav-item .count.mod { background: #f0a53a; color: #1f1000; }
.sidebar-foot { display: flex; gap: 6px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-foot .btn { color: #dfe6f3; }
.main { overflow-y: auto; display: flex; flex-direction: column; min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 5; background: rgba(244,246,249,.92); backdrop-filter: blur(6px); display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 19px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.page { padding: 20px 24px 60px; max-width: 1100px; width: 100%; }
.only-mobile { display: none; }

/* Content items */
.search { margin-bottom: 16px; position: relative; }
.search .ms { position: absolute; left: 10px; top: 9px; color: var(--muted); }
.search input { padding-left: 38px; }
.items { display: grid; gap: 10px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 6px; }
.item.dirty { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.item-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.item-head .key { font-family: ui-monospace, monospace; font-size: 11px; opacity: .7; }
.item-head .spacer { flex: 1; }
.badge { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: #eee; color: #777; }
.item textarea.html { font-family: ui-monospace, monospace; font-size: 12.5px; }
.section-label { font-size: 12px; color: var(--muted); margin: 18px 0 6px; font-weight: 600; }

/* Image picker */
.imgpick { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.imgpick img { width: 150px; height: 100px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #eef1f5; }
.imgpick .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.imgpick.small img { width: 96px; height: 68px; }

/* Machines */
.mlist { display: grid; gap: 10px; }
.mrow { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; gap: 12px; align-items: center; }
.mrow img { width: 90px; height: 62px; object-fit: cover; border-radius: 7px; background: #eef1f5; }
.mrow .info { flex: 1; min-width: 0; }
.mrow .info b { display: block; }
.mrow .info span { color: var(--muted); font-size: 12px; }
.mrow .order { display: flex; flex-direction: column; }
.form { display: grid; gap: 16px; }
.fieldset { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; }
.fieldset h3 { margin: 0; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.specrow { display: grid; grid-template-columns: 1fr 1fr auto auto auto; gap: 6px; align-items: center; }
.gallery { display: grid; gap: 10px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); font-weight: 600; cursor: pointer; }
.switch input { width: auto; }

/* Media library */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.media-grid figure { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; cursor: pointer; position: relative; }
.media-grid figure:hover { outline: 2px solid var(--accent); }
.media-grid img { width: 100%; height: 110px; object-fit: cover; display: block; }
.media-grid figcaption { font-size: 11px; padding: 5px 7px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-grid .del { position: absolute; top: 4px; right: 4px; background: rgba(255,255,255,.9); }

/* Dialog & toast */
.dialog { position: fixed; inset: 0; background: rgba(0,15,35,.55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.dialog-card { background: var(--card); border-radius: 14px; width: 100%; max-width: 820px; max-height: 88vh; display: flex; flex-direction: column; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.dialog-head h3 { margin: 0; font-size: 16px; }
.dialog-body { padding: 16px; overflow-y: auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--primary); color: #fff; padding: 10px 18px; border-radius: 10px; transition: transform .25s; z-index: 60; max-width: calc(100% - 32px); }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }
.empty { color: var(--muted); padding: 30px; text-align: center; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.savebar { position: sticky; bottom: 0; margin-top: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; display: flex; align-items: center; gap: 10px; box-shadow: 0 -6px 20px rgba(0,20,40,.06); }
.savebar .spacer { flex: 1; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 25% 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .app.menu-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .only-mobile { display: inline-flex; }
  .topbar, .page { padding-left: 16px; padding-right: 16px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .specrow { grid-template-columns: 1fr 1fr auto; }
  .specrow .mv { display: none; }
}
.nav-item .ms { width: 20px; overflow: hidden; flex-shrink: 0; }
