.widget {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--component-bg);
  flex-shrink: 0;
  min-height: 36px;
}

.widget-icon {
  display: inline-flex;
  align-items: center;
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}

.widget-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.widget-actions {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  flex-shrink: 0;
}

.widget-body {
  flex: 1;
  overflow: auto;
  padding: 0.75rem;
  position: relative;
  color: var(--text);
}

.widget-loading,
.widget-error,
.widget-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.widget-error {
  flex-direction: column;
  gap: 0.5rem;
  color: var(--status-error);
  padding: 1rem;
}

.widget-error-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.widget-error-message {
  color: var(--status-error);
  max-width: 32ch;
  line-height: 1.4;
}

.widget-error-retry {
  margin-top: 0.25rem;
  min-height: 28px;
  padding: 0.25rem 0.75rem;
  font-size: 0.8125rem;
}

/* ---------- Revoked-Platzhalter ---------- */

.widget-revoked {
  opacity: 0.85;
  background: repeating-linear-gradient(
    45deg,
    var(--bg-default),
    var(--bg-default) 10px,
    var(--component-bg) 10px,
    var(--component-bg) 20px
  );
}

.widget-revoked .widget-header {
  background: var(--border);
  color: var(--text-secondary);
}

.widget-revoked .widget-title {
  color: var(--text-secondary);
  font-style: italic;
}

.revoked-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 100%;
  text-align: center;
  padding: 1rem;
  color: var(--text-secondary);
}

.revoked-icon {
  font-size: 1.75rem;
  line-height: 1;
  opacity: 0.7;
}

.revoked-message {
  font-size: 0.875rem;
  max-width: 32ch;
  line-height: 1.4;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 0.5rem;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Renderer: Number / KpiCard ---------- */

.renderer-number {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  gap: 0.25rem;
}

.renderer-number-value {
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  font-weight: 700;
  color: var(--primary);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.renderer-number-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.renderer-kpi-trend {
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.renderer-kpi-trend--up { color: var(--status-success); }
.renderer-kpi-trend--down { color: var(--status-error); }
.renderer-kpi-trend--flat { color: var(--text-secondary); }

/* ---------- Renderer: Table ---------- */

.renderer-table {
  display: block;
  height: 100%;
  overflow: auto;
}

.renderer-table table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.renderer-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--component-bg);
}

.renderer-table thead th {
  background: var(--component-bg);
  box-shadow: inset 0 -1px 0 var(--border);
  padding: 0.375rem 0.5rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: none;
  white-space: nowrap;
}

.renderer-table tbody td {
  padding: 0.375rem 0.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.renderer-table tbody tr:hover td {
  background: var(--hover-bg);
}

.col-align-left { text-align: left; }
.col-align-right { text-align: right; font-variant-numeric: tabular-nums; }
.col-align-center { text-align: center; }

.renderer-table-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--component-bg);
}

.renderer-table-pager button {
  min-width: 24px;
  height: 24px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
  cursor: pointer;
}

.renderer-table-pager button:disabled {
  opacity: 0.4;
  cursor: default;
}

.renderer-table-pager button:not(:disabled):hover {
  background: var(--hover-bg);
}

/* ---------- Renderer: Charts ---------- */

.renderer-chart {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.renderer-chart canvas {
  display: block;
}

/* ---------- Widget-Header: Quick-Select + Last-Updated ---------- */

.widget-quick-select-slot:empty {
  display: none;
}

.quick-select {
  font-family: inherit;
  font-size: 0.75rem;
  padding: 2px 4px;
  height: 24px;
  max-width: 140px;
  background: var(--component-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}

.quick-select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.widget-last-updated {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---------- Modal (dialog) ---------- */

.modal {
  border: none;
  padding: 0;
  background: var(--component-bg);
  color: var(--text);
  border-radius: var(--radius-card);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
  max-width: min(90vw, 720px);
  width: 90vw;
  max-height: 85vh;
  overflow: hidden;
}

.modal::backdrop {
  background: rgb(0 0 0 / 0.35);
}

.modal[open] {
  animation: modal-fade-in 0.15s ease-out;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-form {
  display: flex;
  flex-direction: column;
  max-height: 85vh;
  margin: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}

.modal-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  font-size: 1.25rem;
}

.modal-body {
  padding: 1rem;
  overflow: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--header-bg);
}

/* ---------- Widget-Picker ---------- */

.picker-dialog {
  max-width: min(95vw, 900px);
  width: 900px;
}

.picker-search {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--component-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  margin-bottom: 0.75rem;
}

.picker-search:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

.picker-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
}

.picker-pill {
  padding: 0.25rem 0.75rem;
  font-family: inherit;
  font-size: 0.8125rem;
  line-height: 1.2;
  color: var(--text);
  background: var(--component-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}

.picker-pill:hover {
  background: var(--hover-bg);
}

.picker-pill.is-active {
  background: var(--primary);
  color: rgb(255 255 255);
  border-color: var(--primary);
}

.picker-pill:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.picker-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}

.picker-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--component-bg);
}

.picker-card:hover {
  border-color: var(--border-strong);
  background: var(--hover-bg);
}

.picker-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.picker-card-icon {
  font-size: 1.125rem;
  line-height: 1;
}

.picker-card-name {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.picker-card-desc {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.2em;
}

.picker-card-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: auto;
}

.picker-card-add {
  padding: 0.25rem 0.625rem;
  min-height: 28px;
  font-size: 0.8125rem;
}

.picker-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ---------- Settings-Dialog ---------- */

.settings-dialog {
  max-width: min(95vw, 520px);
  width: 520px;
}

.settings-section {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.settings-section-title {
  margin: 0 0 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.settings-field-inline {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.settings-field-inline .settings-label {
  margin: 0;
  font-weight: 400;
}

.settings-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
}

.settings-input {
  font-family: inherit;
  font-size: 0.875rem;
  padding: 0.375rem 0.5rem;
  color: var(--text);
  background: var(--component-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  min-height: 32px;
}

.settings-input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}

.settings-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.settings-daterange {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.settings-daterange .settings-input {
  flex: 1;
}

.settings-daterange-sep {
  color: var(--text-secondary);
}

.settings-field-unsupported {
  color: var(--status-warning);
  font-style: italic;
  font-size: 0.8125rem;
}
