:root {
  font-family: Arial, Helvetica, sans-serif;
  color: #33404a;
  background: #f4f7f9;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.page {
  min-height: 100vh;
  padding: 32px 20px;
}

.auth-card {
  width: min(100%, 460px);
  margin: 7vh auto 0;
  border: 1px solid #dce3e7;
  border-radius: 6px;
  padding: 32px;
  background: #fff;
  box-shadow: 0 8px 28px rgba(25, 55, 75, 0.1);
}

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

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: #0075b9;
  font-size: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #0075b9;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: #0064a5;
  font-size: 21px;
}

h2 {
  margin-bottom: 8px;
  color: #39464e;
  font-size: 23px;
}

.tab-row {
  display: flex;
  margin: 30px 0 24px;
  border-bottom: 1px solid #dce3e7;
}

.tab-button {
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 10px 14px;
  color: #7b8790;
  background: transparent;
  font-size: 14px;
  font-weight: 700;
}

.tab-button.active {
  border-bottom-color: #0075b9;
  color: #0075b9;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-form[hidden] {
  display: none;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: #56616a;
  font-size: 13px;
  font-weight: 700;
}

input {
  width: 100%;
  border: 1px solid #c9d1d6;
  border-radius: 3px;
  padding: 11px 12px;
  color: #2f3a41;
  background: white;
}

input:focus {
  border-color: #0075b9;
  outline: 2px solid rgba(0, 117, 185, 0.14);
}

.primary-button,
.secondary-button {
  min-height: 40px;
  border-radius: 3px;
  padding: 10px 16px;
  font-weight: 700;
}

.primary-button {
  border: 1px solid #0075b9;
  color: white;
  background: #0075b9;
}

.primary-button:hover {
  background: #0064a5;
}

.secondary-button {
  border: 1px solid #ccd4d8;
  color: #53616a;
  background: white;
}

.message {
  min-height: 20px;
  margin: 22px 0 0;
  color: #70808a;
  font-size: 13px;
}

.message.error {
  color: #b32e2e;
}

.message.success {
  color: #23813d;
}

.dashboard {
  width: min(100%, 1000px);
  margin: 0 auto;
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
}

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

.connection-status {
  color: #6e7a82;
  font-size: 13px;
  font-weight: 700;
}

.connection-status.connected {
  color: #23813d;
}

.connection-status.error {
  color: #b32e2e;
}

.dashboard-card {
  border: 1px solid #dce3e7;
  border-radius: 6px;
  padding: 32px;
  background: white;
  box-shadow: 0 8px 28px rgba(25, 55, 75, 0.08);
}

.description {
  max-width: 650px;
  color: #687780;
  line-height: 1.55;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 26px;
}

.status-item {
  display: grid;
  gap: 7px;
  border: 1px solid #e1e6e9;
  border-radius: 4px;
  padding: 16px;
}

.status-item span {
  color: #77858d;
  font-size: 13px;
}

.status-item strong {
  color: #697780;
}

.status-item strong.success {
  color: #23813d;
}

.status-item strong.error {
  color: #b32e2e;
}

.message-log {
  min-height: 100px;
  overflow: auto;
  margin: 20px 0 0;
  border-radius: 4px;
  padding: 15px;
  color: #d6e8f4;
  background: #17232c;
  font-family: Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

@media (max-width: 600px) {
  .page {
    padding: 20px 14px;
  }

  .auth-card,
  .dashboard-card {
    padding: 24px;
  }

  .dashboard-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

.dashboard-card + .dashboard-card {
  margin-top: 20px;
}

.dashboard-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.gateway-card h2 {
  margin-bottom: 0;
}

.gateway-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.gateway-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  border: 1px solid #e1e6e9;
  border-radius: 4px;
  padding: 17px;
}

.gateway-item h3 {
  margin: 0 0 6px;
  color: #3e4b53;
  font-size: 16px;
}

.gateway-item p {
  margin: 0;
  color: #7a8790;
  font-family: Consolas, monospace;
  font-size: 12px;
}

.gateway-status {
  align-self: start;
  border-radius: 20px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: capitalize;
}

.gateway-status.online {
  color: #23813d;
  background: #e5f4e8;
}

.gateway-status.offline {
  color: #748088;
  background: #eff2f3;
}

.empty-gateway-list {
  border: 1px dashed #cbd4d9;
  border-radius: 4px;
  padding: 24px;
  color: #748088;
  text-align: center;
}

.log-card {
  margin-top: 20px;
}

.gateway-dialog {
  width: min(480px, calc(100% - 28px));
  border: 0;
  border-radius: 6px;
  padding: 0;
  box-shadow: 0 16px 50px rgba(22, 40, 52, 0.28);
}

.gateway-dialog::backdrop {
  background: rgba(25, 39, 48, 0.52);
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid #e1e6e9;
  padding: 24px;
}

.dialog-header h2 {
  margin: 0;
}

.dialog-body {
  padding: 24px;
}

.dialog-label {
  display: grid;
  gap: 7px;
  margin: 20px 0 0;
  color: #56616a;
  font-size: 13px;
  font-weight: 700;
}

.close-dialog-button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  color: #697780;
  background: transparent;
  font-size: 26px;
  line-height: 1;
}

