:root {
  --red: #e31e24; --red-dark: #b8151a; --black: #111; --ink: #1d1d1f; --muted: #6b6b70;
  --line: #e4e4e8; --bg: #f4f4f6; --card: #fff; --green: #1f9d55; --gray-dot: #b5b5bb;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
       color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: repeating-linear-gradient(115deg, #111 0 38px, #1b1b1b 38px 76px); }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 16px; padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.login-card img { width: 100%; border-radius: 10px; display: block; margin-bottom: 18px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { margin: 0 0 18px; color: var(--muted); }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(227,30,36,.15); }
textarea { min-height: 90px; resize: vertical; }
input[type=color] { width: 54px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.err { color: var(--red-dark); font-size: 14px; min-height: 20px; margin-top: 10px; }
.hint { color: var(--muted); font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px;
  border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; font-weight: 600;
  text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #c9c9cf; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn.dark { background: var(--black); border-color: var(--black); color: #fff; }
.btn.danger { color: var(--red-dark); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; margin-top: 18px; padding: 11px; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- shell ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 10px 16px;
  color: #fff; background: #111; border-bottom: 3px solid var(--red); }
.top::before { content: ""; position: absolute; inset: 0; z-index: -1; opacity: .5;
  background: repeating-linear-gradient(115deg, #111 0 26px, #1c1c1c 26px 52px); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .2px; white-space: nowrap; }
.brand img { height: 34px; border-radius: 6px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: #ff9b9e; letter-spacing: .4px; text-transform: uppercase; }
.top .search { flex: 1; max-width: 460px; margin-left: auto; }
.top .search input { background: #fff; color: var(--ink); border: 0; }
.menu-btn { display: none; }
.layout { display: grid; grid-template-columns: 270px 1fr; min-height: calc(100vh - 57px); }
.side { background: #fff; border-right: 1px solid var(--line); padding: 14px 10px; overflow-y: auto; }
.side h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 14px 10px 6px; }
.nav { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none;
  border-radius: 9px; cursor: pointer; text-align: left; }
.nav:hover { background: var(--bg); }
.nav.active { background: #fdecec; color: var(--red-dark); font-weight: 700; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--muted); background: var(--bg); padding: 1px 8px; border-radius: 99px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--gray-dot); }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(31,157,85,.18); }
.side .add { margin: 10px; width: calc(100% - 20px); }

.main { padding: 20px; min-width: 0; }
.main-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.main-head h2 { margin: 0; font-size: 22px; }
.main-head .sub { color: var(--muted); }
.main-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 14px 12px;
  border-top: 4px solid var(--client-color, var(--line)); display: flex; flex-direction: column; gap: 8px; }
.card .row1 { display: flex; align-items: center; gap: 10px; }
.card .name { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .rid { color: var(--muted); font-size: 13px; }
.card .meta { color: var(--muted); font-size: 13px; display: grid; gap: 2px; }
.card .meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px;
  background: var(--bg); color: var(--ink); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .acts { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.card .acts .grow { flex: 1; }
.empty { background: #fff; border: 2px dashed var(--line); border-radius: var(--radius); padding: 36px 20px;
  text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 6px; }

/* ---------- dialogs ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; }
.dialog { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto; background: #fff;
  border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.dialog header { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.dialog header h3 { margin: 0; font-size: 17px; flex: 1; }
.dialog .body { padding: 4px 18px 18px; }
.dialog footer { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.dialog footer .left { margin-right: auto; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 14px; margin-top: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }
.x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.log { list-style: none; margin: 10px 0 0; padding: 0; font-size: 14px; }
.log li { padding: 8px 0; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
.log time { color: var(--muted); font-size: 12px; }
.secret { font-size: 18px; letter-spacing: 1px; background: var(--bg); padding: 10px; border-radius: 8px; word-break: break-all; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60; background: #111; color: #fff;
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.menu { position: absolute; right: 16px; top: 54px; z-index: 30; background: #fff; color: var(--ink); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25); padding: 6px; min-width: 220px; }
.menu button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--bg); }

/* ---------- phone ---------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; top: 57px; left: 0; bottom: 0; width: 280px; z-index: 40; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .brand span { display: none; }
  .top { gap: 8px; padding: 10px 12px; }
  .main { padding: 14px; }
  .grid { grid-template-columns: 1fr; }
}

/* ---------- client portal + tickets ---------- */
.login-card.portal { max-width: 460px; }
.login-card.portal.wide { max-width: 640px; }
.login-card.portal h1 { font-size: 22px; margin: 4px 0 6px; }
.trap { position: absolute; left: -10000px; width: 1px; height: 1px; opacity: 0; }
.thread { display: grid; gap: 10px; margin: 14px 0; }
.msg { background: var(--bg); border-radius: 12px; padding: 10px 12px; max-width: 92%; }
.msg.mine { background: #fdecec; justify-self: end; }
.msg.tech { background: #eef6f1; }
.msg.ai { background: #eef2fb; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg .text { white-space: pre-wrap; word-break: break-word; }
.pill.status-open { background: #fdecec; color: var(--red-dark); }
.pill.status-in_progress { background: #fff4dd; color: #8a5a00; }
.pill.status-waiting { background: #eef2fb; color: #2b4a9b; }
.pill.status-closed { background: #e9f6ee; color: #1f7a45; }
.pill.pri-high, .pill.pri-urgent { background: var(--red); color: #fff; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--bg); }
.tlist { display: grid; gap: 10px; }
.trow { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; display: grid;
  grid-template-columns: 1fr auto; gap: 4px 12px; cursor: pointer; border-left: 4px solid var(--line); text-align: left;
  border-top: 0; border-right: 0; border-bottom: 0; width: 100%; font: inherit; color: inherit; }
.trow.status-open { border-left-color: var(--red); }
.trow.status-in_progress { border-left-color: #f0a500; }
.trow.status-waiting { border-left-color: #2b6cb0; }
.trow .subj { font-weight: 700; }
.trow .when { color: var(--muted); font-size: 13px; text-align: right; }
.trow .meta { color: var(--muted); font-size: 13px; grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.reply-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.reply-row select { width: auto; }
.linkbox { display: flex; gap: 8px; margin-top: 8px; }
.linkbox input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.nav .count.hot { background: var(--red); color: #fff; }

/* ---------- management ---------- */
.pill.managed { background: #e9f6ee; color: #1f7a45; }
.manage { background: var(--bg); border-radius: 12px; padding: 12px; margin-top: 12px; }
.manage-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.manage select { width: auto; max-width: 60%; flex: 1; }
.manage details { margin-top: 10px; }
.manage summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.manage textarea { margin: 8px 0; }
.output { background: #111; color: #e8e8e8; padding: 12px; border-radius: 10px; max-height: 50vh; overflow: auto;
  white-space: pre-wrap; word-break: break-word; font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.linklike { border: 0; background: none; padding: 0; color: var(--red-dark); font-weight: 600; cursor: pointer; text-align: left; }
textarea.cmd { min-height: 70px; font-size: 12px; }
