/* ---------- SETTINGS LAYOUT ---------- */

/* one column of cards on a narrow screen, two once there is room.
   align-items: start keeps each card the height of its own content
   rather than stretching the short one to match the tall one beside
   it, which is what makes a two-column grid of cards look accidental.
   max-width still applies so the text inside never runs to a silly
   measure on a very wide monitor. */
.settings-layout{
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
  gap: 20px;
  max-width: 720px;
}

@media (min-width: 1180px){
  .settings-layout{
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 1180px;
  }

  /* a section that is mostly a wide control, rather than a stack of
     rows, reads better across the full width than squeezed into half */
  .settings-layout .settings-section.settings-section-wide,
  .settings-layout .settings-section-wide{
    grid-column: 1 / -1;
  }
}

.settings-section{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.2s var(--ease), border-color 0.2s var(--ease);
}

.settings-section-head{
  padding: 16px 20px;
  background: linear-gradient(165deg, var(--surface2) 0%, var(--surface) 65%);
  border-bottom: 1px solid var(--border);
}

.settings-section-title{
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
}

.settings-section-title.danger{ color: var(--danger); }

.settings-section-sub{
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.settings-section-body{
  padding: 18px 20px;
}

.settings-row{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  margin: 0 -14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s var(--ease);
}

.settings-row:last-child{ border-bottom: none; }

.settings-row:hover{ background: var(--surface2); }

.settings-row-label{
  font-size: 13px;
  font-weight: 600;
}

.settings-row-sub{
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

/* ---------- TOGGLE SWITCH ---------- */

.switch{
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
  cursor: pointer;
}

.switch input{
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track{
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 12px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.3);
  transition: background 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.switch-track::before{
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: var(--text);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s var(--ease), background 0.2s var(--ease);
}

.switch input:checked + .switch-track{
  background: linear-gradient(155deg, var(--accent-2) 0%, var(--accent) 55%);
  box-shadow: var(--glow-accent);
}
.switch input:checked + .switch-track::before{
  transform: translateX(16px);
  background: #14171F;
}

.switch input:focus-visible + .switch-track{
  box-shadow: 0 0 0 3px rgba(108,99,255,0.25);
}

.switch input:checked:focus-visible + .switch-track{
  box-shadow: var(--glow-accent), 0 0 0 3px rgba(108,99,255,0.25);
}

/* ---------- AGENT TOKENS ---------- */

.token-row{
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px;
  margin: 0 -14px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  transition: opacity 0.2s var(--ease), background 0.2s var(--ease);
}

.token-row:last-child{ border-bottom: none; }

.token-row:hover{ background: var(--surface2); }

.token-row.revoked{ opacity: 0.55; }

.token-info{ flex: 1; min-width: 0; }

.token-name-row{
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.token-name{
  font-size: 13px;
  font-weight: 600;
}

.token-status-badge{
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid transparent;
}

.token-status-badge.active{
  color: var(--ok);
  border-color: var(--ok);
  background: rgba(61, 217, 167, 0.08);
  box-shadow: 0 0 10px -4px rgba(61, 217, 167, 0.5);
}

.token-status-badge.revoked{
  color: var(--danger);
  border-color: var(--danger);
  background: rgba(229, 72, 77, 0.08);
}

.token-status-badge.readonly{
  color: var(--muted);
  border-color: var(--muted);
  background: transparent;
}

.token-value-row{
  display: flex;
  align-items: center;
  gap: 8px;
}

.token-value{
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.25);
  padding: 4px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}

/* ---------- INSTALL COMMAND OS TABS ---------- */
/* the agent install command differs per operating system, so the modal
   offers one tab each rather than making the user work out which line
   applies to their server. */

.install-os-tabs{
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.install-os-tab{
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 11px;
  cursor: pointer;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.install-os-tab:hover{
  color: var(--text);
  border-color: var(--accent-dim);
}

.install-os-tab.active{
  color: var(--accent-2);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.command-block{
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.25);
  padding: 8px 10px;
  width: 100%;
  resize: none;
  white-space: pre-wrap;
  word-break: break-all;
  transition: border-color 0.2s var(--ease);
}

.command-block:focus{
  border-color: var(--accent);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.25), 0 0 0 3px rgba(108,99,255,0.12);
  outline: none;
}

.token-reveal-btn{
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
  padding: 2px 6px;
  flex-shrink: 0;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
}

.token-reveal-btn:hover{
  color: var(--accent);
  border-color: var(--accent-dim);
  background: rgba(108,99,255,0.08);
}

.token-meta{
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

.token-actions{
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  padding-top: 2px;
}

/* ---------- ACCOUNT FORM ---------- */

.settings-field{
  margin-bottom: 14px;
}

.settings-field:last-child{ margin-bottom: 0; }

.settings-field label{
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-family: var(--mono);
}

.settings-field input{
  width: 100%;
  max-width: 360px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.settings-field input:focus{
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108,99,255,0.12);
}

/* ---------- DANGER ZONE ---------- */

.settings-section.danger-zone{
  border-color: var(--danger);
  box-shadow: var(--shadow-sm), 0 0 0 1px rgba(229,72,77,0.1);
}

.settings-section.danger-zone .settings-section-head{
  border-bottom-color: var(--danger);
}

/* ---------- FIELD HINT (used in modals like service config) ---------- */

.field-hint{
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
}

/* links inside a hint (e.g. the "full control / read-only" presets)
   were falling back to the browser's default dark blue, which is nearly
   unreadable on the dark modal background. */
.field-hint a{
  color: var(--accent);
  text-decoration: underline;
}

/* ---------- RESPONSIVE ---------- */

@media (max-width: 640px){
  .settings-row{ flex-direction: column; align-items: flex-start; gap: 10px; }
  .token-row{ flex-direction: column; }
  .token-value{ max-width: 100%; }
  .settings-field input{ max-width: 100%; }
}

/* ---------- managing what a machine runs ---------- */
/* the apps modal lists everything on one machine and adds them one at a
   time. it replaced the single "configure service" form, which could
   only ever describe one thing per machine. */

.apps-manage-list{
  margin: 4px 0 20px;
}

.apps-manage-empty{
  color: var(--muted);
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}

.apps-manage-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.apps-manage-row + .apps-manage-row{ margin-top: 8px; }

.apps-manage-info{ min-width: 0; }

.apps-manage-name{
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.apps-manage-type{
  font-family: var(--mono);
  font-size: 10px;
  color: var(--type, var(--type-other));
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: 1px solid currentColor;
  border-radius: 10px;
  padding: 2px 8px;
  opacity: 0.95;
}

.apps-manage-meta{
  color: var(--muted);
  font-size: 11px;
  font-family: var(--mono);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.apps-manage-actions{
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.apps-manage-actions .btn{
  padding: 5px 10px;
  font-size: 11px;
}

.apps-manage-actions .btn.danger{ color: var(--danger); }

.apps-form-heading{
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-bottom: 12px;
}

/* the modal now holds a list plus a form, so it can outgrow a short
   screen where the old single form never did */
#appsModalOverlay .modal{
  max-height: 86vh;
  overflow-y: auto;
}

@media (max-width: 640px){
  .apps-manage-row{ flex-direction: column; align-items: stretch; }
  .apps-manage-actions{ justify-content: flex-start; }
}

/* ---------- ACCOUNT AND SETTINGS PAGES ---------- */
/* one quiet column of cards, each a list of one-line rows: what it is,
   what it is set to, and one button. anything that takes typing opens in
   a dialog from its row instead of sitting open on the page, the way
   most sites' account pages work. scoped to .acct-page because Servers
   shares this sheet and keeps its own look. */

.acct-page .page-head{ margin-bottom: 20px; }

.acct-column{
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 760px;
}

/* Settings: a menu of its sections down the left on a wide screen */
.acct-with-nav{
  display: grid;
  grid-template-columns: 1fr;
  gap: 32px;
  align-items: start;
}
.acct-nav{ display: none; }

@media (min-width: 1100px){
  .acct-with-nav{ grid-template-columns: 190px minmax(0, 760px); }
  .acct-nav{
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: sticky;
    top: 24px;
  }
}

.acct-nav a{
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}
.acct-nav a:hover{ color: var(--text); background: var(--surface); }
.acct-nav a.active{
  color: var(--text);
  background: var(--surface);
  border-left-color: var(--accent);
}

/* sections land below the page's top edge when jumped to, not under it */
.acct-page .acct-card{ scroll-margin-top: 20px; }

.acct-card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px 22px;
}

.acct-card-head{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--border);
}

.acct-card-title{
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.005em;
}

.acct-card-sub{
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.acct-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.acct-row:last-child{ border-bottom: none; }
.acct-row[hidden]{ display: none; }

.acct-row-main{ min-width: 0; flex: 1; }

.acct-row-label{
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.acct-row-value{
  font-size: 14px;
  color: var(--text);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.acct-row-label + .acct-row-value{ color: var(--muted); }
.acct-row-dots{ letter-spacing: 0.12em; }

.acct-row-sub{
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin-top: 3px;
}
.acct-row-sub:first-child{ margin-top: 0; }

.acct-row > .btn,
.acct-row > .switch{ flex-shrink: 0; }
.acct-page a.btn{ text-decoration: none; }

/* On / Off beside a setting's name */
.acct-pill{
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
}
.acct-pill.on{
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
  background: color-mix(in srgb, var(--ok) 10%, transparent);
}

/* who you are, at the top of Account */
.acct-hero{
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.acct-hero-avatar{
  width: 56px;
  height: 56px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(155deg, var(--accent-2) 0%, var(--accent) 60%);
}
.acct-hero-info{ min-width: 0; flex: 1; }
.acct-hero-name{
  font-size: 18px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.acct-hero-email{
  color: var(--muted);
  font-size: 13.5px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.acct-card-danger{ border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.acct-card-danger .acct-card-title{ color: var(--danger); }

/* lists that live inside a card: signed-in browsers, activity, keys */
.acct-list-row{ padding: 16px 0; border-bottom: 1px solid var(--border); }
.acct-list-row:last-child{ border-bottom: none; }
.acct-page .session-list .settings-row{ margin: 0; padding: 10px 0 !important; }
.acct-page .session-list .settings-row:hover{ background: none; }
.acct-page .token-row{ margin: 0; padding: 14px 0; }
.acct-page .token-row:hover{ background: none; }
.acct-page .no-records{ color: var(--muted); font-size: 13px; padding: 8px 0; }

/* a value with a Copy button on the same line */
.acct-copy{ display: flex; gap: 8px; margin-top: 10px; }
.acct-copy input{
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  font: 13px var(--mono);
}

/* dialogs opened from these pages */
.acct-steps{
  margin: 4px 0 16px;
  padding-left: 20px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
}
.acct-steps li + li{ margin-top: 4px; }
.acct-mono{ font-family: var(--mono) !important; letter-spacing: 0.04em; }

@media (max-width: 640px){
  .acct-card{ padding: 2px 16px; }
  .acct-row{ flex-wrap: wrap; }
  .acct-row > .btn{ width: auto; }
  .acct-hero{ flex-wrap: wrap; padding: 18px 16px; }
  .acct-hero > .btn{ width: 100%; }
}

/* .btn sets its own display, which beat the hidden attribute: Turn on
   and Turn off both showed */
.acct-page .btn[hidden]{ display: none; }

/* dialogs opened from these two pages: titles in the normal font, like
   the cards they open from */
body:has(.acct-page) .modal-title{
  font-family: var(--sans);
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.005em;
}
body:has(.acct-page) .modal-sub{ font-size: 13.5px; line-height: 1.5; }

/* Show more / Show less under a shortened list */
.acct-more{ display: flex; gap: 8px; margin-top: 4px; }
.acct-more:not(:has(.btn:not([hidden]))){ display: none; }
