:root {
  --bg: #f4f6f9;
  --text: #1f2937;
  --card: #ffffff;
  --accent: #0f766e;
  --accent-2: #115e59;
  --danger: #b91c1c;
  --border: #d1d5db;
  --topbar-bg: #ffffff;
  --topbar-border: #d1d5db;
  --brand-subtext: #4b5563;
  --surface-soft: #fbfdff;
  --surface-soft-danger: #fff7f7;
  --font-ui: "Segoe UI Variable", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background: radial-gradient(circle at top right, #e0f2fe, var(--bg));
}

body.os-windows { --font-ui: "Segoe UI Variable", "Segoe UI", Tahoma, sans-serif; }
body.os-macos { --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif; }
body.os-linux { --font-ui: "Ubuntu", "Noto Sans", "DejaVu Sans", Arial, sans-serif; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --text: #e5e7eb;
    --card: #1f2937;
    --border: #374151;
    --topbar-bg: #0f172a;
    --topbar-border: #334155;
    --brand-subtext: #cbd5e1;
    --surface-soft: #172233;
    --surface-soft-danger: #2b1b1f;
  }
  body {
    background: radial-gradient(circle at top right, #1f2937, var(--bg));
  }
}

.topbar {
  padding: 12px 20px;
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
}

.topbar nav { display: flex; gap: 12px; }
.topbar a { color: var(--text); text-decoration: none; }
.brand {
  display: inline-grid;
  grid-template-columns: 34px auto;
  grid-template-areas:
    "logo title"
    "logo subtitle";
  column-gap: 10px;
  row-gap: 1px;
  align-items: center;
}
.brand-logo-wrap {
  grid-area: logo;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.brand-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
}
.brand-title {
  grid-area: title;
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1.1;
}
.brand-subtitle {
  grid-area: subtitle;
  color: var(--brand-subtext);
  font-size: 0.74rem;
  line-height: 1.1;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.brand-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 6px 0 14px 0;
}
.brand-panel-logo-wrap {
  width: 66px;
  height: 66px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.brand-panel-logo {
  width: 66px;
  height: 66px;
  object-fit: contain;
}
.brand-panel-text {
  color: var(--brand-subtext);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.container {
  width: calc(100vw - 24px);
  max-width: none;
  padding: 0 12px;
  margin: 12px auto;
}

.card {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
}

.card.small { max-width: 420px; margin: 40px auto; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.metric { font-size: 2rem; font-weight: 700; margin: 0; }

.btn {
  border: 0;
  background: var(--accent);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.btn:hover { background: var(--accent-2); }
.btn-secondary { background: #4b5563; }
.btn-danger { background: var(--danger); }

label { display: block; font-weight: 600; margin-bottom: 8px; }
input,
select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 4px;
}
textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 4px;
  resize: vertical;
}

.stack { display: grid; gap: 10px; }
.grid-form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: end; }
.stack-form { display: grid; gap: 12px; max-width: 720px; }
.installer-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 10px;
  background: #f8fafc;
}

.licenses-list {
  display: grid;
  gap: 12px;
}

.license-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-soft);
}

.revoked-license-item {
  background: var(--surface-soft-danger);
  border-color: #fecaca;
}

.license-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

.license-summary::-webkit-details-marker {
  display: none;
}

.license-summary-main {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.license-summary-owner {
  font-weight: 600;
  text-align: right;
}

.license-details {
  margin-top: 10px;
}

.license-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-flow: row dense;
  gap: 16px;
}

.license-field {
  min-width: 0;
  align-self: start;
}

.license-label {
  font-size: 0.78rem;
  color: #4b5563;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.license-key-code {
  display: block;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  margin-bottom: 6px;
}

.license-hint {
  margin-top: 4px;
  color: #4b5563;
  font-size: 0.85rem;
}

.license-field-actions form {
  margin: 0;
}
.license-field-span-2 {
  grid-column: span 2;
}
.license-field-span-3 {
  grid-column: span 3;
}
.license-field-span-4 {
  grid-column: span 4;
}
.license-field-timeline {
  grid-column: 1 / -1;
}
.license-field-actions {
  grid-column: 1 / -1;
}
.license-actions-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

th, td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 8px;
  vertical-align: top;
  min-width: 120px;
}

.license-overrides-table th,
.license-overrides-table td {
  min-width: 0;
}

.license-overrides-table th:first-child,
.license-overrides-table td:first-child {
  min-width: 110px;
}

.entitlement-edit-form {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap !important;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  flex: 1 1 auto;
}

.entitlement-edit-form > * {
  flex: 0 0 auto;
}

.entitlement-edit-form input,
.entitlement-edit-form select {
  width: auto !important;
  min-width: 100px;
  max-width: 220px;
  margin: 0;
  height: 34px;
  line-height: 1.2;
}

.entitlement-edit-form .entitlement-enable {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
}

.entitlement-edit-form label:not(.entitlement-enable) {
  display: inline-flex;
  align-items: center;
  width: auto;
  margin: 0;
}

.entitlement-edit-form select[name="entitlement_type"] {
  min-width: 110px;
}

.entitlement-edit-form input[name="version_min"],
.entitlement-edit-form input[name="version_max"],
.entitlement-edit-form input[name="min_supported_version"],
.entitlement-edit-form input[name="paid_required_from_version"] {
  min-width: 110px;
}

.entitlement-edit-form select[name="trial_allowed"] {
  min-width: 120px;
}

.entitlement-edit-form input[name="trial_days"] {
  min-width: 90px;
}

.entitlement-edit-form input[name="notes"] {
  min-width: 140px;
  max-width: 240px;
}

.entitlement-edit-form input[type="checkbox"] {
  width: auto !important;
  min-width: 0;
  height: auto;
}

