/* State Monitor — Support Desk */

:root {
  --bg: hsl(228 14% 7%);
  --surface: hsl(225 15% 12%);
  --surface-glass: hsla(225 15% 12% / 0.75);
  --column: hsla(225 15% 10% / 0.8);
  --border: hsla(217 20% 30% / 0.3);
  --text: hsl(210 40% 98%);
  --muted: hsl(215 20% 65%);
  --primary: hsl(28 100% 60%);
  --primary-soft: hsla(28 100% 60% / 0.14);
  --primary-dark: hsl(28 95% 48%);
  --on-primary: hsl(222 47% 11%);
  --red: hsl(0 84% 60%);
  --green: hsl(160 60% 45%);
  --purple: hsl(280 65% 60%);
  --blue: hsl(210 90% 62%);
  --radius: 1rem;
  --shadow: 0 1px 3px rgba(0, 0, 0, .35), 0 1px 2px rgba(0, 0, 0, .25);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Sora", ui-sans-serif, system-ui, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(1200px 500px at 80% -10%, hsla(28 100% 60% / 0.06), transparent),
    radial-gradient(900px 400px at -10% 110%, hsla(210 90% 62% / 0.04), transparent);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
::placeholder { color: hsla(215 20% 65% / 0.55); }

.hidden { display: none !important; }

.icon { flex-shrink: 0; display: block; }

/* ---------- Login ---------- */
#login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface-glass); border: 1px solid var(--border);
  backdrop-filter: blur(14px); border-radius: 20px; box-shadow: var(--shadow-lg);
  padding: 46px 42px; width: 100%; max-width: 400px; text-align: center;
}
.login-card .logo {
  width: 52px; height: 52px; margin: 0 auto 16px; border-radius: 14px;
  background: linear-gradient(140deg, var(--primary), hsl(16 100% 55%));
  display: flex; align-items: center; justify-content: center; color: var(--on-primary);
  box-shadow: 0 6px 20px hsla(28 100% 60% / 0.3);
}
.login-card .kicker {
  font-size: 10.5px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase;
  color: var(--primary); margin-bottom: 6px;
}
.login-card h1 { font-size: 24px; margin-bottom: 6px; letter-spacing: -0.01em; font-weight: 600; }
.login-card .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 28px; line-height: 1.5; }
.login-card input {
  width: 100%; padding: 12px 16px; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: 15px; margin-bottom: 14px; outline: none;
  background: hsla(217 20% 20% / 0.5); color: var(--text);
}
.login-card input:focus { border-color: var(--primary); }
.login-card button {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: var(--primary); color: var(--on-primary); font-size: 14.5px; font-weight: 700;
}
.login-card button:hover { background: var(--primary-dark); }
.login-error { color: var(--red); font-size: 13px; min-height: 20px; margin-bottom: 8px; }

