:root {
  font-family: Inter, system-ui, Segoe UI, Roboto, sans-serif;
  color: #1f2937;
  background: linear-gradient(165deg, #f0f9ff 0%, #f5f3ff 48%, #fff7ed 100%);
}

body {
  margin: 0;
  padding: 1.2rem 1.25rem 2rem;
  max-width: 1680px;
  margin-left: auto;
  margin-right: auto;
}

.header,
.toolbar,
.table-wrap {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(148, 163, 184, 0.28);
  box-shadow: 0 8px 26px rgba(15, 23, 42, 0.08);
}

.header {
  padding: 1rem 1.05rem;
  border-radius: 14px;
}

.header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.45rem;
  letter-spacing: 0.2px;
}

.muted {
  margin: 0;
  color: #64748b;
  font-size: 0.85rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  margin: 1.1rem 0 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: #444;
}

.field.narrow input {
  width: 4.5rem;
}

.field input {
  padding: 0.5rem 0.62rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.9rem;
  background: #fff;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
  outline: none;
}

.btn {
  padding: 0.52rem 0.92rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: linear-gradient(135deg, #4f46e5 0%, #2563eb 100%);
  color: #fff;
  box-shadow: 0 8px 16px rgba(37, 99, 235, 0.3);
}

.btn.primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.secondary {
  background: #fff;
  border-color: #cbd5e1;
  color: #334155;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.06);
}

.status {
  min-height: 1.3rem;
  font-size: 0.85rem;
  color: #0f172a;
  margin: 0.2rem 0 0.55rem;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.09);
  border: 1px solid rgba(56, 189, 248, 0.18);
}

.status.error {
  color: #b91c1c;
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.28);
}

.table-wrap {
  max-height: 72vh;
  overflow: auto;
  border-radius: 14px;
  background: #fff;
}

table.devices {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.devices th,
table.devices td {
  padding: 0.56rem 0.68rem;
  text-align: left;
  border-bottom: 1px solid #eceef2;
}

table.devices thead th {
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, #eef2ff 0%, #f8fafc 100%);
  z-index: 1;
  font-weight: 700;
  color: #334155;
}

table.devices tbody tr:hover {
  background: #f8fbff;
}

table.devices tbody td:nth-child(2),
table.devices tbody td:nth-child(3),
table.devices tbody td:nth-child(4),
table.devices tbody td:nth-child(5) {
  font-weight: 600;
  font-size: 0.79rem;
}

table.devices tbody td:nth-child(2) {
  color: #1d4ed8;
}

table.devices tbody td:nth-child(4) {
  color: #0f766e;
}

.work-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.1px;
  border: 1px solid transparent;
}

.work-badge.ready {
  color: #166534;
  background: #dcfce7;
  border-color: #86efac;
}

.work-badge.online {
  color: #0f766e;
  background: #ccfbf1;
  border-color: #5eead4;
}

.work-badge.busy {
  color: #92400e;
  background: #fef3c7;
  border-color: #fcd34d;
}

.work-badge.offline {
  color: #475569;
  background: #e2e8f0;
  border-color: #cbd5e1;
}

.work-badge.warning {
  color: #9a3412;
  background: #ffedd5;
  border-color: #fdba74;
}

.cell-mono {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.82rem;
  word-break: break-all;
}

.cell-stack {
  white-space: pre-line;
  font-size: 0.76rem;
  line-height: 1.4;
  max-width: 18rem;
  vertical-align: top;
}

/* ID последней задачи (6), последнее выполнение (7), следующая (8) — узкие */
table.devices th:nth-child(6),
table.devices td:nth-child(6) {
  max-width: 7rem;
  min-width: 0;
  padding-left: 0.4rem;
  padding-right: 0.4rem;
  font-size: 0.72rem;
}

table.devices th:nth-child(7),
table.devices td:nth-child(7),
table.devices th:nth-child(8),
table.devices td:nth-child(8) {
  max-width: 9.5rem;
  min-width: 0;
  padding-left: 0.4rem;
  padding-right: 0.4rem;
}

table.devices th:nth-child(6),
table.devices th:nth-child(7),
table.devices th:nth-child(8) {
  font-size: 0.72rem;
  line-height: 1.25;
}

table.devices td:nth-child(7).cell-stack,
table.devices td:nth-child(8).cell-stack {
  max-width: 9.5rem;
  font-size: 0.68rem;
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.btn-row {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  cursor: pointer;
  color: #1e293b;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}

.btn-row:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.12);
}

.btn-row:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-row + .btn-row {
  margin-left: 0.35rem;
}

.td-actions {
  vertical-align: top;
}

.device-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 0.5rem;
  align-items: stretch;
  min-width: 15rem;
}

.device-actions > .btn-row {
  margin-left: 0;
  width: 100%;
  box-sizing: border-box;
}

.device-actions .btn-row + .btn-row {
  margin-left: 0;
}

.task-cell {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
  justify-content: flex-end;
}

.task-id-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #475569;
  letter-spacing: 0.02em;
}

.task-id-input {
  margin-left: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 0.3rem 0.45rem;
  font-size: 0.78rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.device-actions .task-cell + .btn-row {
  margin-left: 0;
  align-self: stretch;
}

.task-id-input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.18);
  outline: none;
}

.hidden-row {
  display: none;
}

.device-row {
  cursor: pointer;
}

.details-row td {
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.details-wrap {
  padding: 0.5rem 0.1rem 0.2rem;
}

.details-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: #334155;
  margin-bottom: 0.3rem;
}

.details-muted {
  font-size: 0.78rem;
  color: #64748b;
}

.accounts-list {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.8rem;
  color: #1f2937;
}

.accounts-list li + li {
  margin-top: 0.15rem;
}

.accounts-device-table-wrap {
  margin-top: 0.35rem;
  overflow-x: auto;
}

.accounts-device-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.76rem;
  background: #ffffff;
  border: 1px solid #e2e8f0;
}

.accounts-device-table th,
.accounts-device-table td {
  padding: 0.35rem 0.45rem;
  border-bottom: 1px solid #eef2f7;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.accounts-device-table th {
  background: #f8fafc;
  color: #334155;
  font-weight: 700;
}

.sort-header-btn {
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  font: inherit;
  font-weight: inherit;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.sort-header-btn:focus-visible {
  outline: 2px solid rgba(99, 102, 241, 0.35);
  outline-offset: 2px;
  border-radius: 6px;
}

.sort-arrow {
  font-size: 0.85em;
  opacity: 0.7;
}

.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-card {
  position: relative;
  max-width: 520px;
  width: 100%;
  background: #fff;
  border-radius: 14px;
  padding: 1.25rem 1.35rem;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.modal-title {
  margin: 0 0 0.65rem;
  font-size: 1.15rem;
}

.modal-text {
  margin: 0 0 0.5rem;
  line-height: 1.45;
}

.modal-code {
  font-size: 0.88rem;
  word-break: break-all;
  background: #f1f5f9;
  padding: 0.12rem 0.35rem;
  border-radius: 6px;
}

.modal-meta {
  margin: 0 0 1rem;
  font-size: 0.82rem;
  color: #64748b;
}

.modal-field {
  margin-bottom: 1rem;
}

.modal-field label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
  color: #444;
}

.modal-select,
.modal-input {
  width: 100%;
  padding: 0.5rem 0.62rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.88rem;
  background: #fff;
  box-sizing: border-box;
}

.modal-input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
  outline: none;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.modal-hint {
  margin: 0;
  font-size: 0.78rem;
}
