:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #17212b;
  --muted: #607083;
  --line: #d8e0e8;
  --accent: #2a7de1;
  --accent-2: #0f8f72;
  --danger: #c2414b;
  --warn: #b27712;
  --shadow: 0 10px 30px rgba(24, 39, 75, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(20px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.topbar p,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.icon-btn,
.plain-btn,
.primary-btn,
.tab {
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
}

.icon-btn {
  width: 42px;
  font-size: 22px;
  line-height: 1;
}

.plain-btn,
.primary-btn,
.tab {
  padding: 0 12px;
  font-size: 14px;
}

.primary-btn {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.notice {
  padding: 12px;
  border: 1px solid #f1c45f;
  background: #fff7df;
  color: #60420a;
  border-radius: 8px;
  margin-bottom: 12px;
}

.hidden {
  display: none !important;
}

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

.metric {
  min-height: 78px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric strong {
  display: block;
  font-size: 24px;
  line-height: 1.1;
  margin-bottom: 6px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr minmax(220px, 320px);
  gap: 8px;
  margin-bottom: 12px;
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 1px;
}

.tab.active {
  border-color: var(--accent);
  background: #e6f0fd;
  color: #155da8;
}

.search {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0 11px;
  outline: none;
}

.search:focus {
  border-color: var(--accent);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.85fr);
  gap: 12px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.list {
  display: grid;
}

.empty {
  padding: 16px 12px;
  color: var(--muted);
  font-size: 14px;
}

.row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.row:last-child {
  border-bottom: 0;
}

.user-row {
  width: 100%;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.request-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.primary-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.name {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subline {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.user-title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.user-card-grid {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(180px, 1.2fr) minmax(170px, 1fr) minmax(120px, 0.7fr);
  gap: 8px;
}

.data-point {
  min-width: 0;
  padding: 9px 10px;
  background: #f8fafc;
  border: 1px solid #e5ebf1;
  border-radius: 8px;
}

.data-point span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.data-point strong {
  display: block;
  min-width: 0;
  font-size: 13px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.badge.active {
  background: #e2f5ec;
  color: #08724f;
}

.badge.expired {
  background: #ffe6e8;
  color: var(--danger);
}

.badge.new {
  background: #eef2f6;
  color: #4a5968;
}

.badge.pending,
.badge.expiring {
  background: #fff1d6;
  color: var(--warn);
}

.state-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.device-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill,
.device-chip {
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--surface-2);
  color: #3d4c5c;
  font-size: 12px;
}

.pill.on,
.device-chip.on {
  background: #e2f5ec;
  color: #08724f;
}

.quiet {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.done-btn {
  min-height: 34px;
  border: 1px solid var(--accent-2);
  background: #e2f5ec;
  color: #08724f;
  border-radius: 8px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 650;
}

.lookup-panel {
  margin-top: 12px;
}

.lookup-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
}

.credentials {
  border-top: 1px solid var(--line);
  padding: 12px;
  font-size: 14px;
}

.credentials code,
.detail-grid code {
  word-break: break-all;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(23, 33, 43, 0.36);
  display: flex;
  justify-content: flex-end;
}

.drawer-card {
  width: min(480px, 100%);
  height: 100%;
  overflow: auto;
  background: var(--surface);
  box-shadow: var(--shadow);
}

#drawerBody {
  padding: 12px;
}

.drawer-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.drawer-summary > div,
.drawer-section {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.drawer-summary span,
.info-grid span,
.drawer-section > h3 {
  display: block;
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.drawer-summary strong,
.info-grid strong {
  font-size: 14px;
}

.drawer-sections {
  display: grid;
  gap: 10px;
}

.drawer-section code {
  display: block;
  word-break: break-all;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.drawer-requests {
  display: grid;
  gap: 6px;
}

.drawer-request {
  padding: 9px;
  border: 1px solid #e5ebf1;
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}

.inline-empty {
  padding: 0;
}

.detail-grid {
  display: grid;
  gap: 10px;
  font-size: 14px;
}

.detail-item {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.detail-item span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 880px) {
  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .toolbar,
  .split {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 520px) {
  .app-shell {
    padding-left: 8px;
    padding-right: 8px;
  }

  h1 {
    font-size: 22px;
  }

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

  .metric {
    min-height: 70px;
  }

  .lookup-row,
  .request-row,
  .user-card-grid,
  .drawer-summary,
  .info-grid {
    grid-template-columns: 1fr;
  }
}