/* ---------- Header ---------- */
header {
  background: hsla(225 15% 8% / 0.9); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px; display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.brand { font-weight: 600; font-size: 15.5px; display: flex; align-items: center; gap: 10px; }
.brand .brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(140deg, var(--primary), hsl(16 100% 55%));
  display: flex; align-items: center; justify-content: center; color: var(--on-primary);
}
.brand .brand-sub { font-size: 10px; color: var(--muted); font-weight: 500; display: block; margin-top: 1px; letter-spacing: .01em; }
.brand .role-tag {
  font-size: 10px; font-weight: 700; padding: 3px 9px; border-radius: 99px;
  background: var(--primary-soft); color: var(--primary); text-transform: uppercase;
  letter-spacing: .07em;
}
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-pill {
  font-size: 12px; padding: 4px 12px; border-radius: 99px;
  background: hsla(217 20% 20% / 0.5); color: var(--muted); border: 1px solid var(--border);
}
.stat-pill b { color: var(--text); font-weight: 600; }
.header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn-primary {
  background: var(--primary); color: var(--on-primary); border: none; border-radius: 9px;
  padding: 9px 18px; font-weight: 700; font-size: 13px;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost {
  background: none; border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 14px; color: var(--muted); font-size: 12.5px;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn-ghost:hover { background: hsla(217 20% 20% / 0.5); color: var(--text); }
.btn-icon { padding: 8px; position: relative; }
.btn-icon-label { position: relative; }
header select, .search-wrap {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 9px;
  background: hsla(217 20% 20% / 0.5); font-size: 12.5px; color: var(--text); outline: none;
}
header select:focus { border-color: var(--primary); }
header option { background: var(--surface); }
.search-wrap { display: flex; align-items: center; gap: 8px; padding-left: 10px; }
.search-icon { color: var(--muted); }
#search-input {
  border: none; background: none; outline: none; color: var(--text); font-size: 12.5px;
  width: 150px; padding: 0;
}

/* ---------- View toggle ---------- */
.view-toggle {
  display: flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden;
}
.view-toggle button {
  background: none; border: none; padding: 8px 14px; color: var(--muted); font-size: 12.5px;
  display: flex; align-items: center; gap: 7px;
}
.view-toggle button.active {
  background: var(--primary-soft); color: var(--primary); font-weight: 700;
}

/* ---------- Dashboard ---------- */
#dashboard { padding: 20px 24px; display: grid; gap: 16px; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi .kpi-value { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; }
.kpi .kpi-label { font-size: 11px; color: var(--muted); margin-top: 3px; }
.kpi.k-open .kpi-value { color: var(--blue); }
.kpi.k-progress .kpi-value { color: var(--primary); }
.kpi.k-review .kpi-value { color: var(--purple); }
.kpi.k-done .kpi-value { color: var(--green); }

.dash-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.panel h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin-bottom: 14px; font-weight: 600;
}
.hbar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 12.5px; }
.hbar-row .hbar-label { width: 130px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-row .hbar-track { flex: 1; background: hsla(217 20% 20% / 0.5); border-radius: 99px; height: 9px; overflow: hidden; }
.hbar-row .hbar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--primary), hsl(16 100% 55%)); }
.hbar-row .hbar-n { width: 48px; text-align: right; color: var(--muted); font-size: 12px; }
.hbar-row .hbar-open { color: var(--primary); }

.trend-chart { width: 100%; height: 120px; }
.trend-legend {
  display: flex; align-items: center; gap: 16px; font-size: 11.5px; color: var(--muted); margin-top: 8px;
}
.trend-legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.trend-legend.oldest-open { gap: 6px; color: var(--muted); }
.trend-legend.oldest-open .icon { color: var(--muted); margin-right: 2px; }

.mini-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.mini-chip {
  font-size: 12px; padding: 5px 12px; border-radius: 99px;
  background: hsla(217 20% 20% / 0.5); border: 1px solid var(--border); color: var(--text);
}
.mini-chip b { color: var(--primary); margin-left: 4px; }

/* ---------- Board ---------- */
#board {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  padding: 20px 24px; align-items: start;
}
@media (max-width: 1000px) { #board { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px)  { #board { grid-template-columns: 1fr; } }

.column {
  background: var(--column); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; min-height: 240px;
  transition: border-color .15s, background .15s;
}
.column.drop-target { border-color: var(--primary); background: hsla(28 100% 60% / 0.05); }
.column-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px 12px;
  font-weight: 600; font-size: 13px;
}
.column-head .dot { width: 8px; height: 8px; border-radius: 50%; }
.column-head .count {
  margin-left: auto; font-size: 11px; color: var(--muted);
  background: hsla(217 20% 20% / 0.6); padding: 1px 9px; border-radius: 99px;
}
.col-open .dot { background: var(--blue); }
.col-in_progress .dot { background: var(--primary); }
.col-review .dot { background: var(--purple); }
.col-done .dot { background: var(--green); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 10px; cursor: pointer;
  border-left: 3px solid transparent; transition: transform .1s, box-shadow .1s, border-color .1s;
}
.card:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); border-color: hsla(217 20% 40% / 0.5); }
.card.dragging { opacity: .45; }
.card.p-urgent { border-left-color: var(--red); }
.card.p-high   { border-left-color: var(--primary); }
.card.p-medium { border-left-color: var(--blue); }
.card.p-low    { border-left-color: hsl(215 15% 45%); }
.card .title { font-weight: 600; font-size: 13.5px; line-height: 1.4; margin-bottom: 8px; }
.card .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip {
  font-size: 10.5px; font-weight: 600; padding: 2.5px 9px; border-radius: 99px;
  background: var(--primary-soft); color: var(--primary);
}
.chip.type { background: hsla(217 20% 25% / 0.6); color: var(--muted); }
.card .foot {
  display: flex; justify-content: space-between; align-items: center; margin-top: 9px;
  font-size: 11px; color: var(--muted);
}
.foot-meta { display: flex; gap: 10px; }
.meta-item { display: inline-flex; align-items: center; gap: 3px; }
.meta-item .icon { color: var(--muted); }
.empty-col { text-align: center; color: hsl(215 15% 40%); font-size: 12.5px; padding: 26px 0; }

