:root {
  /* Default to gruvbox light */
  --bg_h: #f9f5d7;
  --bg0: #fbf1c7;
  --bg_s: #f2e5bc;
  --bg1: #ebdbb2;
  --bg2: #d5c4a1;
  --bg3: #bdae93;
  --bg4: #a89984;

  --fg0: #282828;
  --fg1: #3c3836;
  --fg2: #504945;
  --fg3: #665c54;
  --fg4: #7c6f64;

  --red: #9d0006;
  --green: #79740e;
  --yellow: #b57614;
  --blue: #076678;
  --purple: #8f3f71;
  --aqua: #427b58;
  --orange: #af3a03;
  --gray: #928374;

  --red-dim: #cc2412;
  --green-dim: #98971a;
  --yellow-dim: #d79921;
  --blue-dim: #458598;
  --purple-dim: #b16286;
  --aqua-dim: #689d6a;
  --orange-dim: #d65d0e;
  --gray-dim: #7c6f64;

  /* Simple.css variable names */
  --bg: var(--bg0);
  --accent-bg: var(--bg_h);
  --text: var(--fg0);
  --text-light: var(--fg3);
  --border: var(--fg4);
  --accent: var(--orange);
  --accent-hover: var(--orange-dim);
  --code: var(--aqua);
  --preformatted: var(--fg2);
  --marked: var(--yellow);
  --disabled: var(--gray-dim);

  /* Scrollbar styles */
  scrollbar-color: var(--bg3) var(--bg1);
  scrollbar-width: thin;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg_h: #1d2021;
    --bg0: #282828;
    --bg_s: #32302f;
    --bg1: #3c3836;
    --bg2: #504945;
    --bg3: #665c54;
    --bg4: #7c6f64;

    --fg0: #fbf1c7;
    --fg1: #ebdbb2;
    --fg2: #d5c4a1;
    --fg3: #bdae93;
    --fg4: #a89984;

    --red: #fb4934;
    --green: #b8bb26;
    --yellow: #fabd2f;
    --blue: #83a598;
    --purple: #d3869b;
    --aqua: #8ec07c;
    --gray: #928374;
    --orange: #fe8019;

    --red-dim: #cc2412;
    --green-dim: #98971a;
    --yellow-dim: #d79921;
    --blue-dim: #458588;
    --purple-dim: #b16286;
    --aqua-dim: #689d6a;
    --gray-dim: #a89984;
    --orange-dim: #d65d0e;
  }
}

/* A few overrides to simple.css */
body {
  min-height: 100vh;
  grid-template-rows: auto 1fr auto;
}

input,
textarea,
select {
  background-color: var(--bg1);
}
input:focus,
textarea:focus,
select:focus {
  outline: 1px solid var(--accent);
}
::selection {
  background-color: var(--bg3);
  color: var(--fg0);
}

.card {
  background-color: var(--bg_s);
  border: 1px solid var(--bg2);
  border-radius: 8px;
  padding: 2rem;
  margin: 2rem auto;
  max-width: 500px;
}

.card-header {
  margin-bottom: 1.5rem;
  text-align: center;
  border-bottom: 1px solid var(--bg2);
  padding-bottom: 1rem;
}

.card h1 {
  margin: 0;
}

.card form {
  display: flex;
  flex-direction: column;
}

.card form footer {
  margin-top: 0.75rem;
  display: flex;
  justify-content: flex-end;
}

.site-footer {
  margin-top: 4rem;
  padding: 2rem 1rem 1.5rem 1rem;
  color: var(--text-light);
  font-size: 0.9rem;
  text-align: left;
  border-top: 1px solid var(--border);
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 2rem;
  max-width: 45rem;
  margin: 0 auto;
}

.footer-left {
  flex: 1;
  min-width: 200px;
}

.footer-left p {
  margin: 0;
}

.footer-left .copyright {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  color: var(--fg1);
}

.footer-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--text-light);
  text-decoration: none;
  transition: color 0.3s ease;
}

.footer-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.footer-right {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}

.icon {
  display: inline-block;
  vertical-align: middle;
  filter: var(--icon-filter, none);
  height: 1em;
  width: 1em;
}

