:root {
  --bg: #f2f6f4;
  --surface: #ffffff;
  --surface-2: #f7faf9;
  --text: #10231d;
  --muted: #6b7d76;
  --line: #dce7e2;
  --brand: #08765a;
  --brand-dark: #075e54;
  --brand-soft: #e7f5f0;
  --warning: #b67200;
  --danger: #bd3e3e;
  --shadow: 0 12px 30px rgba(18, 50, 40, .08);
  --radius: 18px;
}

[data-theme="dark"] {
  --bg: #0f1815;
  --surface: #17231f;
  --surface-2: #1c2b26;
  --text: #eef7f3;
  --muted: #9eb2aa;
  --line: #2a3d36;
  --brand-soft: #173c31;
  --shadow: 0 12px 30px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 10% 10%, rgba(8,118,90,.18), transparent 30%),
    radial-gradient(circle at 90% 90%, rgba(7,94,84,.12), transparent 30%),
    var(--bg);
}
.login-card {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.brand-logo {
  width: 52px; height: 52px;
  border-radius: 16px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--brand), var(--brand-dark));
  color: #fff; font-weight: 900;
}
.brand-logo.small { width: 42px; height: 42px; border-radius: 13px; font-size: 13px; }
.login-card h1 { margin: 18px 0 7px; }
.login-card p { margin: 0 0 22px; color: var(--muted); line-height: 1.5; }
.login-card small { display: block; margin-top: 14px; text-align: center; color: var(--muted); }

label { display: block; margin: 13px 0 6px; font-size: 12px; font-weight: 800; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(8,118,90,.12);
}
textarea { resize: vertical; }