/* ---------- Modal & Drawer ---------- */
.overlay {
  position: fixed; inset: 0; background: hsla(228 20% 4% / 0.7); z-index: 40;
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 28px;
}
.modal h2 { font-size: 18px; margin-bottom: 4px; font-weight: 600; }
.modal .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--muted); }
.field input, .field textarea, .field select {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: 9px; outline: none; background: hsla(217 20% 20% / 0.5); color: var(--text);
}
.field option { background: var(--surface); }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 110px; }
.form-error { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.upload-zone {
  border: 1.5px dashed var(--border); border-radius: 9px; padding: 14px;
  text-align: center; color: var(--muted); font-size: 12px; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--primary); color: var(--primary); }
.upload-previews { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.upload-previews img {
  width: 60px; height: 60px; object-fit: cover; border-radius: 9px;
  border: 1px solid var(--border);
}
.file-chip {
  display: inline-flex; align-items: center; gap: 7px; max-width: 240px;
  font-size: 12px; padding: 6px 10px 6px 12px; border-radius: 99px;
  background: hsla(217 20% 25% / 0.6); border: 1px solid var(--border);
  color: var(--text); text-decoration: none; overflow: hidden;
}
.file-chip .icon { color: var(--muted); }
.file-chip .fname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-chip .ext-tag {
  font-size: 9.5px; font-weight: 700; color: var(--muted); letter-spacing: .03em;
  background: hsla(217 20% 15% / 0.8); padding: 1px 6px; border-radius: 5px;
}
.file-chip:hover { border-color: var(--primary); }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); z-index: 50;
  overflow-y: auto; padding: 26px 28px;
}
.drawer-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.drawer-head h2 { font-size: 17px; line-height: 1.4; flex: 1; font-weight: 600; }
.drawer .close-btn, .close-btn {
  background: none; border: none; color: var(--muted); line-height: 1;
  display: flex; align-items: center; justify-content: center; padding: 2px;
}
.drawer .close-btn:hover, .close-btn:hover { color: var(--text); }
.drawer .req-id { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.badge-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.status-badge {
  font-size: 11px; font-weight: 700; padding: 3px 12px; border-radius: 99px; color: var(--on-primary);
}
.status-badge.s-open { background: var(--blue); }
.status-badge.s-in_progress { background: var(--primary); }
.status-badge.s-review { background: var(--purple); color: #fff; }
.status-badge.s-done { background: var(--green); color: #fff; }
.prio-badge { font-size: 11px; font-weight: 700; padding: 3px 12px; border-radius: 99px; }
.prio-badge.p-urgent { background: hsla(0 84% 60% / 0.18); color: var(--red); }
.prio-badge.p-high { background: var(--primary-soft); color: var(--primary); }
.prio-badge.p-medium { background: hsla(210 90% 62% / 0.15); color: var(--blue); }
.prio-badge.p-low { background: hsla(217 20% 25% / 0.6); color: var(--muted); }

.monitor-link {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  color: var(--primary); text-decoration: none; margin-bottom: 14px;
}
.monitor-link:hover { text-decoration: underline; }
.monitor-link .icon { color: var(--primary); }

.drawer .description {
  background: hsla(217 20% 16% / 0.7); border: 1px solid var(--border);
  border-radius: 11px; padding: 14px 16px;
  font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; margin-bottom: 18px;
  color: hsl(210 30% 90%);
}
.drawer h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 20px 0 10px; font-weight: 600; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment-list img {
  max-width: 100%; border-radius: 11px; border: 1px solid var(--border); margin-bottom: 4px;
  cursor: zoom-in;
}
.admin-controls {
  display: flex; gap: 10px; background: var(--primary-soft);
  border: 1px solid hsla(28 100% 60% / 0.3);
  border-radius: 11px; padding: 12px; margin-bottom: 6px;
}
.admin-controls select {
  flex: 1; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
.client-actions { display: flex; gap: 10px; margin-bottom: 6px; }

.timeline { font-size: 12.5px; color: var(--muted); }
.timeline li { list-style: none; padding: 4px 0; }

.comment { margin-bottom: 12px; }
.comment .who { font-size: 11px; font-weight: 700; margin-bottom: 3px; }
.comment .who .when { font-weight: 400; color: var(--muted); margin-left: 8px; }
.comment .body {
  background: hsla(217 20% 20% / 0.7); border-radius: 2px 13px 13px 13px; padding: 10px 14px;
  font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; color: hsl(210 30% 92%);
}
.comment.mine .body {
  background: hsla(28 100% 60% / 0.16); border: 1px solid hsla(28 100% 60% / 0.25);
  border-radius: 13px 2px 13px 13px;
}
.comment.mine { text-align: right; }
.comment .msg-attachments { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.comment.mine .msg-attachments { justify-content: flex-end; }
.comment .msg-attachments img {
  max-width: 180px; max-height: 140px; border-radius: 9px;
  border: 1px solid var(--border); cursor: zoom-in;
}
.comment-form { display: flex; gap: 8px; margin-top: 14px; align-items: flex-end; }
.comment-form textarea {
  flex: 1; padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: 11px; resize: vertical; min-height: 44px; outline: none;
  background: hsla(217 20% 20% / 0.5); color: var(--text);
}
.comment-form textarea:focus { border-color: var(--primary); }
.attach-btn {
  background: none; border: 1px solid var(--border); border-radius: 9px;
  padding: 10px; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
}
.attach-btn:hover { border-color: var(--primary); color: var(--primary); }
.chat-pending { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ---------- Chat ---------- */
.unread-badge {
  display: inline-flex; align-items: center; justify-content: center;
  position: absolute; top: -4px; right: -4px; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 99px; background: var(--red); color: #fff;
  font-size: 9.5px; font-weight: 700;
}
.chat-drawer { display: flex; flex-direction: column; }
.chat-drawer.hidden { display: none; }
.chat-partner { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 4px 2px; }
.chat-messages .empty-chat { text-align: center; color: hsl(215 15% 40%); font-size: 13px; padding: 40px 0; }
.chat-drawer .comment-form { margin-top: 10px; }

/* ---------- Interactions: typing, receipts, reactions, activity ---------- */
.typing-indicator {
  font-size: 12px; color: var(--muted); padding: 6px 4px 0; font-style: italic;
}
.typing-indicator::after { content: "…"; animation: typing-dots 1.2s infinite; }
@keyframes typing-dots { 0% { opacity: .2; } 50% { opacity: 1; } 100% { opacity: .2; } }

.seen-mark {
  display: flex; align-items: center; gap: 4px; justify-content: flex-end;
  font-size: 10.5px; color: var(--primary); margin-top: 3px;
}

.react-row { display: flex; gap: 4px; margin-top: 4px; align-items: center; flex-wrap: wrap; }
.comment.mine .react-row { justify-content: flex-end; }
.reaction-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 99px; border: 1px solid var(--border);
  background: hsla(217 20% 22% / 0.7); color: var(--text); cursor: pointer;
}
.reaction-chip.mine { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.react-bar { display: none; gap: 2px; }
.comment:hover .react-bar { display: inline-flex; }
.react-bar button {
  background: none; border: none; padding: 3px; border-radius: 6px; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  opacity: .6; transition: opacity .1s, color .1s;
}
.react-bar button:hover { opacity: 1; color: var(--primary); }

.ref-link { color: var(--primary); font-weight: 600; cursor: pointer; }
.ref-link:hover { text-decoration: underline; }

.msg-attachments audio { max-width: 240px; height: 36px; }

.activity-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 11px 6px; border-bottom: 1px solid var(--border);
  font-size: 13px; cursor: pointer; border-radius: 8px;
}
.activity-item:hover { background: hsla(217 20% 20% / 0.4); }
.activity-item .act-icon { color: var(--primary); margin-top: 2px; }
.activity-item .act-body { flex: 1; line-height: 1.45; }
.activity-item .act-body b { color: var(--text); font-weight: 700; }
.activity-item .act-when { font-size: 11px; color: var(--muted); white-space: nowrap; }
.voice-btn-recording { border-color: var(--red) !important; color: var(--red) !important; animation: typing-dots 1s infinite; }

/* ---------- Lightbox & toast ---------- */
#lightbox {
  position: fixed; inset: 0; z-index: 70; background: hsla(228 20% 4% / 0.88);
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
#lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 12px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 11px 22px; border-radius: 99px;
  font-size: 13px; z-index: 80; box-shadow: var(--shadow-lg);
}

@media (max-width: 620px) {
  .header-actions { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .header-actions .btn-primary { flex: 1 1 100%; }
  .search-wrap { flex: 1 1 100%; }
  #search-input { width: 100%; }
}
