:root{
  color-scheme:light;
  --page:#eef3f8;
  --surface:#ffffff;
  --surface-soft:#f8fafc;
  --ink:#17202f;
  --muted:#667085;
  --line:#d8e0ea;
  --line-strong:#c5cfdb;
  --brand:#0f766e;
  --brand-dark:#0b5f59;
  --brand-soft:#e8f5f3;
  --accent:#b65f12;
  --accent-soft:#fff3e3;
  --danger:#b42318;
  --danger-soft:#fff0ee;
  --shadow-sm:0 1px 2px rgba(15,23,42,.06);
  --shadow-md:0 12px 32px rgba(15,23,42,.10);
  --radius:8px;
}

*{box-sizing:border-box}
html{min-height:100%}
body{
  min-height:100%;
  margin:0;
  background:
    linear-gradient(180deg,#f7fafc 0,#eef3f8 340px,#e9eff6 100%);
  color:var(--ink);
  font:14px/1.5 Inter,Segoe UI,Arial,sans-serif;
  letter-spacing:0;
}
button,input,select,textarea{font:inherit;color:inherit}
button{touch-action:manipulation}

.admin-topbar{
  position:sticky;
  top:0;
  z-index:20;
  display:grid;
  grid-template-columns:auto minmax(360px,1fr) auto;
  align-items:center;
  gap:18px;
  padding:12px 22px;
  background:rgba(255,255,255,.94);
  border-bottom:1px solid var(--line);
  box-shadow:var(--shadow-sm);
  backdrop-filter:saturate(140%) blur(14px);
}

.brand{
  display:flex;
  align-items:center;
  gap:10px;
  color:var(--ink);
  text-decoration:none;
  font-weight:750;
  white-space:nowrap;
}
.brand-mark{
  display:grid;
  place-items:center;
  width:36px;
  height:36px;
  border-radius:8px;
  background:#102a43;
  color:#fff;
  font-size:12px;
  letter-spacing:.04em;
  box-shadow:inset 0 -1px 0 rgba(255,255,255,.14);
}

.admin-topbar nav{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:3px;
  min-width:0;
  overflow:auto;
  scrollbar-width:none;
}
.admin-topbar nav::-webkit-scrollbar{display:none}
.admin-topbar nav a{
  display:inline-flex;
  align-items:center;
  min-height:36px;
  padding:8px 12px;
  border-radius:7px;
  color:#475467;
  text-decoration:none;
  white-space:nowrap;
  transition:background .16s ease,color .16s ease;
}
.admin-topbar nav a.active{
  background:var(--brand-soft);
  color:var(--brand-dark);
  font-weight:700;
}
.admin-topbar nav a:hover{background:#f1f5f9;color:#101828}

.topbar-actions{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:8px;
  min-width:0;
}
.status-pill{
  display:inline-flex;
  align-items:center;
  gap:7px;
  min-height:34px;
  padding:7px 10px;
  border:1px solid #b7ddd8;
  border-radius:999px;
  background:var(--brand-soft);
  color:var(--brand-dark);
  font-size:12px;
  font-weight:700;
  white-space:nowrap;
}
.status-pill:before{
  content:"";
  width:7px;
  height:7px;
  border-radius:50%;
  background:var(--brand);
}

.ghost-button,.primary-button{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:38px;
  border:1px solid transparent;
  border-radius:7px;
  padding:9px 13px;
  cursor:pointer;
  font-weight:700;
  text-decoration:none;
  transition:background .16s ease,border-color .16s ease,box-shadow .16s ease,transform .16s ease;
}
.ghost-button{
  background:#fff;
  border-color:var(--line);
  color:#344054;
}
.ghost-button:hover{
  background:#f8fafc;
  border-color:var(--line-strong);
}
.primary-button{
  background:var(--brand);
  color:#fff;
  box-shadow:0 8px 20px rgba(15,118,110,.18);
}
.primary-button:hover{background:var(--brand-dark)}
.ghost-button:active,.primary-button:active{transform:translateY(1px)}

.admin-shell{
  width:min(1440px,100%);
  margin:0 auto;
  padding:26px;
}
.admin-section{display:none}
.admin-section.active{display:block}
.admin-section[hidden]{display:none}

.section-head{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:18px;
  min-height:94px;
  margin:0 0 18px;
  padding:2px 2px 0;
}
.section-head h1,.login-card h1{
  margin:4px 0 6px;
  color:#101828;
  font-size:32px;
  line-height:1.12;
  letter-spacing:0;
}
.section-head p,.login-card p{
  max-width:760px;
  margin:0;
  color:var(--muted);
}
.eyebrow{
  display:inline-flex;
  align-items:center;
  gap:7px;
  color:var(--brand-dark);
  font-size:11px;
  font-weight:800;
  letter-spacing:.08em;
  text-transform:uppercase;
}
.eyebrow:before{
  content:"";
  width:6px;
  height:6px;
  border-radius:50%;
  background:var(--brand);
}

.metric-grid{
  display:grid;
  grid-template-columns:repeat(5,minmax(150px,1fr));
  gap:12px;
  margin-bottom:16px;
}
.metric{
  min-height:114px;
  padding:16px;
  border:1px solid var(--line);
  border-radius:var(--radius);
  background:var(--surface);
  box-shadow:var(--shadow-sm);
}
.metric span{
  display:block;
  color:var(--muted);
  font-size:12px;
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:.04em;
}
.metric strong{
  display:block;
  margin-top:15px;
  color:#101828;
  font-size:30px;
  line-height:1;
  letter-spacing:0;
}
.metric:first-child{
  border-color:#b7ddd8;
  background:linear-gradient(180deg,#fff 0,#f1faf8 100%);
}

.two-column,.users-layout,.support-layout{
  display:grid;
  grid-template-columns:minmax(0,1fr) minmax(0,1fr);
  gap:16px;
  align-items:start;
}
.users-layout{grid-template-columns:420px minmax(0,1fr)}
.support-layout{grid-template-columns:360px minmax(0,1fr)}

.admin-card{
  min-width:0;
  border:1px solid var(--line);
  border-radius:var(--radius);
  background:rgba(255,255,255,.96);
  box-shadow:var(--shadow-sm);
}
.admin-card:not(.table-card){padding:16px}
.card-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:12px;
}
.card-head h2,.admin-card h2{
  margin:0;
  color:#101828;
  font-size:18px;
  line-height:1.25;
}
.card-head span{color:var(--muted);font-size:13px}

.job-grid{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:10px;
}
.job-item,.finance-item,.user-row,.conversation-row{
  border:1px solid var(--line);
  border-radius:var(--radius);
  background:var(--surface-soft);
}
.job-item,.finance-item{padding:13px}
.job-item strong,.finance-item strong{
  display:block;
  margin-top:7px;
  color:#101828;
  font-size:24px;
  line-height:1;
}
.job-item span,.finance-item span{
  color:var(--muted);
  font-size:12px;
  font-weight:700;
}
.job-item:nth-child(2){background:#eff8ff;border-color:#b2ddff}
.job-item:nth-child(4){background:var(--danger-soft);border-color:#fecdca}

.finance-list{display:grid;gap:10px}
.admin-search,.section-head select{
  min-width:280px;
  min-height:40px;
  border:1px solid var(--line);
  border-radius:7px;
  background:#fff;
  padding:10px 12px;
  outline:none;
  box-shadow:var(--shadow-sm);
}
.admin-search:focus,.section-head select:focus,
.reply-form textarea:focus,.settings-form textarea:focus,.settings-form input:focus,.settings-form select:focus,.login-card input:focus{
  border-color:var(--brand);
  box-shadow:0 0 0 3px rgba(15,118,110,.14);
}

.user-list,.conversation-list{
  display:grid;
  gap:8px;
  align-content:start;
  max-height:calc(100vh - 210px);
  overflow:auto;
  padding:10px;
}
.user-row,.conversation-row{
  width:100%;
  min-height:72px;
  padding:12px;
  text-align:left;
  cursor:pointer;
  transition:background .16s ease,border-color .16s ease,box-shadow .16s ease;
}
.user-row:hover,.conversation-row:hover{background:#fff;border-color:var(--line-strong)}
.user-row.active,.conversation-row.active{
  background:#fff;
  border-color:var(--brand);
  box-shadow:0 0 0 3px rgba(15,118,110,.13);
}
.row-title{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  color:#101828;
  font-weight:750;
}
.row-meta{
  margin-top:6px;
  color:var(--muted);
  font-size:13px;
  line-height:1.35;
}
.badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:24px;
  min-height:22px;
  border-radius:999px;
  background:var(--brand-soft);
  color:var(--brand-dark);
  padding:3px 8px;
  font-size:12px;
  font-weight:800;
}
.badge.warn{background:var(--accent-soft);color:#8a4b00}

.user-detail{min-height:360px}
.user-detail>p{color:var(--muted);margin:7px 0 0}
.detail-grid{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:10px;
  margin:16px 0;
}
.detail-grid div{
  min-height:74px;
  border:1px solid var(--line);
  border-radius:var(--radius);
  background:var(--surface-soft);
  padding:12px;
}
.detail-grid span{
  display:block;
  color:var(--muted);
  font-size:12px;
  font-weight:700;
}
.detail-grid strong{
  display:block;
  margin-top:8px;
  color:#101828;
  font-size:20px;
}
.user-detail h3{
  margin:18px 0 8px;
  color:#101828;
  font-size:15px;
}
.mini-list{display:grid;gap:0}
.mini-item{
  padding:10px 0;
  border-top:1px solid var(--line);
}
.mini-item:first-child{border-top:0}
.mini-item strong{
  display:block;
  color:#1d2939;
  font-weight:700;
}
.mini-item span{
  display:block;
  margin-top:3px;
  color:var(--muted);
  font-size:13px;
}

.support-thread{padding:0!important;overflow:hidden}
.thread-messages{
  display:grid;
  align-content:start;
  gap:10px;
  min-height:392px;
  max-height:calc(100vh - 310px);
  overflow:auto;
  padding:16px;
  background:#fbfdff;
}
.thread-messages>p{color:var(--muted);margin:0}
.message{
  width:fit-content;
  max-width:min(620px,84%);
  padding:11px 12px;
  border:1px solid var(--line);
  border-radius:8px;
  background:#fff;
  box-shadow:var(--shadow-sm);
}
.message.admin{
  justify-self:end;
  border-color:#b7ddd8;
  background:#edf8f6;
}
.message small{
  display:block;
  margin-top:6px;
  color:var(--muted);
  font-size:12px;
}
.reply-form{
  display:grid;
  grid-template-columns:minmax(0,1fr) auto;
  gap:10px;
  padding:12px;
  border-top:1px solid var(--line);
  background:#fff;
}
.reply-form textarea{
  width:100%;
  min-height:76px;
  resize:vertical;
  border:1px solid var(--line);
  border-radius:7px;
  padding:10px 11px;
  background:#fff;
  outline:none;
}
.reply-form .primary-button{align-self:end}

.table-card{
  overflow:auto;
  padding:0!important;
}
table{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
  background:#fff;
}
th,td{
  padding:12px;
  border-bottom:1px solid var(--line);
  text-align:left;
  vertical-align:top;
}
th{
  position:sticky;
  top:0;
  z-index:1;
  background:#f8fafc;
  color:#667085;
  font-size:11px;
  font-weight:800;
  letter-spacing:.05em;
  text-transform:uppercase;
}
tbody tr:hover td{background:#fbfdff}
td code{
  display:block;
  max-width:420px;
  white-space:pre-wrap;
  word-break:break-word;
  color:#475467;
  font-size:12px;
}

.login-panel{
  display:grid;
  min-height:calc(100vh - 112px);
  place-items:center;
  padding:24px;
}
.login-card{
  position:relative;
  display:grid;
  gap:14px;
  width:min(480px,100%);
  border:1px solid var(--line);
  border-radius:8px;
  background:#fff;
  padding:26px;
  box-shadow:var(--shadow-md);
}
.login-card:before{
  content:"";
  position:absolute;
  inset:0 0 auto;
  height:4px;
  border-radius:8px 8px 0 0;
  background:var(--brand);
}
.login-card label,.settings-form label{
  display:grid;
  gap:7px;
  color:#344054;
  font-size:13px;
  font-weight:750;
}
.reply-form textarea,.settings-form textarea,.settings-form input,.settings-form select,.login-card input{
  width:100%;
  border:1px solid var(--line);
  border-radius:7px;
  background:#fff;
  padding:10px 11px;
  outline:none;
}
.settings-form{
  display:grid;
  gap:14px;
  padding:18px!important;
}
.form-grid{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:14px;
}
.settings-form textarea{resize:vertical}
.settings-actions{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  padding-top:2px;
}

.api-admin-summary{
  display:grid;
  grid-template-columns:repeat(5,minmax(0,1fr));
  gap:14px;
  margin:0 0 16px;
}
.api-admin-summary article{
  min-height:86px;
  display:grid;
  align-content:center;
  gap:6px;
  padding:16px;
  border:1px solid var(--line);
  border-radius:14px;
  background:#fff;
  box-shadow:var(--shadow-sm);
}
.api-admin-summary span{
  color:var(--muted);
  font-size:12px;
  font-weight:800;
  letter-spacing:.04em;
  text-transform:uppercase;
}
.api-admin-summary strong{
  font-size:28px;
  line-height:1;
}
.api-admin-card{
  overflow:auto;
}
.api-admin-table{
  min-width:1040px;
  table-layout:fixed;
}
.api-admin-table th:nth-child(1){width:28%}
.api-admin-table th:nth-child(2){width:11%}
.api-admin-table th:nth-child(3){width:10%}
.api-admin-table th:nth-child(4){width:12%}
.api-admin-table th:nth-child(5){width:22%}
.api-admin-table th:nth-child(6){width:11%}
.api-admin-table th:nth-child(7){width:6%}
.api-admin-table td{
  vertical-align:top;
}
.api-admin-table td strong,
.api-admin-table td small{
  display:block;
}
.api-admin-table td small{
  margin-top:4px;
  color:var(--muted);
  font-size:12px;
  line-height:1.35;
}
.api-status{
  display:inline-flex;
  align-items:center;
  min-height:28px;
  padding:5px 9px;
  border-radius:999px;
  font-size:12px;
  font-weight:900;
  white-space:nowrap;
}
.api-status.connected{
  color:#067647;
  background:#dcfae6;
}
.api-status.missing{
  color:#92400e;
  background:#fef3c7;
}
.api-key-list{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
}
.api-key-pill{
  display:inline-flex;
  max-width:100%;
  padding:5px 8px;
  border:1px solid var(--line);
  border-radius:999px;
  background:#f8fafc;
  color:#344054;
  font-size:12px;
  font-weight:750;
}
.muted{
  color:var(--muted);
}

.toast{
  position:fixed;
  right:22px;
  bottom:22px;
  z-index:50;
  max-width:min(420px,calc(100vw - 44px));
  transform:translateY(16px);
  opacity:0;
  pointer-events:none;
  transition:opacity .18s ease,transform .18s ease;
  border:1px solid rgba(255,255,255,.14);
  border-radius:8px;
  background:#101828;
  color:#fff;
  padding:12px 14px;
  box-shadow:var(--shadow-md);
}
.toast.show{transform:none;opacity:1}
.toast p{margin:0}

[hidden]{display:none!important}

@media (max-width:1180px){
  .admin-topbar{grid-template-columns:1fr auto}
  .admin-topbar nav{
    grid-column:1/-1;
    grid-row:2;
    justify-content:flex-start;
    padding-top:2px;
  }
  .metric-grid{grid-template-columns:repeat(3,1fr)}
  .users-layout{grid-template-columns:360px minmax(0,1fr)}
}

@media (max-width:900px){
  .admin-shell{padding:20px}
  .section-head{display:block;min-height:0}
  .section-head h1{font-size:28px}
  .admin-search,.section-head select{width:100%;min-width:0;margin-top:14px}
  .metric-grid{grid-template-columns:repeat(2,1fr)}
  .two-column,.users-layout,.support-layout{grid-template-columns:1fr}
  .user-list,.conversation-list{max-height:none}
  .reply-form{grid-template-columns:1fr}
  .reply-form .primary-button{justify-self:end}
}

@media (max-width:620px){
  body{font-size:13px}
  .admin-topbar{display:flex;flex-wrap:wrap;gap:10px;padding:10px 12px}
  .brand{width:100%}
  .admin-topbar nav{width:100%;order:3}
  .topbar-actions{width:100%;justify-content:flex-start;overflow:auto}
  .admin-shell{padding:14px}
  .metric-grid,.job-grid,.detail-grid,.form-grid{grid-template-columns:1fr}
  .api-admin-summary{grid-template-columns:1fr}
  .metric{min-height:94px}
  .metric strong{font-size:26px}
  .message{max-width:94%}
  .settings-actions{justify-content:stretch;flex-direction:column}
  .settings-actions button{width:100%}
}
