:root {
  color-scheme: dark;
  --bg: #101214;
  --surface: #1a1d21;
  --surface-strong: #252a30;
  --text: #eef1f4;
  --muted: #a8b0bb;
  --line: #3a4048;
  --divider: #2f343b;
  --accent: #246bfe;
  --accent-dark: #174fc0;
  --active: #34d96b;
  --active-dark: #147c3a;
  --suspended: #ff4f45;
  --suspended-dark: #9b201b;
  --free: #9a9a9a;
  --free-dark: #454545;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 22px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-copy,
.login-message {
  color: var(--muted);
}

.login-message {
  min-height: 20px;
  margin: 0;
  font-weight: 700;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.75rem, 2.4vw, 2.45rem);
}

h2 {
  font-size: 1.1rem;
}

.top-actions,
.form-actions,
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.ghost-button,
.danger-button,
.small-button,
.tiny-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 700;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.ghost-button,
.small-button,
.tiny-button {
  background: #23272d;
  color: var(--text);
  border: 1px solid var(--line);
}

.danger-button {
  background: #33201f;
  color: #ffb7b2;
  border: 1px solid #5a302d;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
}

.tiny-button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 0.78rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.history-panel {
  margin-bottom: 16px;
  padding: 16px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.history-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(170px, 220px) minmax(0, 1fr) 132px;
  align-items: start;
  gap: 12px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #20242a;
}

.history-item strong,
.history-item span,
.history-item time {
  display: block;
}

.history-item span,
.history-item time,
.history-item p {
  color: var(--muted);
  font-size: 0.84rem;
}

.history-item p {
  margin: 0;
  overflow-wrap: anywhere;
}

.history-item time {
  text-align: right;
}

.user-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.users-list {
  display: grid;
  gap: 8px;
}

.backup-list {
  display: grid;
  gap: 8px;
}

.user-item,
.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #20242a;
}