.entitlement-actions-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
}

.entitlement-actions-row form {
  margin: 0;
}

.entitlement-edit-form .btn {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.entitlement-actions-row .entitlement-delete-form {
  margin-left: auto;
  align-self: center;
}

.entitlement-actions-row .entitlement-delete-form .btn {
  height: 34px;
  white-space: nowrap;
}

.entitlement-edit-row td {
  background: rgba(255, 255, 255, 0.02);
  padding-top: 10px;
  padding-bottom: 10px;
}

.entitlement-edit-host {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form input {
  width: 100%;
  max-width: 120px;
  margin: 0;
}

.inline-form input.wide {
  max-width: 240px;
}

td code {
  display: inline-block;
  max-width: 280px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.sessions-table {
  table-layout: fixed;
}

.sessions-table th,
.sessions-table td {
  min-width: 0;
}

.sessions-table td {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.sessions-table .btn {
  white-space: nowrap;
}

.copy-license-key {
  margin-top: 0;
}

.error { color: var(--danger); margin: 0; }

.notice-ok {
  border-left: 4px solid var(--accent);
}

.notice-error {
  border-left: 4px solid var(--danger);
}

.inline-form form {
  margin: 0;
}

@media (max-width: 800px) {
  .topbar { flex-wrap: wrap; }
  th, td { min-width: 160px; }
  .inline-form input.wide { max-width: 100%; }
  .license-grid { grid-template-columns: 1fr; }
  .license-field-timeline,
  .license-field-actions,
  .license-field-span-2,
  .license-field-span-3,
  .license-field-span-4 {
    grid-column: auto;
  }
  .license-summary {
    flex-direction: column;
    align-items: flex-start;
  }
  .license-summary-owner {
    text-align: left;
  }
}

.deploy-overlay {
  position: fixed;
  right: 14px;
  bottom: 14px;
  max-width: min(460px, 92vw);
  background: rgba(17, 24, 39, 0.92);
  color: #f9fafb;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.86rem;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.deploy-overlay:not([open]) .deploy-content {
  display: none;
}

.deploy-toggle {
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 24px;
  color: #f9fafb;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 6px 0;
  padding: 0 2px;
  line-height: 1;
  border-radius: 4px;
}

.deploy-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
}

.deploy-toggle::-webkit-details-marker {
  display: none;
}

.deploy-toggle::marker {
  content: "";
}

.deploy-row + .deploy-row {
  margin-top: 6px;
}

@media (max-width: 1180px) and (min-width: 801px) {
  .license-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .license-field-span-3,
  .license-field-span-4 {
    grid-column: 1 / -1;
  }
}

.muted { color: var(--brand-subtext); }
.small { font-size: 0.9rem; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 0.95rem;
}
.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.data-table th {
  background: var(--surface-soft);
}
.hash-cell { font-size: 0.82rem; }

.feedback-pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-soft);
}

.feedback-row {
  cursor: pointer;
}

.feedback-row-selected {
  background: rgba(15, 118, 110, 0.12);
}

.feedback-toast {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.feedback-screenshot-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.feedback-screenshot-button {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  margin: 0;
  background: var(--surface-soft);
  cursor: pointer;
  overflow: hidden;
  width: 100%;
}

.feedback-screenshot-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.feedback-screenshot {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}

.feedback-image-viewer {
  position: fixed;
  inset: 0;
  z-index: 1200;
}

.feedback-image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
}

.feedback-image-viewer-toolbar {
  position: absolute;
  top: 12px;
  right: 12px;
  left: 12px;
  z-index: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  color: #f3f4f6;
  font-weight: 600;
}

.feedback-image-viewer-stage {
  position: absolute;
  inset: 54px 12px 12px 12px;
  overflow: hidden;
  cursor: grab;
}

.feedback-image-viewer-stage.is-panning {
  cursor: grabbing;
}

.feedback-image-viewer-image {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  max-height: none;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.system-usage-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  align-items: end;
}

.metric-line {
  margin: 8px 0 0 0;
  font-size: 1.05rem;
}

.metrics-high-usage {
  color: #dc2626;
  font-weight: 700;
}

/* ── Product Policies inline editor ── */
.policy-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.policy-page-header h1 { margin: 0 0 4px 0; }
.policy-page-header p { margin: 0; }

#policy-list { display: grid; gap: 6px; }

.policy-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.policy-item.is-open { border-color: var(--accent); }
.policy-item-new { border-style: dashed; }

.policy-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  background: var(--surface-soft);
  user-select: none;
}
.policy-summary:hover { background: var(--card); }
.policy-summary-new { cursor: default; background: var(--card); }
.policy-summary-new:hover { background: var(--card); }

.policy-summary-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.policy-summary-app { font-size: 0.95rem; }

.policy-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-ok  { background: #d1fae5; color: #065f46; }
.badge-off { background: #fee2e2; color: #991b1b; }
@media (prefers-color-scheme: dark) {
  .badge-ok  { background: #064e3b; color: #6ee7b7; }
  .badge-off { background: #7f1d1d; color: #fca5a5; }
}

.policy-summary-chip {
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
}
.policy-summary-chip.muted { color: #6b7280; }

.policy-chevron {
  font-size: 0.7rem;
  color: #6b7280;
  flex-shrink: 0;
  transition: transform 0.15s;
}
.policy-item.is-open .policy-chevron { transform: rotate(180deg); }

.policy-editor {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--card);
}

.policy-editor-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.policy-editor-actions-left { display: flex; gap: 8px; }

.input-locked {
  background: var(--surface-soft);
  color: #6b7280;
  cursor: not-allowed;
}

.btn-sm { padding: 5px 10px; font-size: 0.82rem; }

.muted { color: #6b7280; }
.small { font-size: 0.85rem; }
