:root {
  color-scheme: light;
  --background: #fff8f3;
  --foreground: #2a1209;
  --card: #ffffff;
  --card-foreground: #2a1209;
  --popover: #ffffff;
  --popover-foreground: #2a1209;
  --primary: #ff4f1f;
  --primary-hover: #e83d13;
  --primary-soft: #fff0e8;
  --primary-ring: rgba(255, 79, 31, 0.24);
  --primary-foreground: #ffffff;
  --secondary: #ffe8dc;
  --secondary-foreground: #8a260f;
  --muted: #fff1e8;
  --muted-foreground: #8b5e4b;
  --placeholder: #d9b4a3;
  --accent: #ffe0d1;
  --accent-foreground: #8a260f;
  --destructive: #e11d48;
  --destructive-foreground: #fafafa;
  --border: #ffd4c2;
  --input: #ffc5ad;
  --ring: #ff4f1f;
  --success: #059669;
  --warning: #d97706;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(154, 52, 18, 0.08);
  --shadow-lg: 0 24px 64px rgba(154, 52, 18, 0.24);

  --bg: var(--background);
  --text: var(--foreground);
  --line: var(--border);
  --panel: var(--card);
  --panel-soft: var(--muted);
  --accent-strong: var(--primary);
  --danger: var(--destructive);
  --ok: var(--success);
  --warn: var(--warning);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--background);
  background-image:
    radial-gradient(circle at 18% -12%, rgba(255, 79, 31, 0.2), transparent 34%),
    radial-gradient(circle at 82% 0%, rgba(255, 167, 38, 0.18), transparent 30%),
    linear-gradient(180deg, #fff1e8 0, #fffaf7 280px),
    linear-gradient(rgba(255, 111, 56, 0.075) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 111, 56, 0.075) 1px, transparent 1px);
  background-repeat: no-repeat, no-repeat, no-repeat, repeat, repeat;
  background-size: auto, auto, auto, 44px 44px, 44px 44px;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--foreground);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.topbar {
  align-items: center;
  backdrop-filter: blur(14px);
  background: rgba(255, 248, 243, 0.86);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  display: flex;
  gap: 24px;
  min-height: 57px;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  align-items: center;
  color: var(--text);
  display: inline-flex;
  font-size: 15px;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand::before {
  background: linear-gradient(135deg, #ff4f1f 0, #ff8a1f 100%);
  border-radius: 6px;
  box-shadow: 0 8px 18px rgba(255, 79, 31, 0.35);
  content: "";
  display: inline-block;
  height: 22px;
  width: 22px;
}

.brand:hover {
  text-decoration: none;
}

.topbar nav {
  background: rgba(255, 232, 220, 0.72);
  border: 1px solid rgba(255, 197, 173, 0.84);
  border-radius: var(--radius);
  display: flex;
  flex: 1;
  gap: 2px;
  padding: 3px;
}

.topbar nav a {
  border-radius: calc(var(--radius) - 2px);
  color: var(--muted-foreground);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  padding: 10px 12px;
  white-space: nowrap;
}

.topbar nav a:hover,
.topbar nav a.active {
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(255, 79, 31, 0.22);
  color: var(--primary-foreground);
  text-decoration: none;
}

.container {
  margin: 0 auto;
  max-width: 1760px;
  padding: 32px 32px 72px;
}

h1,
h2 {
  margin: 0 0 16px;
}

h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0;
  line-height: 1.25;
}

.panel,
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel {
  box-shadow: 0 1px 2px rgba(154, 52, 18, 0.06), 0 12px 28px rgba(154, 52, 18, 0.07);
  margin: 0 0 20px;
  overflow: hidden;
  padding: 24px;
  position: relative;
}

.create-panel {
  background: linear-gradient(180deg, #ffffff 0, #fff7f2 100%);
}

.panel::before {
  background: linear-gradient(90deg, transparent, rgba(255, 79, 31, 0.42), transparent);
  content: "";
  height: 1px;
  left: 0;
  opacity: 0.45;
  position: absolute;
  right: 0;
  top: 0;
}

.panel-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 0 0 16px;
}

.page-head {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  margin: 0 0 16px;
}

.panel-head h2 {
  margin: 0;
}

.page-head h1 {
  margin: 0;
}

.compact {
  max-width: 420px;
}

.login {
  margin: 10vh auto;
  max-width: 460px;
  position: relative;
}

.login h1 {
  margin-bottom: 18px;
}

.login::before {
  background: radial-gradient(circle, rgba(255, 79, 31, 0.18), transparent 68%);
  content: "";
  height: 260px;
  left: 50%;
  pointer-events: none;
  position: absolute;
  top: -82px;
  transform: translateX(-50%);
  width: 420px;
  z-index: -1;
}

.metrics {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin: 0 0 28px;
}

.metric {
  color: var(--text);
  display: block;
  overflow: hidden;
  padding: 20px;
  position: relative;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.metric::before {
  background: linear-gradient(90deg, #ff4f1f, #ffb020);
  content: "";
  height: 3px;
  left: 0;
  opacity: 0.85;
  position: absolute;
  right: 0;
  top: 0;
}

.metric:hover {
  border-color: #ffb396;
  box-shadow: 0 14px 32px rgba(255, 79, 31, 0.14);
  transform: translateY(-1px);
  text-decoration: none;
}

.metric strong {
  display: block;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  margin: 0 0 8px;
}

.metric span,
small {
  color: var(--muted-foreground);
}

form {
  margin: 0;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
}

input,
select,
textarea,
button {
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  font: inherit;
  min-height: 36px;
  padding: 8px 12px;
}

input,
select,
textarea {
  background: var(--background);
  box-shadow: 0 1px 1px rgba(154, 52, 18, 0.04);
  color: var(--foreground);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--placeholder);
  opacity: 1;
}

input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
  color: var(--placeholder);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
  outline: none;
}

textarea {
  resize: vertical;
}

button {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 8px 18px rgba(255, 79, 31, 0.22);
  color: var(--primary-foreground);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  line-height: 1;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease, transform 80ms ease;
  white-space: nowrap;
}

button:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 10px 22px rgba(255, 79, 31, 0.28);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: var(--secondary);
  border-color: var(--secondary);
  box-shadow: none;
  color: var(--secondary-foreground);
}