.close-dialog-button:hover {
  color: #0075b9;
  background: #edf7fc;
}

@media (max-width: 600px) {
  .dashboard-card-header {
    align-items: stretch;
    flex-direction: column;
  }

  .gateway-item {
    grid-template-columns: 1fr;
  }
}

.devices-card {
  margin-top: 20px;
}

.device-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.cloud-device-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  border: 1px solid #e1e6e9;
  border-radius: 4px;
  padding: 16px;
}

.cloud-device-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  color: #8c989e;
  background: #f0f3f4;
  font-size: 18px;
}

.cloud-device-icon.on {
  color: #d69600;
  background: #fff4cd;
  box-shadow: 0 0 10px rgba(235, 184, 29, 0.35);
}

.cloud-device-icon.unavailable {
  color: #b54444;
  background: #fceaea;
}

.cloud-device-main {
  min-width: 0;
}

.cloud-device-main h3 {
  margin: 1px 0 5px;
  color: #3e4b53;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.cloud-device-main p {
  margin: 0;
  color: #7a8790;
  font-family: Consolas, monospace;
  font-size: 11px;
  overflow-wrap: anywhere;
}

.cloud-device-meta {
  grid-column: 1 / -1;
  color: #78858d;
  font-size: 12px;
}

.cloud-device-state {
  display: inline-block;
  margin-top: 5px;
  border-radius: 20px;
  padding: 4px 8px;
  color: #6f7b83;
  background: #f0f2f3;
  font-size: 11px;
  font-weight: 700;
  text-transform: capitalize;
}

.cloud-device-state.on {
  color: #23813d;
  background: #e5f4e8;
}

.cloud-device-state.unavailable {
  color: #b32e2e;
  background: #fceaea;
}

.device-controls {
  display: flex;
  grid-column: 1 / -1;
  gap: 10px;
  margin-top: 2px;
}

.device-controls-compact {
  grid-column: 1 / -1;
  margin-top: 0;
}

.device-settings-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid #0075b9;
  border-radius: 3px;
  padding: 8px 12px;
  color: #0075b9;
  background: #edf7fc;
  font-size: 12px;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(0, 117, 185, 0.08);
}

.device-settings-button:hover {
  background: #dfeef8;
}

.device-command-button {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 7px 11px;
  font-size: 12px;
  font-weight: 700;
}

.device-command-on {
  border-color: #23813d;
  color: #ffffff;
  background: #23813d;
}

.device-command-on:hover:not(:disabled) {
  background: #1b6b32;
}

.device-command-off {
  border-color: #687780;
  color: #ffffff;
  background: #687780;
}

.device-command-off:hover:not(:disabled) {
  background: #4d5b63;
}

.device-command-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.command-status {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12px;
  font-weight: 700;
}

.command-status-requested,
.command-status-delivered,
.command-status-accepted {
  color: #a86e00;
}

.command-status-confirmed {
  color: #23813d;
}

.command-status-failed {
  color: #b32e2e;
}

.device-settings-dialog {
  width: min(560px, calc(100% - 28px));
  border: 0;
  border-radius: 6px;
  padding: 0;
  box-shadow: 0 16px 50px rgba(22, 40, 52, 0.28);
}

.device-settings-dialog::backdrop {
  background: rgba(25, 39, 48, 0.52);
}

.settings-body {
  display: grid;
  gap: 18px;
}

.settings-section {
  display: grid;
  gap: 12px;
}

.settings-section h3 {
  margin: 0;
  color: #39464e;
}

.settings-grid {
  display: grid;
  gap: 12px;
}

.entity-id-label {
  margin: 4px 0 0;
  color: #7a8790;
  font-family: Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.settings-message {
  min-height: 20px;
  margin: 0;
  font-size: 13px;
}

.settings-message.error {
  color: #b32e2e;
}

.settings-message.success {
  color: #23813d;
}