:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --text: #172027;
  --muted: #66727c;
  --line: #d9dfe4;
  --brand: #086b73;
  --brand-dark: #075159;
  --green-bg: #dff3e8;
  --green: #12623a;
  --amber-bg: #fff0c8;
  --amber: #765300;
  --red-bg: #f9dddd;
  --red: #8b2222;
  --blue-bg: #e2edf8;
  --blue: #285a82;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { max-width: 100%; overflow-x: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }

.app-header {
  min-height: 92px;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.product-label, .section-label {
  display: block;
  margin-bottom: 4px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.title-row { display: flex; align-items: center; gap: 12px; }
h1, h2, h3, p { margin: 0; letter-spacing: 0; }
h1 { font-size: 25px; line-height: 1.2; }
h2 { font-size: 17px; }
h3 { margin-bottom: 12px; font-size: 15px; }

.account-controls { display: flex; align-items: end; justify-content: flex-end; gap: 9px; }
.account-controls label { width: min(230px, 22vw); }
.account-controls label span, .account-name span, form label > span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.account-name { min-width: 130px; padding-bottom: 9px; }
.account-name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

input, select, textarea {
  width: 100%;
  height: 38px;
  min-width: 0;
  padding: 0 10px;
  border: 1px solid #bfc8cf;
  border-radius: 5px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 70px; padding-top: 9px; padding-bottom: 9px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #83b9bd; outline-offset: 1px; }

button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}
button:disabled { cursor: not-allowed; opacity: 0.55; }
.primary-button { background: var(--brand); color: #fff; }
.primary-button:hover { background: var(--brand-dark); }
.secondary-button { border-color: #bbc5cc; background: #fff; color: #27343c; }
.secondary-button:hover { background: #edf1f3; }
.danger-button { min-height: 32px; border-color: #d8a8a8; background: #fff; color: var(--red); }
.danger-button:hover { background: var(--red-bg); }
.icon-button {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-color: #d8a8a8;
  background: #fff;
  color: var(--red);
  font-size: 20px;
  line-height: 1;
}
.icon-button:hover { background: var(--red-bg); }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

main { width: min(1600px, 100%); margin: 0 auto; padding: 22px 28px 40px; }

.login-panel { min-height: calc(100vh - 150px); display: grid; place-items: start center; padding-top: min(12vh, 110px); }
.login-form {
  width: min(430px, 100%);
  padding: 24px;
  display: grid;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.login-form p { margin-top: 7px; color: var(--muted); line-height: 1.45; }

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.metric { min-height: 78px; padding: 13px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 9px; font-size: 22px; line-height: 1; }

.status-badge, .status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.neutral { background: #e9edf0; color: #53616b; }
.ok, .sent { background: var(--green-bg); color: var(--green); }
.warning, .queued, .waiting_for_network, .submitted_unconfirmed { background: var(--amber-bg); color: var(--amber); }
.failed { background: var(--red-bg); color: var(--red); }
.sending { background: var(--blue-bg); color: var(--blue); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.tabs { display: inline-flex; border: 1px solid #bfc8cf; border-radius: 6px; overflow-x: auto; }
.tab { min-height: 36px; border: 0; border-right: 1px solid #bfc8cf; border-radius: 0; background: #fff; color: #43515b; }
.tab:last-child { border-right: 0; }
.tab.active { background: var(--text); color: #fff; }
.refresh-block { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }

.data-panel { display: none; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.data-panel.active { display: block; }
.section-heading { min-height: 54px; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.section-heading p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.section-heading > span { color: var(--muted); font-size: 12px; }
.section-actions { display: flex; align-items: center; gap: 10px; }
.section-actions > span { color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 1050px; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 11px 12px; border-bottom: 1px solid #e6eaed; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
th { background: #f7f8f9; color: #53616b; font-size: 11px; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafb; }
th:nth-child(1) { width: 150px; }
th:nth-child(2) { width: 160px; }
th:nth-last-child(1) { width: 130px; }
th.action-column, td.action-column {
  position: sticky;
  right: 0;
  z-index: 2;
  width: 58px;
  border-left: 1px solid #e6eaed;
  background: #fff;
  text-align: center;
}
th.action-column { z-index: 3; background: #f7f8f9; }
tbody tr:hover td.action-column { background: #f8fafb; }
.message-cell { min-width: 260px; line-height: 1.4; }
.job-id, code { color: var(--muted); font-family: Consolas, monospace; font-size: 11px; }
.empty { height: 110px; color: var(--muted); text-align: center; vertical-align: middle; }
.subtext { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }

.inline-form { padding: 14px 16px; display: flex; align-items: end; gap: 9px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.inline-form label { width: min(430px, 70%); }
.compact-form { padding: 0; border: 0; background: transparent; }
.secret-output { padding: 13px 16px; display: grid; grid-template-columns: 180px minmax(240px, 1fr) auto; align-items: center; gap: 12px; border-bottom: 1px solid #d8c27d; background: #fff8dc; }
.secret-output div span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.secret-output code { padding: 9px 10px; overflow: auto; border: 1px solid #d7c687; background: #fff; color: var(--text); white-space: nowrap; }
.management-band { padding: 18px 16px; border-bottom: 1px solid var(--line); }
.user-form { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)) minmax(150px, auto) auto; align-items: end; gap: 10px; }
.edit-user-form { display: grid; grid-template-columns: repeat(3, minmax(160px, 1fr)) auto auto auto; align-items: end; gap: 10px; }
.check-field { min-height: 38px; display: flex; align-items: center; gap: 7px; }
.check-field input { width: 16px; height: 16px; }
.check-field span { margin: 0; }
.form-actions { display: flex; gap: 8px; }
.management-table th:nth-child(1), .management-table th:nth-child(2) { width: auto; }
.sms-form { padding: 14px 16px; display: grid; grid-template-columns: 220px minmax(320px, 1fr) auto; align-items: end; gap: 10px; border-bottom: 1px solid var(--line); background: #fafbfc; }
.sms-form-actions { display: flex; gap: 8px; }

.notice {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(440px, calc(100vw - 40px));
  padding: 11px 14px;
  border-radius: 6px;
  background: var(--red);
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}
.notice.success { background: var(--green); }
.notice.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1150px) {
  .app-header { align-items: flex-start; }
  .account-controls { flex-wrap: wrap; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .user-form { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .edit-user-form { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
  .sms-form { grid-template-columns: 190px minmax(260px, 1fr) auto; }
}

@media (max-width: 760px) {
  .app-header { padding: 16px; flex-direction: column; }
  .account-controls { width: 100%; justify-content: flex-start; }
  .account-controls label { width: calc(50% - 5px); }
  .account-name { width: calc(100% - 90px); }
  main { padding: 16px 12px 30px; }
  .login-panel { padding-top: 30px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .toolbar { align-items: stretch; flex-direction: column; }
  .tabs { width: 100%; }
  .tab { flex: 0 0 auto; }
  .refresh-block { justify-content: space-between; }
  .inline-form, .secret-output { align-items: stretch; flex-direction: column; }
  .inline-form { display: flex; }
  .inline-form label { width: 100%; }
  .secret-output { display: flex; }
  .user-form, .edit-user-form { grid-template-columns: 1fr; }
  .sms-form { grid-template-columns: 1fr; }
  .sms-form-actions { justify-content: stretch; }
  .sms-form-actions button { flex: 1; }
  .section-actions { gap: 7px; }
}