button.secondary:hover {
  background: #ffd8c6;
  border-color: #ffd8c6;
}

button.ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--muted-foreground);
}

button.ghost:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text);
}

.icon-button {
  align-items: center;
  display: inline-flex;
  font-size: 20px;
  height: 36px;
  justify-content: center;
  min-height: 36px;
  padding: 0;
  width: 36px;
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--destructive-foreground);
}

button.danger:hover {
  background: #be123c;
  border-color: #be123c;
}

.grid-form {
  align-items: end;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

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

.send-form {
  display: grid;
  gap: 22px;
  max-width: 1080px;
}

.settings-panel {
  max-width: 860px;
}

.admin-password-grid {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}

.backup-create-form {
  align-items: end;
  grid-template-columns: minmax(320px, 1fr) auto;
  margin: 0 0 10px;
}

.send-form label {
  color: #9b6a56;
}

.send-form input,
.send-form select,
.send-form textarea {
  background: rgba(255, 250, 247, 0.78);
}

.form-section {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 16px;
  padding-bottom: 18px;
}

.form-section h2 {
  margin: 0;
}

.send-primary-grid,
.send-options-grid {
  display: grid;
  gap: 14px;
}

.send-primary-grid {
  grid-template-columns: 1.2fr 1fr;
}

.send-options-grid {
  grid-template-columns: minmax(360px, 680px);
}

.wide-field {
  grid-column: 1 / -1;
}

.send-actions {
  display: flex;
  justify-content: flex-start;
}

.check {
  align-items: center;
  display: flex;
  gap: 8px;
  min-height: 36px;
}

.check input,
.checks input {
  min-height: auto;
}

.checks {
  background: rgba(255, 241, 232, 0.72);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 12px;
}

.checks label {
  align-items: center;
  display: flex;
  flex-direction: row;
  font-weight: 500;
}

.checks input,
.check input {
  accent-color: var(--primary);
}

.device-checks {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.actions {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: flex-start;
  min-width: max-content;
  white-space: nowrap;
}

.server-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.server-pill {
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--secondary-foreground);
  display: inline-flex;
  font-size: 12px;
  font-weight: 500;
  max-width: 100%;
  padding: 3px 8px;
}

.server-summary .server-pill {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-links {
  display: flex;
  gap: 6px;
  min-width: max-content;
}

.attachment-link {
  align-items: center;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--secondary-foreground);
  display: inline-flex;
  font-size: 12px;
  font-weight: 650;
  height: 26px;
  justify-content: center;
  min-width: 30px;
  padding: 0 8px;
}

.attachment-link:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
  text-decoration: none;
}

.token-copy {
  display: flex;
  gap: 8px;
  min-width: 620px;
}

.token-value {
  align-items: center;
  display: flex;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  min-height: 38px;
  min-width: 500px;
  padding: 8px 10px;
  width: 100%;
}

.muted {
  color: var(--muted-foreground);
}

.filters {
  align-items: end;
  display: flex;
  gap: 10px;
  margin: 0 0 16px;
}

.filters label {
  color: var(--muted-foreground);
  min-width: 190px;
}

.filters label:first-child {
  min-width: 280px;
}

.filters input,
.filters select {
  min-width: 100%;
}

.history-toolbar {
  margin: 0 0 16px;
}

.history-toolbar .filters {
  margin: 0;
}

