:root {
  /* Palette "Himmel": cool greys, with sky blue as the accent. */
  --bg: #F4F6F7;
  --surface: #FFFFFF;
  --surface-sunk: #F9FAFB;
  --tab-bg: #EDF1F3;
  --active-bg: #E7ECEF;
  --border: #DFE5E8;
  --border-strong: #C3CCD1;
  --text: #18181B;
  --text-2: #3F3F46;
  --muted: #52525B;
  --ok: #16A34A;
  --ok-text: #166534;
  --bad: #D97706;
  --bad-text: #92400E;
  --error-bg: #FEF2F2;
  --error-text: #991B1B;
  --accent: #0369A1;
  --accent-hover: #075985;
  --accent-tint: #E0F2FE;
  --focus: var(--accent);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Figtree, system-ui, sans-serif;
  font-size: 15px;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

h1 { margin: 0; font-size: 32px; font-weight: 600; letter-spacing: -0.6px; }
p { margin: 0; }

.brand { font-size: 26px; font-weight: 600; letter-spacing: -0.5px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
}

/* Forms */
.stack { display: flex; flex-direction: column; gap: 20px; }
.stack-tight { display: flex; flex-direction: column; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
label { font-size: 14px; font-weight: 500; }

input[type=email], input[type=password], input[type=text], input[type=time], .code-input {
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-sunk);
  color: var(--text);
  font: inherit;
}
.code-input {
  height: 56px;
  font-family: ui-monospace, monospace;
  font-size: 26px;
  letter-spacing: 10px;
  text-align: center;
}

.button {
  height: 48px;
  padding: 0 22px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #FFFFFF;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.button:hover { background: var(--accent-hover); }
.button.secondary:hover, .button.outline:hover { background: var(--surface-sunk); }
.button.secondary {
  width: 100%;
  height: 40px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-weight: 500;
}
.link-button {
  padding: 0;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.error {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 14px;
}

/* Login and registration */
.auth {
  min-height: 100vh;
  max-width: 452px;
  margin: 0 auto;
  padding: 48px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 28px;
}
.auth .brand { text-align: center; }
.auth-card { padding: 32px; border-radius: 16px; display: flex; flex-direction: column; gap: 20px; }
.auth-card h1 { font-size: 26px; letter-spacing: -0.4px; }
.below { text-align: center; color: var(--muted); font-size: 14px; }

.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 10px;
  background: var(--tab-bg);
}
.tab {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.code-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

/* Signed-in shell */
.app { min-height: 100vh; display: flex; }
.sidebar {
  flex: 0 0 240px;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-right: 1px solid var(--border);
  background: var(--surface-sunk);
}
.sidebar .brand { font-size: 24px; padding: 0 12px 24px; }
.nav-links { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
}
.nav-item.active { background: var(--active-bg); color: var(--text); font-weight: 600; }
.nav-item.soon { color: #A1A1AA; }
.nav-heading {
  margin: 16px 12px 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #71717A;
}
.sidebar-user {
  margin-top: auto;
  padding: 16px 12px 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
  overflow-wrap: anywhere;
}
.content {
  flex: 1 1 0;
  min-width: 0;
  padding: 40px 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Narrow: the menu is a bar on top. Brand and log-out on one row, the
   links under them, scrolling sideways if they do not fit. */
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar {
    flex: none;
    padding: 12px 16px 8px;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar .brand { font-size: 20px; padding: 0 4px; }
  .nav-links { grid-column: 1 / -1; flex-direction: row; gap: 2px; overflow-x: auto; scrollbar-width: none; margin: 0 -4px; }
  .nav-item { flex: none; padding: 8px 12px; }
  .nav-heading { display: none; }
  .sidebar-user { grid-row: 1; grid-column: 2; margin: 0; padding: 0; border-top: none; flex-direction: row; align-items: center; }
  .sidebar-user > :not(form) { display: none; }
  .sidebar-user .button { height: 36px; padding: 0 14px; }
  .content { padding: 28px 20px; }
}
@media (max-width: 640px) {
  .content { padding: 24px 16px; }
}

dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 10px 24px; }
dt { color: var(--muted); }
dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.status { display: inline-flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 4px; }
.status.ok { color: var(--ok-text); }
.status.ok::before { background: var(--ok); }
.status.bad { color: var(--bad-text); }
.status.bad::before { background: var(--bad); }

code { font-family: ui-monospace, monospace; font-size: 14px; }

/* Devices */
.page-head { display: flex; flex-direction: column; gap: 6px; }
.flash {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--accent-tint);
  color: var(--accent-hover);
  font-size: 14px;
}
.add-device { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.add-device-text { display: flex; flex-direction: column; gap: 6px; flex: 1 1 280px; }
.add-device label { font-weight: 600; }
.pair-input {
  width: 180px;
  height: 48px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-sunk);
  color: var(--text);
  font-family: ui-monospace, monospace;
  font-size: 18px;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.device-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
/* The photo the screen shows now, whole: a crop at card size would cut
   the faces smart fit keeps. */
.device-preview {
  position: relative;
  aspect-ratio: 16 / 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #22282D;
  color: #98A3AB;
  font-size: 14px;
}
.device-preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.device-preview.offline img { opacity: 0.45; filter: grayscale(0.6); }
.status-pill {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  background: rgba(14, 20, 26, 0.72);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
}
.status-pill::before { content: ""; width: 8px; height: 8px; border-radius: 4px; }
.status-pill.ok::before { background: var(--ok); }
.status-pill.bad::before { background: var(--bad); }
.device-body { padding: 16px 20px 18px; display: flex; flex-direction: column; gap: 12px; }
.device-body h2 { margin: 0; font-size: 17px; font-weight: 600; }
.device-body h2 a { text-decoration: none; color: var(--text); }
.device-body h2 a:hover { color: var(--accent); }
.device-facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.device-facts dt { color: var(--muted); }
.device-facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.link-button.danger { color: var(--error-text); font-weight: 500; font-size: 13px; }

/* Sources and device detail */
h2 { margin: 0; font-size: 17px; font-weight: 600; }
legend { padding: 0; margin-bottom: 6px; font-size: 14px; font-weight: 500; }
fieldset { margin: 0; padding: 0; border: none; }
select {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-sunk);
  color: var(--text);
  font: inherit;
}
.section-label { font-size: 14px; letter-spacing: 1px; text-transform: uppercase; color: #71717A; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.time-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.source-types { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.source-type {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.source-type.active { border: 2px solid var(--accent); }
.source-type.soon { color: #A1A1AA; }
a.source-type { color: var(--text); text-decoration: none; }
a.source-type:hover { border-color: var(--border-strong); }
.relogin { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.relogin-row { display: flex; flex-wrap: wrap; gap: 8px; }
.relogin-row input { flex: 1 1 200px; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface-sunk); font: inherit; }
.relogin-row .button { height: 40px; }
.button.outline {
  height: 40px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-weight: 500;
}
.button.outline.danger { border-color: #FCA5A5; color: #B91C1C; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.list { padding: 0; }
.list-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--tab-bg);
}
.list-row:last-child { border-bottom: none; }
.list-main { flex: 1 1 260px; display: flex; flex-direction: column; gap: 4px; }
.row-title { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge.ok { background: #DCFCE7; color: var(--ok-text); }
.badge.error { background: var(--error-bg); color: var(--error-text); }
.badge.pending { background: #FEF3C7; color: var(--bad-text); }
.error-text { color: var(--error-text); }
.back { font-size: 14px; text-decoration: none; }
.detail-grid { display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-start; }
.detail-main { flex: 1 1 420px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.detail-side { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.detail-grid .card { padding: 24px; }
.option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.option-text { display: flex; flex-direction: column; gap: 2px; }
.option input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.source-name { margin-top: 6px; }

/* Album and group pickers */
.chosen-albums { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.chosen-albums:empty { display: none; }
.chosen-album { cursor: default; }
.chosen-album .link-button { flex: none; }
.chosen-album [data-detail]:empty { display: none; }
.combo { position: relative; }
.combo-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-sunk);
  color: var(--text);
  font: inherit;
}
.combo-list {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(24, 24, 27, 0.12);
}
.combo-option {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.combo-option.active, .combo-option:hover { background: var(--active-bg); }
.combo + [data-nomatch], .combo [data-nomatch] { margin-top: 6px; }

/* Users and account */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sidebar-name { font-weight: 600; font-size: 14px; }
.invite-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.invite-form .invite-email { flex: 1 1 260px; }
.invite-form .invite-role { width: 150px; }
.invite-form select { height: 48px; }
.invite-form .error { flex-basis: 100%; margin: 0; }
.invite-link input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface-sunk); font: inherit; font-family: ui-monospace, monospace; font-size: 13px; }
.table-card { padding: 0; overflow-x: auto; }
table.users { width: 100%; min-width: 680px; border-collapse: collapse; font-size: 15px; }
table.users th { text-align: left; padding: 14px 16px; font-size: 13px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); }
table.users td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.users th:first-child, table.users td:first-child { padding-left: 24px; }
table.users tr:last-child td { border-bottom: 0; }
table.users tr.pending { background: var(--surface-sunk); }
table.users .user-name { font-weight: 500; }
table.users .actions { text-align: right; white-space: nowrap; }
table.users .actions form { display: inline-block; margin-left: 6px; }
.role { display: inline-block; font-size: 13px; font-weight: 500; padding: 3px 10px; border-radius: 999px; background: var(--active-bg); color: var(--text-2); }
.role.admin { background: var(--accent-tint); color: var(--accent-hover); font-weight: 600; }
.role.pending { background: transparent; border: 1px dashed var(--muted); color: var(--muted); }
.small-button { height: 36px; padding: 0 12px; font-size: 14px; }
.danger-card { border-color: #FECACA; }
.danger-card h2 { color: var(--error-text); }
.login-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; }
.code-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.account { display: flex; flex-direction: column; gap: 20px; max-width: 760px; }
.account-delete { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.account-delete > div { flex: 1 1 320px; }
.pending-email { padding: 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-sunk); }