.icon-copyright {
  width: 1.2em;
  height: 1.2em;
}

@media (prefers-color-scheme: dark) {
  :root {
    --icon-filter: invert(1) opacity(0.8);
  }
}

/* Override simple.css header styles, it is too tall */
body > header {
  padding: 0 0.5rem;

  > *:only-child {
    margin-block: 0 0.5rem;
  }
}

/* Form validation and error messages */
.error-message {
  color: var(--red);
  font-size: 0.875rem;
  margin-top: 0;
  margin-bottom: 0.75rem;
  animation: fadeIn 0.2s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

header nav {
  padding: 0.5rem 0 0 0;
  ul {
    justify-content: flex-start;
  }

  a {
    display: flex;
    align-items: center;
    margin-bottom: 0;
    margin-left: 0.2rem;
    margin-right: 0.2rem;
  }

  a.brand {
    border: none;
    padding: 0;
    gap: 0.5rem;
    margin: 0 0.5rem;

    img {
      height: 2.5rem;
      width: 2.5rem;
    }
  }

  a.loginlogout {
    gap: 0.25rem;
    margin-left: auto;
    margin-bottom: 0;

    /* Button-like styling */
    background-color: var(--accent);
    color: var(--bg);
    border: 1px solid var(--accent);
    padding: 0.1rem 0.8rem;

    align-items: baseline;

    .icon {
      height: 1.4em;
      width: 1.4em;
      display: block;
      flex-shrink: 0;
      /* Dunno why firefox is fucky about this, but :shrug: */
      transform: translateY(0.3em);
      filter: invert(1);
      @media (prefers-color-scheme: dark) {
        filter: none;
      }
    }
  }
  a.loginlogout:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
  }

  .push-right {
    margin-left: auto;
  }

  a.nav-link {
    border: none;
    background: transparent;
    font-weight: bold;
    color: var(--text-light);
  }

  a.nav-link:hover,
  a.nav-link[aria-current='page'] {
    background: transparent;
    border: none;
    color: var(--accent);
  }
}

/* Error pages */
.error-page {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.error-container {
  text-align: center;
  max-width: 500px;
  width: 100%;
}

.error-code {
  font-size: 6rem;
  font-weight: 900;
  color: var(--orange);
  line-height: 1;
  margin-bottom: 0.5rem;
  letter-spacing: -0.05em;
}

.error-title {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--fg1);
  margin-bottom: 1rem;
}

.error-description {
  font-size: 1.125rem;
  color: var(--fg2);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.error-reason {
  background-color: var(--bg1);
  border: 1px solid var(--bg3);
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 2rem;
  font-size: 0.95rem;
  color: var(--fg3);
}

.error-reason strong {
  color: var(--fg2);
}

.error-actions {
  margin-top: 2rem;
}

.error-actions .button {
  display: inline-block;
  padding: 0.75rem 2rem;
  background-color: var(--accent);
  color: var(--bg);
  text-decoration: none;
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 2px solid var(--accent);
}

.error-actions .button:hover {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
}

.error-actions .button:active {
  transform: translateY(0);
}

@media (max-width: 600px) {
  .error-code {
    font-size: 4rem;
  }

  .error-title {
    font-size: 1.5rem;
  }

  .error-description {
    font-size: 1rem;
  }
}

/* Inline error alerts (for login errors) */
.error-alert {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  animation: fadeIn 0.3s ease-in;
}

.error-alert.error-401 {
  background-color: var(--bg1);
  border-left: 4px solid var(--red);
}

.error-alert .error-message {
  margin: 0;
  color: var(--red);
  font-size: 0.95rem;
}

#error-container:not(:empty) {
  margin-top: 1rem;
}

@media (max-width: 600px) {
  .content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
  }
}

.instance-table {
  width: 100%;
  table-layout: fixed;
  white-space: nowrap;
}

.instance-table th,
.instance-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.instance-table th:not(.ip-addr-col) {
  width: 40%;
}

.ip-addr-col {
  width: 20%;
}