.table-scroll {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  overflow-x: auto;
  overflow-y: visible;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

th {
  background: #fff3eb;
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 500;
  height: 44px;
}

tbody tr {
  transition: background 120ms ease;
}

tbody tr:hover {
  background: var(--muted);
}

.data-table td {
  max-width: 520px;
}

td:first-child,
th:first-child {
  padding-left: 16px;
}

td:last-child,
th:last-child {
  padding-right: 16px;
}

.row-note {
  display: block;
  margin-top: 6px;
  max-width: 380px;
  white-space: normal;
}

code {
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--foreground);
  font-size: 0.92em;
  padding: 2px 5px;
  word-break: break-all;
}

.badge {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  display: inline-flex;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  padding: 4px 8px;
}

.badge::before {
  background: currentColor;
  border-radius: 999px;
  content: "";
  height: 6px;
  opacity: 0.72;
  width: 6px;
}

.status-tooltip-wrap {
  display: inline-flex;
  position: relative;
}

.status-cell {
  display: grid;
  gap: 6px;
  justify-items: start;
  min-width: 150px;
}

.target-devices {
  color: var(--muted-foreground);
  display: block;
  line-height: 1.35;
  max-width: 220px;
  white-space: normal;
}

.status-tooltip-wrap .badge {
  cursor: default;
}

.status-tooltip-source {
  display: none;
}

.floating-status-tooltip {
  background: #fffaf7;
  border: 1px solid #ffb396;
  border-radius: 10px;
  box-shadow: 0 18px 48px rgba(154, 52, 18, 0.2);
  color: var(--foreground);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.55;
  max-width: min(780px, calc(100vw - 80px));
  min-width: 420px;
  padding: 14px 16px;
  pointer-events: none;
  position: fixed;
  white-space: pre-wrap;
  word-break: break-word;
  z-index: 1000;
}

.ok {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: var(--ok);
}

.warn {
  background: #fefce8;
  border-color: #fde68a;
  color: var(--warn);
}

.bad {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--danger);
}

.alert {
  border-radius: var(--radius);
  margin: 0 0 16px;
  padding: 12px 14px;
}

.send-result {
  border: 1px solid currentColor;
  border-radius: var(--radius);
  padding: 14px 16px;
}

.send-result ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.detail p {
  margin: 8px 0;
}

.code-block {
  background: linear-gradient(135deg, #431407 0, #7c2d12 100%);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  color: #fafafa;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin: 0 0 10px;
  overflow-x: auto;
  padding: 16px;
}

.code-block code {
  background: transparent;
  border: 0;
  color: inherit;
  font-size: 13px;
  padding: 0;
  white-space: pre;
}

.modal {
  background: var(--popover);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 760px;
  padding: 0;
  width: min(760px, calc(100vw - 48px));
}

.wide-modal {
  max-width: 980px;
  width: min(980px, calc(100vw - 48px));
}

.device-servers-modal {
  max-width: 1760px;
  width: min(1760px, calc(100vw - 96px));
}

.device-servers-modal .grid-form {
  grid-template-columns: minmax(180px, 0.8fr) minmax(420px, 1.7fr) minmax(360px, 1.5fr) minmax(140px, 0.55fr) minmax(110px, 0.45fr);
}

.device-servers-modal .table-scroll {
  width: 100%;
}

.device-servers-modal table {
  min-width: 1320px;
}

.device-servers-modal th:nth-child(3),
.device-servers-modal td:nth-child(3) {
  min-width: 320px;
}

.device-servers-modal th:nth-child(4),
.device-servers-modal td:nth-child(4) {
  min-width: 260px;
}

.device-servers-modal th:nth-child(6),
.device-servers-modal td:nth-child(6) {
  min-width: 180px;
}

.device-servers-modal th:nth-child(8),
.device-servers-modal td:nth-child(8) {
  min-width: 210px;
}

.compact-table th,
.compact-table td {
  padding: 10px 10px;
}

.modal::backdrop {
  background: rgba(67, 20, 7, 0.36);
}

.modal form {
  padding: 24px;
}

.modal-head,
.modal-actions {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.modal-head {
  border-bottom: 1px solid var(--line);
  background: #fff3eb;
  margin: -24px -24px 18px;
  padding: 18px 20px;
}

.modal-head h2 {
  margin: 0;
}

.modal-actions {
  border-top: 1px solid var(--line);
  background: #fff3eb;
  gap: 10px;
  justify-content: flex-end;
  margin: 4px -24px -24px;
  padding: 18px 24px;
}

.token-table th:nth-child(3),
.token-table td:nth-child(3) {
  min-width: 720px;
}

.backup-table th:nth-child(2),
.backup-table td:nth-child(2) {
  min-width: 300px;
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .topbar nav {
    flex-wrap: wrap;
  }

  .filters {
    flex-direction: column;
  }

  .page-head {
    align-items: stretch;
    flex-direction: column;
  }

  .send-primary-grid,
  .send-options-grid {
    grid-template-columns: 1fr;
  }

  .device-servers-modal {
    width: min(980px, calc(100vw - 28px));
  }

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

  .container {
    padding: 22px 14px 48px;
  }

  .token-copy {
    min-width: 0;
  }

  .token-value {
    min-width: 0;
  }

  .actions {
    flex-wrap: wrap;
  }
}