.user-item span,
.backup-item span {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.summary-item {
  border-radius: 8px;
  padding: 14px 16px;
  color: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.summary-item:hover,
.summary-item:focus-visible {
  box-shadow: 0 18px 44px rgba(22, 30, 43, 0.16);
  outline: 3px solid rgba(36, 107, 254, 0.18);
  transform: translateY(-1px);
}

.summary-item span {
  display: block;
  margin-bottom: 5px;
  font-size: 0.86rem;
  font-weight: 700;
}

.summary-item strong {
  font-size: 1.85rem;
}

.summary-item.active {
  background: linear-gradient(135deg, var(--active), var(--active-dark));
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.summary-item.suspended {
  background: linear-gradient(135deg, var(--suspended), var(--suspended-dark));
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.summary-item.free {
  background: linear-gradient(135deg, var(--free), var(--free-dark));
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

.form-panel,
.table-panel {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.form-panel {
  padding: 14px;
  overflow-x: auto;
  overflow-y: visible;
}

form {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

.profile-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px;
  min-width: 0;
}

.saved-add-profile-button {
  justify-self: start;
}

.profile-group {
  display: grid;
  grid-template-columns: minmax(48px, 0.8fr) minmax(48px, 0.8fr);
  grid-template-areas:
    "id password"
    "status status"
    "name name";
  gap: 5px;
  margin: 0;
  padding: 6px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #20242a;
}

.profile-group legend {
  padding: 0 5px;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
}

.profile-group label {
  gap: 4px;
  font-size: 0.72rem;
}

.client-name-field {
  grid-area: name;
}

.profile-id-field {
  grid-area: id;
}

.profile-password-field {
  grid-area: password;
}

.profile-status-field {
  grid-area: status;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  min-height: 34px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #15181c;
  color: var(--text);
  padding: 0 9px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(36, 107, 254, 0.16);
}

textarea {
  min-height: 34px;
  max-height: 58px;
  padding-top: 7px;
  padding-bottom: 7px;
  line-height: 1.35;
  overflow-y: auto;
  resize: vertical;
}

.table-panel {
  overflow: hidden;
  resize: vertical;
  min-height: 260px;
}

.table-toolbar {
  justify-content: space-between;
  padding: 14px;
  background: var(--surface-strong);
  border-bottom: 2px solid var(--line);
}

.search-box {
  flex: 1;
  max-width: 420px;
}

.compact-select {
  width: 150px;
}

.table-wrap {
  position: relative;
  overflow: auto;
  max-height: 68vh;
}

table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
  border-collapse: collapse;
}

th:first-child,
td:first-child {
  width: 220px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 8px solid var(--bg);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #2f343b;
  color: var(--text);
  font-size: 0.92rem;
}

td {
  background: var(--surface);
}

.account-row {
  border-left: 8px solid var(--divider);
  box-shadow: inset 0 0 0 2px var(--line);
}

.account-row:nth-child(3n + 1) {
  border-left-color: var(--divider);
}

.account-row:nth-child(3n + 2) {
  border-left-color: var(--divider);
}

.account-row:nth-child(3n + 3) {
  border-left-color: var(--divider);
}

.account-row td {
  border-top: 2px solid var(--line);
}

.account-row td:first-child {
  border-left: 2px solid var(--line);
  border-radius: 8px 0 0 8px;
}

.account-row td:last-child {
  border-right: 2px solid var(--line);
  border-radius: 0 8px 8px 0;
}

.credential-cell {
  min-width: 210px;
  background: #242931;
  color: var(--text);
  font-weight: 700;
}

.credential-cell span {
  display: block;
  overflow-wrap: anywhere;
}

.account-service-field {
  max-width: 220px;
}

.account-service-badge {
  display: inline-flex;
  width: fit-content;
  margin-top: 8px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--text);
  font-size: 0.78rem;
}

.saved-service-select {
  margin-top: 8px;
  gap: 4px;
  color: var(--muted);
  font-size: 0.72rem;
}

.saved-service-select select,
.account-service-field select {
  min-height: 34px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

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

.credential-cell .small-button {
  width: 100%;
  min-height: 30px;
  padding: 0 8px;
  font-size: 0.82rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  min-height: 28px;
  border-radius: 999px;
  color: #000;
  font-weight: 700;
}

.status-badge.Ativo {
  background: var(--active);
}

.status-badge.Susp {
  background: var(--suspended);
}

.status-badge.Livre {
  background: var(--free);
}

.profile-list {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.saved-add-profile-button {
  margin-top: 2px;
  width: 42px;
  min-height: 36px;
  padding: 0;
  border-radius: 8px;
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
}

.profile-line {
  display: grid;
  grid-template-columns: 26px 72px minmax(120px, 0.72fr) 72px 92px 132px;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  border: 2px solid #4c535d;
  border-radius: 8px;
  background: #20242a;
}

.profile-line.empty-profile {
  background: #181b20;
  color: var(--muted);
}

.profile-line-highlight {
  outline: 3px solid rgba(36, 107, 254, 0.32);
  background: #1f2a3a;
}

.profile-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 800;
}

.inline-field {
  min-width: 0;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-weight: 700;
}

.inline-field:focus {
  border-color: var(--accent);
  background: #15181c;
  outline: 2px solid rgba(36, 107, 254, 0.18);
}

.inline-name {
  font-weight: 500;
}

.inline-status {
  color: #000;
  text-align: center;
}

.inline-status.Ativo {
  background: var(--active);
  border-color: var(--active);
  color: #000;
}

.inline-status.Susp {
  background: var(--suspended);
  border-color: var(--suspended);
  color: #000;
}

.inline-status.Livre {
  background: var(--free);
  border-color: var(--free);
  color: #000;
}

.primary-inline-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.profile-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: nowrap;
  min-width: 0;
}

.profile-actions .tiny-button {
  min-width: 58px;
  padding: 0 6px;
  white-space: nowrap;
}

.empty-state {
  display: none;
  margin: 0;
  padding: 32px 18px;
  color: var(--muted);
  text-align: center;
}

.empty-state.visible {
  display: block;
}

@media (max-width: 860px) {
  .topbar,
  .workspace,
  .table-toolbar,
  .history-header {
    display: grid;
  }

  .profile-group {
    grid-template-columns: minmax(48px, 0.8fr) minmax(48px, 0.8fr);
  }

  .profile-line {
    grid-template-columns: 24px 66px minmax(100px, 0.72fr) 66px 82px 122px;
    gap: 4px;
  }

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

  .history-item time {
    text-align: left;
  }

  .top-actions,
  .form-actions {
    flex-wrap: wrap;
  }

  .user-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 16px;
  }

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

  .compact-select,
  .search-box {
    width: 100%;
    max-width: none;
  }

  .profile-group {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "id status"
      "password password"
      "name name";
  }

  .client-name-field {
    grid-area: name;
  }

  th:first-child,
  td:first-child {
    width: 180px;
  }
}
