:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-soft: #eef6f5;
  --ink: #16202f;
  --muted: #627084;
  --line: #d8dee8;
  --accent: #087c76;
  --accent-dark: #075f5b;
  --warn: #a53a3a;
  --amber: #916900;
  --shadow: 0 12px 34px rgba(31, 41, 55, .08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
.link-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 13px;
  cursor: pointer;
  font-weight: 800;
}

button:hover,
.link-button:hover {
  border-color: rgba(8, 124, 118, .38);
  color: var(--accent-dark);
}

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

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

button.danger {
  border-color: rgba(165, 58, 58, .28);
  color: var(--warn);
}

button:disabled {
  cursor: not-allowed;
  opacity: .56;
}

a {
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(12px);
}

.header-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 14px clamp(16px, 4vw, 34px) 10px;
}

.header-row h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.16;
}

.header-row [data-user-email] {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.app-main {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 26px) 34px;
}

.top-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 0 clamp(16px, 4vw, 34px) 12px;
}

.tab-button {
  min-width: 0;
  min-height: 38px;
  border-color: transparent;
  background: #eef2f7;
  color: #405064;
}

.tab-button.active {
  border-color: rgba(8, 124, 118, .34);
  background: var(--accent);
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .88);
  padding: 14px clamp(16px, 4vw, 34px);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.brand {
  min-width: 0;
}

.brand p,
.eyebrow {
  margin: 0 0 3px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.brand h1,
.login-card h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.main {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 26px) 34px;
}

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

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

.login-copy {
  margin: 10px 0 18px;
  color: var(--muted);
}

.form-grid,
.admin-form {
  display: grid;
  gap: 12px;
}

.admin-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-form .wide {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.message {
  min-height: 24px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.message[data-tone="success"] {
  color: var(--accent-dark);
}

.message[data-tone="error"] {
  color: var(--warn);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 13px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 26px;
  line-height: 1;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.filter-bar button {
  min-height: 34px;
  padding: 0 11px;
}

.filter-bar button.active {
  border-color: rgba(8, 124, 118, .36);
  background: var(--panel-soft);
  color: var(--accent-dark);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, .82fr) minmax(0, 1.18fr);
  gap: 14px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px;
}

.panel-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 14px;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.section-title-row h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.hint-text {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 8px;
  padding: 2px 8px;
  background: #eef2f7;
  color: #2f3a4d;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status-approved {
  background: #e7f6f3;
  color: var(--accent-dark);
}

.status-pending {
  background: #fff6df;
  color: var(--amber);
}

.status-blocked {
  background: #ffe9e9;
  color: var(--warn);
}

.device-gate {
  max-width: 620px;
}

.device-request-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-top: 14px;
}

.credential-grid,
.device-list {
  display: grid;
  gap: 10px;
}

.credential-card,
.device-row {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 13px;
}

.credential-card-head,
.device-row-main {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.credential-card h3 {
  margin: 0;
  font-size: 16px;
}

.credential-card p,
.device-row span {
  display: block;
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.credential-card button {
  justify-self: end;
}

.locked-panel,
.ready-panel {
  border: 1px solid #e5e9f1;
  border-radius: 8px;
  background: #fbfcfe;
  padding: 14px;
}

.ready-panel strong,
.ready-panel span,
.empty-state strong,
.empty-state span {
  display: block;
  overflow-wrap: anywhere;
}

.ready-panel span,
.empty-state span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.device-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.admin-console-grid {
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 17px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.card-list {
  display: grid;
  gap: 10px;
}

.work-card,
.profile-row,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 13px;
}

.work-card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.work-card-head p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.work-card h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.25;
}

.work-body {
  margin: 9px 0;
  color: #364153;
  overflow-wrap: anywhere;
}

.priority {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 8px;
  padding: 2px 8px;
  background: #eef2f7;
  color: #2f3a4d;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.priority-high,
.priority-urgent {
  background: #fff2dc;
  color: var(--amber);
}

.priority-urgent {
  background: #ffe9e9;
  color: var(--warn);
}

.work-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.admin-row .work-meta {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.work-meta div {
  border: 1px solid #e5e9f1;
  border-radius: 8px;
  padding: 8px;
}

.work-meta dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.work-meta dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.card-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

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

.profile-row strong,
.profile-row span {
  display: block;
  overflow-wrap: anywhere;
}

.profile-row span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.check-row input {
  width: auto;
  min-height: auto;
}

@media (max-width: 760px) {
  .topbar,
  .header-row,
  .toolbar,
  .panel-head,
  .section-title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions > *,
  .toolbar > button {
    flex: 1 1 auto;
  }

  .summary-grid,
  .content-grid,
  .admin-console-grid,
  .admin-form,
  .device-request-form,
  .work-meta,
  .admin-row .work-meta {
    grid-template-columns: 1fr;
  }

  .top-tabs {
    gap: 6px;
  }

  .tab-button {
    padding: 0 8px;
  }

  .credential-card button,
  .device-request-form button {
    width: 100%;
  }

  .main {
    padding-top: 14px;
  }

  .app-main {
    padding-top: 14px;
  }
}