.btn {
  border-radius: 11px;
  padding: 10px 13px;
  border: 1px solid transparent;
  font-weight: 800;
}
.btn.primary { background: var(--brand); color: white; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.secondary { background: var(--surface-2); border-color: var(--line); color: var(--text); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.whatsapp { background: #25d366; color: #0a2c1e; }
.btn.warning { background: #fff2d7; color: #855400; }
.btn.danger-outline { background: #fff4f4; border-color: #efc1c1; color: var(--danger); }
.full { width: 100%; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 11px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface-2);
}

.app { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  min-height: 70px;
  padding: 12px 20px;
  display: flex; align-items: center;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong, .brand span { display: block; }
.brand span { color: var(--muted); font-size: 11px; margin-top: 2px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 6px 10px;
}
.user-chip strong, .user-chip span { display: block; }
.user-chip strong { font-size: 12px; }
.user-chip span { color: var(--muted); font-size: 10px; }
.avatar {
  width: 31px; height: 31px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand); color: white; font-size: 11px; font-weight: 900;
}

.dashboard {
  padding: 16px 20px 10px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 11px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 4px 16px rgba(18,50,40,.04);
}
.kpi span, .kpi small { display: block; }
.kpi span { font-size: 11px; font-weight: 800; color: var(--muted); }
.kpi strong { display: block; margin: 4px 0; font-size: 25px; }
.kpi small { color: var(--muted); font-size: 10px; }

.toolbar {
  padding: 8px 20px 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.toolbar-left, .toolbar-right { display: flex; gap: 8px; }
.toolbar-right { flex: 1; justify-content: flex-end; }
.toolbar-right input { max-width: 360px; }
.toolbar-right select { max-width: 190px; }

.content-grid {
  padding: 0 20px 20px;
  display: grid;
  grid-template-columns: minmax(330px, 430px) minmax(0, 1fr);
  gap: 14px;
  min-height: 640px;
}
.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-title {
  min-height: 68px;
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.panel-title h2, .panel-title h3 { margin: 2px 0 0; }
.panel-title.compact { min-height: auto; padding: 12px 0 8px; border: 0; }
.eyebrow {
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 9px;
  font-weight: 900;
}
.counter {
  min-width: 32px; height: 32px;
  border-radius: 999px;
  display: grid; place-items: center;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 900;
}

.ticket-list { max-height: 760px; overflow: auto; }
.ticket-card {
  padding: 14px 15px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.ticket-card:hover { background: var(--surface-2); }
.ticket-card.active { background: var(--brand-soft); }
.ticket-head { display: flex; gap: 8px; align-items: center; }
.ticket-head strong {
  min-width: 0; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ticket-phone { color: var(--muted); font-size: 11px; }
.ticket-subject { margin-top: 6px; font-size: 12px; color: var(--muted); }
.ticket-meta { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 5px; }
.badge, .status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 9px;
  font-weight: 900;
}
.badge.pending, .status-badge.pending { background:#fff5dc;color:#815500;border-color:#efd79c; }
.badge.open, .status-badge.open { background:#e5f5ef;color:#075e54;border-color:#bce2d4; }
.badge.waiting, .status-badge.waiting { background:#eaf1ff;color:#355a96;border-color:#c8d7f5; }
.badge.done, .status-badge.done { background:#eef1f0;color:#59625f; }
.badge.high { background:#fff0f0;color:#a52f2f;border-color:#efc2c2; }
.badge.urgent { background:#ffe5e5;color:#8d1919;border-color:#eaa9a9; }

.detail-panel { padding: 0 18px 18px; }
.empty-state {
  min-height: 620px;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}
.empty-state h2 { color: var(--text); margin-bottom: 6px; }
.empty-state p { max-width: 420px; margin: 0; line-height: 1.5; }
.empty-icon {
  width: 62px; height: 62px; border-radius: 20px;
  margin: 0 auto;
  display: grid; place-items: center;
  color: var(--brand); background: var(--brand-soft);
  font-size: 26px; font-weight: 900;
}
.detail-header {
  padding: 18px 0 14px;
  display: flex; justify-content: space-between; gap: 12px;
  border-bottom: 1px solid var(--line);
}
.detail-header h2 { margin: 3px 0; }
.detail-header p { margin: 0; color: var(--muted); font-size: 12px; }
.detail-grid {
  padding: 14px 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}
.detail-grid article {
  min-width: 0;
  padding: 11px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.detail-grid span, .detail-grid strong { display: block; }
.detail-grid span { color: var(--muted); font-size: 10px; font-weight: 800; }
.detail-grid strong { margin-top: 4px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.sla-block {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}
.sla-head { display: flex; justify-content: space-between; font-size: 11px; }
.progress { height: 8px; margin-top: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress div { height: 100%; width: 0%; background: var(--brand); transition: width .3s; }
.detail-actions {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}
.history-block { margin-top: 14px; border-top: 1px solid var(--line); }
.history-list { display: grid; gap: 7px; }
.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 9px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.history-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); }
.history-item span { color: var(--muted); font-size: 10px; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  padding: 18px;
  background: rgba(10,27,21,.55);
}
.modal {
  width: min(500px, 100%);
  max-height: 92vh;
  overflow: auto;
  padding: 20px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.modal header { display: flex; justify-content: space-between; }
.modal h2 { margin: 3px 0 0; }
.modal-actions { margin-top: 17px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.toast {
  position: fixed;
  right: 20px; bottom: 20px; z-index: 50;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #10231d;
  color: white;
  box-shadow: var(--shadow);
}

@media (max-width: 1100px) {
  .dashboard { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .detail-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .detail-actions { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 820px) {
  .topbar { align-items: flex-start; }
  .user-chip { display: none; }
  .dashboard { grid-template-columns: repeat(2, minmax(0,1fr)); padding: 12px; }
  .toolbar { padding: 4px 12px 12px; display: grid; }
  .toolbar-left, .toolbar-right { display: grid; grid-template-columns: 1fr 1fr; }
  .toolbar-right input { grid-column: 1 / -1; max-width: none; }
  .toolbar-right select { max-width: none; }
  .content-grid { padding: 0 12px 12px; grid-template-columns: 1fr; }
  .ticket-list { max-height: 440px; }
  .empty-state { min-height: 360px; }
}
@media (max-width: 540px) {
  .brand span, #logoutBtn { display: none; }
  .top-actions { gap: 5px; }
  .dashboard { grid-template-columns: 1fr 1fr; gap: 7px; }
  .kpi { padding: 11px; }
  .kpi strong { font-size: 21px; }
  .kpi small { display: none; }
  .toolbar-left, .toolbar-right { grid-template-columns: 1fr; }
  .toolbar-right input { grid-column: auto; }
  .detail-grid, .detail-actions { grid-template-columns: 1fr; }
  .detail-header { align-items: flex-start; }
}
