:root {
  --bg: #12141a;
  --bg2: #1a1d26;
  --card: #20242f;
  --card2: #272c3a;
  --border: #2f3542;
  --text: #e8eaf0;
  --muted: #8b92a5;
  --orange: #ff6a1f;
  --orange2: #ff8b4d;
  --green: #35c46f;
  --red: #ff5566;
  --yellow: #ffb020;
  --sidebar-w: 218px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text);
  font-size: 14px; min-height: 100vh;
}
::selection { background: rgba(255,106,31,.4); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.danger { color: var(--red); }
.lead { color: var(--muted); margin-bottom: 12px; line-height: 1.5; }

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
aside {
  width: var(--sidebar-w); flex-shrink: 0; background: linear-gradient(180deg, #1c1f29, #14161e);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; transition: width .2s;
}
aside.collapsed { width: 58px; }
aside.collapsed .brand h1, aside.collapsed nav span, aside.collapsed .sidefoot span { display: none; }
.brand { display: flex; align-items: center; gap: 9px; padding: 14px 12px; }
.logo {
  width: 32px; height: 32px; flex-shrink: 0; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--orange), #ff3d00); font-weight: 800; font-size: 17px; color: #fff;
  box-shadow: 0 2px 12px rgba(255,106,31,.45);
}
.brand h1 { font-size: 15px; font-weight: 400; white-space: nowrap; }
.brand h1 b { color: var(--orange); font-weight: 700; }
#collapseBtn { margin-left: auto; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 4px; }
#collapseBtn:hover { color: var(--text); }
aside nav { display: flex; flex-direction: column; gap: 1px; padding: 4px 8px; flex: 1; }
aside nav button, .sidefoot button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; color: var(--muted); border: none; padding: 9px 10px;
  border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500; transition: all .15s; white-space: nowrap;
}
aside nav button i, .sidefoot button i { font-style: normal; width: 18px; text-align: center; flex-shrink: 0; }
aside nav button:hover, .sidefoot button:hover { color: var(--text); background: var(--card); }
aside nav button.active { background: var(--orange); color: #fff; font-weight: 600; box-shadow: 0 2px 10px rgba(255,106,31,.35); }
.sidefoot { padding: 8px; border-top: 1px solid var(--border); }
.badge { background: var(--red); color: #fff; border-radius: 10px; padding: 1px 6px; font-size: 11px; margin-left: auto; }

main { flex: 1; padding: 18px; max-width: 1600px; min-width: 0; }

/* ---------- Controls ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
button, .button {
  background: var(--card); border: 1px solid var(--border); padding: 8px 13px; border-radius: 8px;
  cursor: pointer; font-size: 13px; text-decoration: none; color: var(--text); display: inline-block; transition: all .15s;
}
button:hover, .button:hover { border-color: var(--orange); }
button.primary, .button.primary {
  background: linear-gradient(135deg, var(--orange), #ff4d00); color: #fff; border: none; font-weight: 600;
  box-shadow: 0 2px 10px rgba(255,106,31,.3);
}
button.primary:hover { filter: brightness(1.1); }
button:disabled { opacity: .5; cursor: wait; }
input, select, textarea {
  padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  font-family: inherit; background: var(--bg2); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--orange); }
input::placeholder, textarea::placeholder { color: #5a6070; }
input[type="date"] { color-scheme: dark; }
a { color: var(--orange2); }

/* ---------- Inbox ---------- */
.split { display: flex; gap: 12px; height: calc(100vh - 108px); }
.thread-list { width: 320px; flex-shrink: 0; overflow-y: auto; background: var(--card); border-radius: 12px; border: 1px solid var(--border); }
.thread-item { padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .15s; }
.thread-item:hover { background: var(--card2); }
.thread-item.selected { background: rgba(255,106,31,.12); border-left: 3px solid var(--orange); }
.thread-item .who { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.thread-item .who .acc { font-weight: 400; color: var(--muted); font-size: 12px; }
.thread-item .preview { color: var(--muted); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-item.unanswered .who::before { content: "\25CF "; color: var(--orange); }
.thread-view { flex: 1; min-width: 0; background: var(--card); border-radius: 12px; border: 1px solid var(--border); display: flex; flex-direction: column; }
.thread-view .placeholder { margin: auto; color: var(--muted); }
.msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 78%; padding: 9px 13px; border-radius: 12px; white-space: pre-wrap; line-height: 1.45; }
.msg.in { background: var(--card2); align-self: flex-start; border-bottom-left-radius: 3px; }
.msg.out { background: linear-gradient(135deg, rgba(255,106,31,.25), rgba(255,61,0,.2)); border: 1px solid rgba(255,106,31,.3); align-self: flex-end; border-bottom-right-radius: 3px; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 5px; }
.replybox { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.replybox textarea { flex: 1 1 100%; resize: vertical; min-height: 44px; }
.order-panel {
  width: 340px; flex-shrink: 0; overflow-y: auto; background: var(--card);
  border-radius: 12px; border: 1px solid var(--border); padding: 12px;
}
.order-panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 10px 0 6px; }
.order-panel h3:first-child { margin-top: 0; }
.ocard { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 8px; font-size: 13px; }
.ocard .row { display: flex; justify-content: space-between; gap: 8px; margin: 2px 0; }
.ocard .row .k { color: var(--muted); }
.note-item { border-left: 3px solid var(--orange); padding: 5px 8px; margin: 6px 0; background: var(--bg2); border-radius: 0 8px 8px 0; font-size: 12px; }
.note-item .by { color: var(--muted); font-size: 11px; display: flex; justify-content: space-between; gap: 6px; margin-top: 3px; }
.note-item .acts a { cursor: pointer; margin-left: 6px; text-decoration: none; }

/* Allegro-style order card */
.ocard .otop { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.oitem { display: flex; gap: 9px; margin-bottom: 9px; }
.oitem img { width: 54px; height: 54px; object-fit: contain; background: #fff; border-radius: 8px; flex-shrink: 0; }
.oitem .oinfo { flex: 1; min-width: 0; }
.oitem .oname { font-weight: 600; line-height: 1.3; white-space: normal; }
.oitem .osub { color: var(--muted); font-size: 11px; margin-top: 2px; }
.oblock { border-top: 1px solid var(--border); padding-top: 7px; margin-top: 7px; }
.oblock .btitle { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 4px; }
.paid { color: var(--green); font-weight: 700; }
.pickup { background: rgba(255,106,31,.10); border: 1px dashed rgba(255,106,31,.4); border-radius: 8px; padding: 6px 8px; margin-top: 5px; font-size: 12px; }

/* Claim cards */
.claim { display: flex; gap: 12px; }
.claim img { width: 62px; height: 62px; object-fit: contain; background: #fff; border-radius: 8px; flex-shrink: 0; }
.claim .cbody { flex: 1; min-width: 0; }
.ctype { font-size: 10px; font-weight: 700; letter-spacing: .5px; padding: 2px 7px; border-radius: 5px; }
.ctype.claim { background: rgba(255,85,102,.2); color: var(--red); border: 1px solid rgba(255,85,102,.4); }
.ctype.dispute { background: rgba(77,159,255,.18); color: #4d9fff; border: 1px solid rgba(77,159,255,.4); }
.cmsg { background: var(--bg2); border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 12px;
  max-height: 90px; overflow: auto; white-space: pre-wrap; color: var(--muted); }

/* ---------- Tables ---------- */
.scrollwrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td:first-child, th:first-child { padding-left: 13px; }
th { background: var(--bg2); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
tr:hover td { background: var(--card2); }
tr:last-child td { border-bottom: none; }
tr.warn-bad td { background: rgba(255,85,102,.12); }
tr.warn-ok td { background: rgba(255,176,32,.10); }
.up { color: var(--green); font-weight: 600; }
.down { color: var(--red); font-weight: 600; }
.pen { cursor: pointer; color: var(--orange2); }

/* ---------- Cards, tags, stats ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 13px; margin-bottom: 10px; }
.card .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.card .head b { font-size: 14px; }
.tag { background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-size: 11px; color: var(--muted); }
.tag.ok { color: var(--green); border-color: rgba(53,196,111,.4); }
.tag.warn { color: var(--orange2); border-color: rgba(255,106,31,.4); }
.tag.bad { color: var(--red); border-color: rgba(255,85,102,.4); }
.statrow { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: linear-gradient(160deg, var(--card), var(--bg2)); border: 1px solid var(--border); border-radius: 12px; padding: 13px 15px; }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.stat .value { font-size: 21px; font-weight: 700; margin-top: 4px; }
.stat.hl { border-color: rgba(255,106,31,.5); box-shadow: 0 0 18px rgba(255,106,31,.12); }
.stat.hl .value { color: var(--orange2); }
.markup-edit { color: var(--orange2); cursor: pointer; border-bottom: 1px dashed var(--orange2); }
.deadline { font-weight: 700; }
.deadline.soon { color: var(--red); }
.deadline.ok { color: var(--green); }

/* ---------- Labels ---------- */
.label-chip {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 600;
  cursor: pointer; user-select: none; margin: 1px 2px;
  color: var(--lc); border: 1px solid var(--lc); background: transparent; opacity: .65; transition: all .15s;
}
.label-chip:hover { opacity: 1; }
.label-chip.on { background: var(--lc); color: #fff; opacity: 1; }
.labelpick { display: inline-flex; align-items: center; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 11px; max-width: 580px; margin: 12px 0 20px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.form label.row { flex-direction: row; align-items: center; gap: 8px; }
h2 { margin: 20px 0 6px; font-size: 16px; }
h2:first-child { margin-top: 0; }
code { background: var(--bg2); border: 1px solid var(--border); padding: 2px 7px; border-radius: 6px; user-select: all; color: var(--orange2); }
#saveStatus { margin-left: 10px; color: var(--green); }
.placeholder { color: var(--muted); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 100;
}
.tpl-row { display: flex; gap: 8px; margin-bottom: 8px; }
.tpl-row textarea { flex: 1; min-height: 40px; }

@media (max-width: 1100px) { .order-panel { display: none; } }
