:root {
  color-scheme: light;
  --page: #f3faf7;
  --surface: #ffffff;
  --surface-soft: #f6faf8;
  --line: #dceae4;
  --line-strong: #c8ddd4;
  --ink: #18332a;
  --ink-soft: #60766d;
  --brand: #168765;
  --brand-deep: #0c6b50;
  --brand-soft: #dff4eb;
  --on: #12805e;
  --on-soft: #e3f6ee;
  --off: #52675f;
  --off-soft: #edf2f0;
  --danger: #c95757;
  --danger-soft: #fff0ee;
  --warning: #b8781c;
  --warning-soft: #fff5dd;
  --shadow: 0 12px 32px rgba(41, 91, 72, 0.08);
  --shadow-strong: 0 22px 60px rgba(31, 75, 59, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

html.has-session #login-view {
  display: none;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 4%, rgba(75, 190, 148, 0.13), transparent 25rem),
    linear-gradient(180deg, #f7fcfa 0, var(--page) 28rem);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 390px);
  padding: 32px 26px 26px;
  border: 1px solid rgba(201, 224, 215, 0.9);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-strong);
  text-align: center;
}

.brand-mark,
.brand__mark {
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #2aaa7d, #0d7658);
  color: #fff;
  box-shadow: 0 9px 22px rgba(18, 128, 94, 0.24);
}

.brand-mark {
  width: 58px;
  height: 58px;
  margin: 0 auto 20px;
  border-radius: 19px;
  font-size: 25px;
  font-weight: 800;
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.login-card h1 {
  margin: 7px 0 0;
  font-size: 28px;
  letter-spacing: -0.04em;
}

.login-card__intro {
  margin: 9px 0 26px;
  color: var(--ink-soft);
  font-size: 14px;
}

.login-form {
  display: grid;
  gap: 14px;
  text-align: left;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
}

.field input {
  width: 100%;
  min-height: 50px;
  padding: 0 15px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  outline: none;
  background: var(--surface-soft);
  color: var(--ink);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.field input:focus {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(22, 135, 101, 0.12);
}

.form-message {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.button,
.icon-button,
.text-button,
.dialog-close {
  border: 0;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease, background 140ms ease;
}

.button:active,
.icon-button:active,
.text-button:active {
  transform: scale(0.98);
}

.button:disabled,
.icon-button:disabled,
.text-button:disabled {
  cursor: default;
  opacity: 0.48;
  transform: none;
}

.button {
  min-height: 46px;
  padding: 0 17px;
  border-radius: 14px;
  font-weight: 700;
}

.button--block {
  width: 100%;
}

.button--primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: #fff;
  box-shadow: 0 10px 20px rgba(18, 128, 94, 0.2);
}

.console-view {
  min-height: 100vh;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid rgba(220, 234, 228, 0.82);
  background: rgba(247, 252, 250, 0.88);
  backdrop-filter: blur(18px);
}

.app-header__inner,
.main-content {
  width: min(100% - 28px, 980px);
  margin: 0 auto;
}

.app-header__inner {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand__mark {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  font-weight: 800;
}

.brand h1 {
  overflow: hidden;
  margin: 0;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand p {
  margin: 3px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.connection-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
}

.connection-badge i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aada6;
}

.connection-badge--online i {
  background: #22a879;
  box-shadow: 0 0 0 4px rgba(34, 168, 121, 0.12);
}

.connection-badge--warning i {
  background: #d6932e;
}

.connection-badge--danger i {
  background: var(--danger);
}

.icon-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}

.icon-button span {
  font-size: 20px;
  line-height: 1;
  transform: rotate(90deg);
}

.icon-button b {
  font-size: 12px;
}

.main-content {
  padding: 18px 0 max(30px, env(safe-area-inset-bottom));
}

.quick-card {
  padding: 18px;
  border: 1px solid #cfe5dc;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(230, 248, 241, 0.94), rgba(255, 255, 255, 0.98) 68%);
  box-shadow: var(--shadow);
}

.quick-card__summary {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.quick-card h2,
.section-heading h2,
.dialog-header h2 {
  margin: 4px 0 0;
  letter-spacing: -0.025em;
}

.quick-card h2 {
  font-size: 20px;
}

.quick-card__status {
  margin: 5px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.power-count {
  flex: 0 0 auto;
  min-width: 62px;
  padding: 9px 11px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--brand-deep);
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}

.bulk-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.bulk-actions .button {
  min-width: 0;
}

.button__icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-right: 4px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
}

.button--on {
  border: 1px solid #b9dfd0;
  background: var(--on-soft);
  color: var(--on);
}

.button--off {
  border: 1px solid #d7e2de;
  background: #fff;
  color: var(--off);
}

.batch-progress {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid rgba(193, 221, 210, 0.72);
}

.batch-progress__track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #dcece6;
}

.batch-progress__track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #28aa7e, #67c7a5);
  transition: width 220ms ease;
}

.batch-progress p {
  margin: 7px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.content-section {
  margin-top: 24px;
}

.section-heading {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 11px;
}

.section-heading h2 {
  font-size: 18px;
}

.section-heading p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.text-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 11px;
  border-radius: 11px;
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-size: 12px;
  font-weight: 700;
}

.text-button span:first-child {
  font-size: 18px;
}

.text-button.is-spinning span:first-child {
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.device-card,
.door-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 7px 20px rgba(45, 93, 75, 0.055);
}

.device-card {
  position: relative;
  overflow: hidden;
  padding: 14px 12px 12px;
}