tr {
  button,
  .button {
    font-size: 1rem;
    padding: 0.3em 0.3em 0.1em;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* Admin Settings Page */
.upgrade-table {
  width: 100%;
}

.inline-form {
  display: inline;
}

.status-green {
  color: var(--green);
}

.status-red {
  color: var(--red);
}

.status-yellow {
  color: var(--yellow);
}

.github-config-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.status-configured {
  color: var(--green);
  white-space: nowrap;
}

.status-not-configured {
  color: var(--yellow);
  white-space: nowrap;
}

.input-group {
  display: flex;
  gap: 0.5rem;
}

.flex-3 {
  flex: 3;
}

.flex-1 {
  flex: 1;
}

/* Modals */
dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
}

dialog {
  border: 1px solid var(--accent);
}

.modal-dialog {
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.modal-dialog.modal-lg {
  width: 80%;
  max-width: 800px;
  border: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal-content {
  padding: 1.5rem;
  background: var(--bg);
  color: var(--text);
}

.modal-lg .modal-content {
  padding: 1rem;
}

.modal-title {
  margin-top: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  margin-top: 1.5rem;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--text);
  color: var(--text);
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border: none;
  cursor: pointer;
}

.logs-container {
  background: var(--bg_h);
  color: var(--text);
  padding: 1rem;
  height: 300px;
  overflow-y: scroll;
  border-radius: 4px;
  margin-bottom: 1rem;
  white-space: pre-wrap;
}

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

/* JS Interactions */
.hidden {
  display: none !important;
}

.log-entry-muted {
  color: var(--gray);
}

.log-level-info {
  color: var(--green);
}

.log-level-warn {
  color: var(--yellow);
}

.log-level-error {
  color: var(--red);
}

.log-meta {
  color: var(--fg4);
}

.log-entry-success {
  color: var(--green);
  font-weight: bold;
  margin-top: 1rem;
}

/* Instance Page Styles */
.instance-info {
  background: var(--bg1);
  padding: 1rem;
  border-radius: 4px;
  margin-bottom: 2rem;
  border: 1px solid var(--border);

  th {
    text-align: center;
  }
}

.status-online {
  color: var(--green);
  font-weight: bold;
}

.status-offline {
  color: var(--red);
  font-weight: bold;
}

.rpc-controls {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.control-panel {
  flex: 1;
  min-width: 300px;
  border: 1px solid var(--border);
  padding: 1.5rem;
  border-radius: 4px;
  background: var(--bg1);

  .destructive {
    background-color: var(--red);
    color: white;
  }
}

.control-panel button {
  margin-top: 0.5rem;
  cursor: pointer;
}

.crypto-note {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 0.5rem;
}

.console-output {
  border: 1px solid var(--border);
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 4px;
  padding: 1rem;
  font-family: monospace;
}

.console-output h3 {
  color: #eee;
  margin-top: 0;
  border-bottom: 1px solid #555;
  padding-bottom: 0.5rem;
}

.log-container {
  height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.log-entry {
  padding: 0.1rem 0.5rem;
  border-left: 2px solid transparent;
  white-space: pre-wrap;
}

.log-entry.system {
  color: #888;
  font-style: italic;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background-color: var(--bg1);
  color: var(--fg0);
  border: 1px solid var(--border);
  padding: 1rem;
  border-radius: 6px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  min-width: 300px;
  max-width: 400px;
  animation: slideIn 0.3s ease-out forwards;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.toast.toast-success {
  border-left: 4px solid var(--green);
}

.toast.toast-error {
  border-left: 4px solid var(--red);
}

.toast.toast-info {
  border-left: 4px solid var(--blue);
}

.toast-message {
  flex: 1;
}

.toast-close {
  cursor: pointer;
  color: var(--fg4);
  background: none;
  border: none;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}

.toast-close:hover {
  color: var(--fg1);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/* Input Validation */
.input-group-relative {
  position: relative;
  flex-grow: 1;
}

.input-error {
  border-color: var(--red) !important;
  outline: 1px solid var(--red) !important;
}

.validation-tooltip {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 10;
  background-color: var(--red);
  color: #fff;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  margin-top: 0.25rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  white-space: nowrap;
}

.validation-tooltip.visible {
  opacity: 1;
}

hr {
  margin: 2rem 0;
  border-color: var(--border-color);
}
