:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1f2933; --muted: #6b7785; --line: #e1e5ea;
  --accent: #2f6fdb; --accent-ink: #fff; --tool: #eef3fb;
  --s-new: #6b7785; --s-prog: #2f6fdb; --s-wait: #b7791f; --s-res: #2f855a; --s-closed: #4a5568;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
button, select, input, textarea { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; padding: 7px 14px; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button:disabled { opacity: .55; cursor: default; }

.top { display: flex; align-items: baseline; gap: 14px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-size: 18px; font-weight: 700; color: var(--ink); }
.org { color: var(--muted); }
.powered { margin-left: auto; color: var(--muted); font-size: 12px; }
main { flex: 1; min-height: 0; }

/* list */
.list { max-width: 1100px; margin: 0 auto; padding: 20px 16px; }
.bar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: none; background: none; padding: 6px 12px; border-radius: 6px; color: var(--muted); }
.tabs button.on { background: var(--panel); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.bar .grow { flex: 1; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr.row { cursor: pointer; }
tr.row:hover td { background: #f8fafc; }
tr:last-child td { border-bottom: none; }
.cid { font-weight: 600; white-space: nowrap; }
.sub { color: var(--muted); font-size: 12px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; color: #fff; white-space: nowrap; }
.pill[data-s="New"] { background: var(--s-new); } .pill[data-s="In progress"] { background: var(--s-prog); }
.pill[data-s="Waiting"] { background: var(--s-wait); } .pill[data-s="Resolved"] { background: var(--s-res); } .pill[data-s="Closed"] { background: var(--s-closed); }
@media (max-width: 700px) { .hide-sm { display: none; } .powered { margin-left: 0; } }

/* case */
.case { display: grid; grid-template-columns: minmax(340px, 2fr) 3fr; height: 100%; min-height: 0; }
.left { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.head { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.head h1 { font-size: 17px; margin: 4px 0 8px; }
.meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 12px; }
.meta select, .meta input { padding: 3px 6px; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.desc { margin-top: 8px; color: var(--ink); white-space: pre-wrap; }
.chat { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 12px 12px 2px 12px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; }
.msg .text { background: #f6f7f9; padding: 8px 12px; border-radius: 12px 12px 12px 2px; }
.msg .text p { margin: 0 0 6px; } .msg .text p:last-child { margin: 0; }
.msg .text h3, .msg .text h4 { margin: 8px 0 4px; font-size: 14px; }
.msg .text ul { margin: 4px 0 6px 18px; padding: 0; }
.msg .text table { font-size: 12px; margin: 6px 0; }
.msg .text th, .msg .text td { padding: 4px 6px; }
.step { font-size: 12px; color: var(--muted); background: var(--tool); border-radius: 6px; padding: 4px 8px; margin: 3px 0; display: flex; gap: 6px; align-items: center; }
.step.save { color: var(--s-res); font-weight: 600; cursor: pointer; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--s-prog); flex: none; }
.step.done .dot { background: var(--s-res); }
.working { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.spin { width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: r 1s linear infinite; }
@keyframes r { to { transform: rotate(360deg); } }
.compose { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.compose textarea { width: 100%; min-height: 64px; resize: vertical; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.compose .row2 { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 12px; background: var(--tool); border: none; color: var(--accent); }
.compose .row2 .grow { flex: 1; }
.right { display: flex; flex-direction: column; min-height: 0; }
.rtabs { display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; align-items: center; }
.rtabs button { border: none; background: none; color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.rtabs button.on { background: var(--tool); color: var(--accent); }
.rtabs .grow { flex: 1; }
.frame { flex: 1; min-height: 0; position: relative; }
.frame > div, .frame iframe { width: 100%; height: 100%; border: 0; }
.empty { color: var(--muted); padding: 30px; text-align: center; }
@media (max-width: 900px) {
  .case { grid-template-columns: 1fr; grid-template-rows: auto 70vh; height: auto; }
  .left { border-right: none; border-bottom: 1px solid var(--line); }
  .chat { max-height: 60vh; }
}

/* modal + login */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal.hidden { display: none; }
.card { background: var(--panel); border-radius: 10px; padding: 20px; width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 10px; }
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.card input, .card select, .card textarea { border: 1px solid var(--line); border-radius: 6px; padding: 8px; background: #fff; }
.card .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.err { color: #c53030; font-size: 13px; min-height: 1em; }
.login { max-width: 360px; margin: 12vh auto; }

.actions { display: flex; gap: 8px; margin-top: 10px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1f2933; color: #fff; padding: 8px 14px; border-radius: 6px; z-index: 20; }
