:root {
  --bg: #F7FAF8;
  --bg-2: #E8F8EF;
  --panel: #FFFFFF;
  --line: #D5DDE0;
  --ink: #12382a;
  --muted: #3d6b54;
  --primary: #008B45;
  --dark: #006B38;
  --accent: #20B65A;
  --light: #E8F8EF;
  --white: #FFFFFF;
  --ok: #008B45;
  --alarm: #d14343;
  --shadow: 0 16px 40px rgba(0, 107, 56, 0.12);
  color-scheme: light;
  font-family: Inter, "Noto Sans", "Noto Sans SC", "Noto Sans Thai", "Noto Sans Arabic", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: #b42318; min-height: 1.2em; }
.ok { color: var(--ok); }
.alarm { color: var(--alarm); }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 420px at 8% -10%, rgba(32, 182, 90, 0.18), transparent 60%),
    radial-gradient(700px 380px at 110% 0%, rgba(0, 139, 69, 0.12), transparent 55%),
    var(--bg);
}
.login-card, .modal-card {
  width: min(440px, 100%);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-card { text-align: center; }
.login-card h1, .modal-card h2 { color: var(--dark); font-weight: 700; margin: 8px 0 4px; letter-spacing: -0.02em; }
.login-card h1 { font-size: 28px; }
.logo { width: 96px; height: 96px; object-fit: contain; display: block; margin: 0 auto 4px; }
.logo.small { width: 40px; height: 40px; margin: 0; border-radius: 10px; }
label { display: grid; gap: 6px; margin: 14px 0; font-size: 14px; color: var(--dark); text-align: left; }
input, select, textarea {
  width: 100%;
  background: var(--white);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
textarea { min-height: 74px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(0, 139, 69, 0.35); border-color: var(--primary); }
button {
  background: var(--primary);
  color: var(--white);
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 700;
}
button:hover { background: var(--dark); }
button.ghost, button.tiny {
  background: var(--white);
  color: var(--dark);
  border: 1px solid var(--line);
}
button.ghost:hover, button.tiny:hover { background: var(--light); }
button.danger { background: var(--white); color: #b42318; border: 1px solid #f0c2bc; }
button.danger:hover { background: #fff5f4; }
button.tiny { padding: 6px 10px; font-size: 13px; font-weight: 600; }
button.tiny.on, .tabs button.on {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}
button.tiny.on:hover, .tabs button.on:hover { background: var(--dark); }

.shell { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.top {
  display: flex; gap: 18px; align-items: center; justify-content: space-between;
  padding: 12px 18px; background: var(--white); color: var(--ink);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand, .who, .stats { display: flex; align-items: center; gap: 10px; }
.who { flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
.aside-tools button { white-space: nowrap; }
.brand strong { display: block; font-size: 18px; letter-spacing: -0.02em; color: var(--dark); }
.top .muted { color: var(--muted); }
.top button.ghost {
  background: var(--white);
  color: var(--dark);
  border-color: var(--line);
}
.top button.ghost:hover { background: var(--light); border-color: var(--primary); color: var(--primary); }
.stats { gap: 8px; flex-wrap: wrap; }
.stat {
  background: var(--light);
  border: 1px solid var(--line);
  color: var(--dark);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
}
.stat b { color: var(--primary); font-weight: 700; }
.workspace { display: grid; grid-template-columns: 320px 1fr; min-height: 0; flex: 1; }
aside {
  background: var(--dark);
  color: var(--white);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.aside-tools { display: flex; gap: 8px; padding: 12px; }
.aside-tools input {
  background: var(--white);
  color: var(--ink);
}
.device-list { overflow: auto; padding: 0 10px 16px; display: grid; gap: 8px; align-content: start; }
button.device {
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 4px;
  color: var(--white);
  font-weight: 500;
}
button.device:hover { background: rgba(255, 255, 255, 0.14); }
button.device.active {
  background: var(--light);
  color: var(--dark);
  border-color: var(--light);
  box-shadow: inset 3px 0 0 var(--accent);
}
button.device .imei,
button.device .muted { color: #d7f3e4; }
button.device.active .imei,
button.device.active .muted { color: var(--dark); }
button.device .pill { background: rgba(255, 255, 255, 0.16); color: var(--white); }
button.device.active .pill { background: var(--white); color: var(--dark); }
button.device.active .pill.hot { background: #fdeceb; color: #b42318; }
aside .empty { color: #d7f3e4; }
.device .row, .spread, .tabs, .actions, .inline { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
label.inline { justify-content: flex-start; }
.imei { font-family: ui-monospace, "Cascadia Code", "Source Code Pro", monospace; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 99px; background: transparent; border: 2px solid rgba(255, 255, 255, 0.55); display: inline-block; box-sizing: border-box; }
main .dot { border-color: #b7c4bc; }
.dot.on { background: transparent; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(32, 182, 90, 0.22); }
.pill { border-radius: 999px; padding: 2px 8px; font-size: 12px; background: rgba(255, 255, 255, 0.14); color: var(--white); }
main .pill, .modal-card .pill { background: var(--light); color: var(--dark); }
.pill.hot { background: rgba(209, 67, 67, 0.16); color: #ffd7d2; }
main .pill.hot, .modal-card .pill.hot { background: #fdeceb; color: #b42318; }
.pill.good { background: rgba(32, 182, 90, 0.2); color: #e8f8ef; }
main .pill.good { background: var(--light); color: var(--primary); }

main { padding: 18px; overflow: auto; background: var(--bg); }
.panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}
.tabs { flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { background: var(--white); color: var(--dark); border: 1px solid var(--line); }
.tabs button:hover { background: var(--light); }
h2, h3 { color: var(--dark); font-weight: 700; margin: 0 0 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.metric { background: var(--light); border-radius: 12px; padding: 12px; border: 1px solid var(--line); }
.metric span { display: block; color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.metric strong { font-size: 22px; color: var(--dark); }
.flags { display: flex; flex-wrap: wrap; gap: 6px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
#map { height: 360px; border-radius: 12px; border: 1px solid var(--line); background: var(--light); overflow: hidden; }
#map .maplibregl-map { height: 100%; border-radius: 12px; }
.chart { width: 100%; height: 180px; background: var(--light); border-radius: 12px; }
.preset-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.contact-row, .member-row { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 8px; margin-bottom: 8px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.chat { display: grid; gap: 8px; max-height: 420px; overflow: auto; }
.bubble { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; background: var(--light); }
.bubble.out { border-color: #9ed9b4; background: var(--white); }
.composer { display: grid; gap: 8px; }
.toggle-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.toggle { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--white); border-radius: 12px; padding: 8px 10px; border: 1px solid var(--line); }
.empty { color: var(--muted); padding: 28px; }

#toasts { position: fixed; right: 14px; bottom: 14px; display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--white); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); max-width: 360px; }
.toast.bad { border-left-color: var(--alarm); }

dialog { border: 0; padding: 0; background: transparent; color: inherit; }
dialog::backdrop { background: rgba(0, 43, 24, 0.45); }
.modal-card { width: min(520px, calc(100vw - 24px)); background: var(--white); }

.lang-pick {
  position: relative;
  display: inline-flex;
  width: auto;
  margin: 0;
  gap: 0;
}
.lang-pick select {
  width: auto;
  min-width: 8.75rem;
  padding: 8px 10px;
  font-weight: 600;
  background: var(--white);
}
.login-card .lang-pick { width: min(220px, 100%); margin: 10px auto 0; }
.login-card .lang-pick select { width: 100%; text-align: center; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}
html[dir="rtl"] label,
html[dir="rtl"] th,
html[dir="rtl"] td,
html[dir="rtl"] button.device { text-align: right; }
html[dir="rtl"] .imei,
html[dir="rtl"] input[name="imei"],
html[dir="rtl"] input[name="phone"],
html[dir="rtl"] input[name="url"],
html[dir="rtl"] input[name="peer"],
html[dir="rtl"] input[name="room"],
html[dir="rtl"] input[name="center"],
html[dir="rtl"] input[name="sos1"],
html[dir="rtl"] input[name="sos2"],
html[dir="rtl"] input[name="sos3"],
html[dir="rtl"] input[name="account"],
html[dir="rtl"] textarea#raw {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}
html[dir="rtl"] #toasts { right: auto; left: 14px; }
html[dir="rtl"] .toast { border-left-width: 1px; border-right: 4px solid var(--accent); }
html[dir="rtl"] .toast.bad { border-right-color: var(--alarm); }
html[dir="rtl"] button.device.active { box-shadow: inset -3px 0 0 var(--accent); }
html[lang="zh-CN"] .metric span,
html[lang="th"] .metric span,
html[lang="ar"] .metric span,
html[lang="zh-CN"] th,
html[lang="th"] th,
html[lang="ar"] th {
  letter-spacing: 0;
  text-transform: none;
}

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  aside { max-height: 240px; }
  .top { flex-wrap: wrap; }
  .who { flex: 1 1 100%; justify-content: flex-start; }
  .two, .three, .contact-row, .member-row { grid-template-columns: 1fr; }
}