.device-card::before {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  background: #d9e5e0;
  content: "";
}

.device-card--on::before {
  background: #35ad83;
}

.device-card--busy::before {
  background: #e3a645;
}

.device-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 7px;
}

.device-card h3 {
  min-height: 38px;
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
}

.device-status {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--off-soft);
  color: var(--off);
  font-size: 9px;
  font-weight: 800;
  white-space: nowrap;
}

.device-status::before {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.device-status--on {
  background: var(--on-soft);
  color: var(--on);
}

.device-status--busy {
  background: var(--warning-soft);
  color: var(--warning);
}

.device-status--unknown {
  color: #81958d;
}

.device-card__message {
  min-height: 32px;
  margin: 8px 0 11px;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.device-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.device-action {
  min-width: 0;
  min-height: 44px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-soft);
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.device-action--on {
  border-color: #c7e5d9;
  background: #ecf8f3;
  color: var(--on);
}

.device-action--off {
  background: #f6f8f7;
  color: var(--off);
}

.device-action:disabled {
  cursor: default;
  opacity: 0.45;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 28px 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 18px;
  color: var(--ink-soft);
  text-align: center;
  font-size: 13px;
}

.door-list {
  display: grid;
  gap: 10px;
}

.door-card {
  padding: 15px;
}

.door-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.door-card h3 {
  margin: 0;
  font-size: 15px;
}

.door-card p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.door-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 28px;
  padding: 16px 2px 0;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 10px;
}

.app-footer button {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 11px;
}

.log-dialog {
  width: min(calc(100% - 24px), 680px);
  max-height: min(82vh, 760px);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 24px;
  background: transparent;
  box-shadow: var(--shadow-strong);
}

.log-dialog::backdrop {
  background: rgba(17, 42, 33, 0.36);
  backdrop-filter: blur(4px);
}

.dialog-shell {
  max-height: min(82vh, 760px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.dialog-header,
.dialog-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
}

.dialog-header {
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  font-size: 20px;
}

.dialog-close {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--ink-soft);
  font-size: 25px;
  line-height: 1;
}

.diagnostic-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 13px 20px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfc;
}

.diagnostic-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.diagnostic-button--test {
  border-color: #ead9b8;
  background: #fffaf0;
  color: #9a691e;
}

.diagnostic-button:disabled {
  opacity: 0.48;
}

.log-list {
  min-height: 250px;
  flex: 1 1 auto;
  overflow: auto;
  padding: 14px 20px;
  background: #f5f8f7;
  overscroll-behavior: contain;
}

.log-empty {
  min-height: 210px;
  display: grid;
  place-items: center;
  color: #8ca098;
  font-size: 12px;
}

.log-entry {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #e2ebe7;
}

.log-entry:last-child {
  border-bottom: 0;
}

.log-entry time {
  color: #8ba097;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
}

.log-entry__content {
  min-width: 0;
}

.log-entry__title {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
}

.log-entry__level {
  padding: 2px 5px;
  border-radius: 5px;
  background: #e5efeb;
  color: var(--ink-soft);
  font-size: 8px;
}

.log-entry--success .log-entry__level {
  background: var(--on-soft);
  color: var(--on);
}

.log-entry--error .log-entry__level {
  background: var(--danger-soft);
  color: var(--danger);
}

.log-entry--send .log-entry__level {
  background: var(--warning-soft);
  color: var(--warning);
}

.log-entry pre {
  margin: 6px 0 0;
  overflow-wrap: anywhere;
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 9px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.dialog-footer {
  border-top: 1px solid var(--line);
}

.dialog-footer .button {
  min-width: 92px;
}

.text-button--quiet {
  padding: 0;
  background: transparent;
  color: var(--ink-soft);
}

.toast {
  position: fixed;
  z-index: 80;
  right: 16px;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 16px;
  width: fit-content;
  max-width: min(420px, calc(100% - 32px));
  margin: auto;
  padding: 11px 15px;
  border-radius: 12px;
  background: #173b2f;
  color: #fff;
  box-shadow: 0 14px 34px rgba(16, 54, 41, 0.25);
  font-size: 12px;
  text-align: center;
}

.toast--error {
  background: #923f3f;
}

@media (min-width: 700px) {
  .main-content {
    padding-top: 26px;
  }

  .quick-card {
    display: grid;
    grid-template-columns: minmax(230px, 1fr) minmax(360px, 1.4fr);
    align-items: center;
    gap: 24px;
    padding: 22px;
  }

  .bulk-actions {
    margin-top: 0;
  }

  .batch-progress {
    grid-column: 1 / -1;
    margin-top: 0;
  }

  .device-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }

  .device-card {
    padding: 16px 14px 14px;
  }

  .device-card h3 {
    min-height: auto;
    font-size: 15px;
  }

  .device-card__message {
    font-size: 11px;
  }

  .door-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 430px) {
  .connection-badge {
    width: 26px;
    min-height: 26px;
    justify-content: center;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .connection-badge span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .icon-button {
    min-height: 36px;
  }
}

@media (max-width: 350px) {
  .app-header__inner,
  .main-content {
    width: min(100% - 20px, 980px);
  }

  .device-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .log-dialog {
    width: 100%;
    max-width: none;
    max-height: 88vh;
    margin: auto 0 0;
    border-radius: 24px 24px 0 0;
  }

  .dialog-shell {
    max-height: 88vh;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .dialog-header,
  .dialog-footer {
    padding-right: 16px;
    padding-left: 16px;
  }

  .diagnostic-actions,
  .log-list {
    padding-right: 16px;
    padding-left: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
