/* Home Assistant–inspired theme tokens */
:root {
  --primary-color: #03a9f4;
  --dark-primary-color: #0288d1;
  --accent-color: #ff9800;
  --primary-background-color: #fafafa;
  --secondary-background-color: #e5e5e5;
  --card-background-color: #ffffff;
  --primary-text-color: #212121;
  --secondary-text-color: #727272;
  --text-primary-color: #ffffff;
  --disabled-text-color: #bdbdbd;
  --divider-color: rgba(0, 0, 0, 0.12);
  --error-color: #db4437;
  --success-color: #43a047;
  --app-header-background-color: var(--primary-color);
  --app-header-text-color: var(--text-primary-color);
  --sidebar-background-color: #ffffff;
  --ha-card-border-radius: 12px;
  --ha-card-box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
  --mdc-shape-small: 4px;
  --font-family: Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --header-height: 56px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-family);
  font-size: 14px;
  color: var(--primary-text-color);
  background: var(--primary-background-color);
  -webkit-font-smoothing: antialiased;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--app-header-background-color);
  color: var(--app-header-text-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.app-header .menu-icon {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.app-header .menu-icon:hover {
  background: rgba(255, 255, 255, 0.12);
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.02em;
  flex: 1;
}

.app-header .badge {
  font-size: 12px;
  opacity: 0.9;
  background: rgba(0, 0, 0, 0.18);
  padding: 4px 10px;
  border-radius: 12px;
}

.layout {
  display: grid;
  grid-template-columns: 256px 1fr;
  min-height: calc(100vh - var(--header-height));
}

.sidebar {
  background: var(--sidebar-background-color);
  border-right: 1px solid var(--divider-color);
  padding: 16px 8px;
}

.sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-radius: 0 24px 24px 0;
  color: var(--primary-text-color);
  text-decoration: none;
  cursor: default;
}

.sidebar .nav-item.active {
  background: color-mix(in srgb, var(--primary-color) 18%, transparent);
  color: var(--primary-color);
  font-weight: 500;
}

.sidebar .nav-item svg {
  flex-shrink: 0;
}

.sidebar .hint {
  margin: 24px 16px 8px;
  color: var(--secondary-text-color);
  font-size: 12px;
  line-height: 1.4;
}

.main {
  padding: 16px;
  max-width: 960px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.toolbar label {
  color: var(--secondary-text-color);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 1;
}

.ha-textfield {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--divider-color);
  border-radius: var(--mdc-shape-small);
  background: var(--card-background-color);
  color: var(--primary-text-color);
  min-width: 160px;
}

.ha-textfield:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 0;
  border-color: var(--primary-color);
}

.ha-button {
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--mdc-shape-small);
  background: var(--primary-color);
  color: var(--text-primary-color);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.ha-button:hover {
  background: var(--dark-primary-color);
}

.ha-button.secondary {
  background: transparent;
  color: var(--primary-color);
  box-shadow: none;
  border: 1px solid var(--divider-color);
}

.ha-button.secondary:hover {
  background: color-mix(in srgb, var(--primary-color) 10%, transparent);
}

.ha-button.danger {
  background: var(--error-color);
}

.ha-button:disabled {
  background: var(--disabled-text-color);
  cursor: not-allowed;
  box-shadow: none;
}

.ha-card {
  background: var(--card-background-color);
  border-radius: var(--ha-card-border-radius);
  box-shadow: var(--ha-card-box-shadow);
  margin-bottom: 16px;
  overflow: hidden;
}

.ha-card-header {
  padding: 16px 16px 0;
  font-size: 18px;
  font-weight: 400;
}

.ha-card .card-content {
  padding: 16px;
}

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

.form-grid .row {
  display: grid;
  gap: 6px;
}

.form-grid .row.two {
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-grid label {
  color: var(--secondary-text-color);
  font-size: 12px;
}

.form-grid textarea.ha-textfield {
  height: auto;
  min-height: 72px;
  padding: 10px 12px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--divider-color);
  margin-bottom: 12px;
}

.tabs button {
  border: 0;
  background: transparent;
  color: var(--secondary-text-color);
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.tabs button.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

.panel[hidden] {
  display: none;
}

.identity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.identity-card {
  background: var(--card-background-color);
  border-radius: var(--ha-card-border-radius);
  box-shadow: var(--ha-card-box-shadow);
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  transition: box-shadow 0.15s ease;
}

.identity-card:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.16);
}

.identity-card .meta .issuer {
  color: var(--secondary-text-color);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.identity-card .meta .label {
  font-size: 16px;
  font-weight: 500;
  margin-top: 2px;
  word-break: break-word;
}

.identity-card .meta .agent {
  margin-top: 6px;
  font-size: 12px;
  color: var(--secondary-text-color);
}

.identity-card.stale-card {
  border-left: 3px solid var(--accent-color);
}

.identity-card .tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.identity-card .tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 2px 8px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--primary-color) 12%, transparent);
  color: var(--primary-color);
}

.identity-card .tag.source {
  background: color-mix(in srgb, var(--dark-primary-color) 14%, transparent);
  color: var(--dark-primary-color);
}

.identity-card .tag.agent {
  background: rgba(0, 0, 0, 0.06);
  color: var(--secondary-text-color);
}

.identity-card .tag.added-by {
  background: color-mix(in srgb, var(--success-color) 16%, transparent);
  color: var(--success-color);
}

.identity-card .tag.stale {
  background: color-mix(in srgb, var(--accent-color) 18%, transparent);
  color: #e65100;
}

.identity-card .provenance {
  margin-top: 6px;
  font-size: 12px;
  color: var(--secondary-text-color);
  line-height: 1.35;
}

.identity-card .provenance.muted {
  font-style: italic;
  opacity: 0.85;
}

.identity-card .notes {
  margin-top: 4px;
  font-size: 12px;
  color: var(--primary-text-color);
  opacity: 0.85;
}

.identity-card .code-block {
  text-align: right;
  cursor: pointer;
  user-select: none;
}

.identity-card .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--primary-color);
  line-height: 1.1;
}

.identity-card .code.expiring {
  color: var(--accent-color);
}

.ring-wrap {
  display: inline-grid;
  place-items: center;
  margin-top: 6px;
}

.ring {
  width: 28px;
  height: 28px;
  transform: rotate(-90deg);
}

.ring circle.track {
  fill: none;
  stroke: var(--divider-color);
  stroke-width: 3;
}

.ring circle.prog {
  fill: none;
  stroke: var(--primary-color);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.2s linear, stroke 0.2s ease;
}

.ring circle.prog.warn {
  stroke: var(--accent-color);
}

.card-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  border-top: 1px solid var(--divider-color);
  margin-top: 4px;
  padding-top: 8px;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--secondary-text-color);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--primary-color);
}

.icon-btn.danger:hover {
  color: var(--error-color);
}

.empty {
  text-align: center;
  color: var(--secondary-text-color);
  padding: 48px 16px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #323232;
  color: #fff;
  padding: 12px 20px;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
  z-index: 100;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.error-banner {
  background: color-mix(in srgb, var(--error-color) 12%, white);
  color: var(--error-color);
  border-left: 4px solid var(--error-color);
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: 4px;
  display: none;
}

.error-banner.show {
  display: block;
}

@media (max-width: 800px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .form-grid .row.two {
    grid-template-columns: 1fr;
  }
}
