.xgm-app {
  --xgm-bg: #f4f7fb;
  --xgm-card: #fff;
  --xgm-text: #182335;
  --xgm-muted: #64748b;
  --xgm-border: #dfe7f1;
  --xgm-primary: #1769e0;
  --xgm-primary-dark: #0e4eaf;
  --xgm-success: #087b55;
  --xgm-danger: #c12b3d;
  --xgm-warning: #9b5c04;
  --xgm-shadow: 0 10px 30px rgba(25, 50, 85, .09);
  color: var(--xgm-text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  width: 100%;
}

.xgm-app * { box-sizing: border-box; }
.xgm-app button, .xgm-app input, .xgm-app select, .xgm-app textarea { font: inherit; }
.xgm-app button { cursor: pointer; }
.xgm-app button:focus-visible, .xgm-app input:focus-visible, .xgm-app select:focus-visible, .xgm-app textarea:focus-visible {
  outline: 3px solid rgba(23, 105, 224, .24);
  outline-offset: 2px;
}

.xgm-shell {
  background: var(--xgm-bg);
  border: 1px solid var(--xgm-border);
  border-radius: 20px;
  box-shadow: var(--xgm-shadow);
  min-height: 600px;
  overflow: hidden;
}

.xgm-topbar {
  align-items: center;
  background: linear-gradient(135deg, #12243e, #173f78);
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  padding: 22px 24px;
}

.xgm-brand h2 { color: #fff; font-size: 22px; line-height: 1.15; margin: 0 0 4px; }
.xgm-brand p { color: #cbd9ec; font-size: 13px; margin: 0; }
.xgm-save-state { align-items: center; color: #d7e7ff; display: inline-flex; font-size: 12px; gap: 6px; }
.xgm-save-state::before { background: #5ee4ae; border-radius: 50%; content: ""; height: 8px; width: 8px; }

.xgm-projectbar {
  align-items: end;
  background: #fff;
  border-bottom: 1px solid var(--xgm-border);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1.5fr) minmax(180px, 2fr) auto;
  padding: 16px 24px;
}

.xgm-actions, .xgm-inline, .xgm-toolbar { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; }
.xgm-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.xgm-field > label, .xgm-label { color: #3a4b63; font-size: 12px; font-weight: 700; letter-spacing: .01em; }
.xgm-help { color: var(--xgm-muted); font-size: 12px; margin: 4px 0 0; }

.xgm-input, .xgm-select, .xgm-textarea {
  background: #fff;
  border: 1px solid #cbd6e5;
  border-radius: 9px;
  color: var(--xgm-text);
  min-height: 42px;
  padding: 9px 11px;
  width: 100%;
}
.xgm-textarea { min-height: 90px; resize: vertical; }
.xgm-input:focus, .xgm-select:focus, .xgm-textarea:focus { border-color: var(--xgm-primary); }

.xgm-btn {
  align-items: center;
  background: #fff;
  border: 1px solid #cbd6e5;
  border-radius: 9px;
  color: #263750;
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
  justify-content: center;
  line-height: 1.1;
  min-height: 40px;
  padding: 9px 13px;
  text-decoration: none;
}
.xgm-btn:hover { background: #f4f7fb; border-color: #aabbd1; }
.xgm-btn-primary { background: var(--xgm-primary); border-color: var(--xgm-primary); color: #fff; }
.xgm-btn-primary:hover { background: var(--xgm-primary-dark); border-color: var(--xgm-primary-dark); }
.xgm-btn-success { background: var(--xgm-success); border-color: var(--xgm-success); color: #fff; }
.xgm-btn-danger { color: var(--xgm-danger); }
.xgm-btn-ghost { background: transparent; border-color: rgba(255,255,255,.35); color: #fff; }
.xgm-btn-small { font-size: 12px; min-height: 32px; padding: 6px 9px; }
.xgm-btn-icon { min-width: 34px; padding-left: 8px; padding-right: 8px; }
.xgm-btn[disabled] { cursor: not-allowed; opacity: .5; }

.xgm-steps {
  background: #fff;
  border-bottom: 1px solid var(--xgm-border);
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 10px 20px 0;
}
.xgm-step {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  color: #5d6d83;
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 700;
  padding: 11px 14px 12px;
}
.xgm-step.is-active { border-bottom-color: var(--xgm-primary); color: var(--xgm-primary); }
.xgm-step-number { align-items: center; background: #e9eef6; border-radius: 50%; display: inline-flex; height: 23px; justify-content: center; margin-right: 6px; width: 23px; }
.xgm-step.is-active .xgm-step-number { background: var(--xgm-primary); color: #fff; }

.xgm-content { padding: 24px; }
.xgm-panel[hidden] { display: none !important; }
.xgm-section-head { align-items: flex-start; display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; margin-bottom: 18px; }
.xgm-section-head h3 { color: var(--xgm-text); font-size: 21px; margin: 0 0 4px; }
.xgm-section-head p { color: var(--xgm-muted); margin: 0; }
.xgm-grid { display: grid; gap: 18px; }
.xgm-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.xgm-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.xgm-card { background: var(--xgm-card); border: 1px solid var(--xgm-border); border-radius: 14px; box-shadow: 0 4px 14px rgba(25, 50, 85, .04); padding: 18px; }
.xgm-card h4 { color: var(--xgm-text); font-size: 16px; margin: 0 0 12px; }
.xgm-form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.xgm-form-grid .xgm-span-2 { grid-column: span 2; }

.xgm-empty { border: 1px dashed #c0ccdc; border-radius: 12px; color: var(--xgm-muted); padding: 28px 18px; text-align: center; }
.xgm-empty strong { color: #33455e; display: block; margin-bottom: 5px; }
.xgm-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.xgm-list-item { align-items: center; background: #f8fafc; border: 1px solid var(--xgm-border); border-radius: 10px; display: flex; gap: 10px; padding: 10px; }
.xgm-list-main { flex: 1; min-width: 0; }
.xgm-list-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xgm-list-main small { color: var(--xgm-muted); }
.xgm-code { background: #e9f1ff; border-radius: 5px; color: #174f9f; font-family: Consolas, monospace; font-size: 12px; font-weight: 700; padding: 3px 6px; }
.xgm-type-dot { border-radius: 50%; flex: 0 0 auto; height: 10px; width: 10px; }

.xgm-template {
  align-items: center;
  background: #f9fbfe;
  border: 2px dashed #c5d3e5;
  border-radius: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 110px;
  padding: 16px;
}
.xgm-template.is-dragover { background: #edf5ff; border-color: var(--xgm-primary); }
.xgm-chip { align-items: center; background: #fff; border: 1px solid #bfcde0; border-left: 4px solid var(--xgm-primary); border-radius: 8px; display: inline-flex; gap: 7px; padding: 7px 8px; }
.xgm-chip[draggable="true"] { cursor: grab; }
.xgm-chip-code { font-family: Consolas, monospace; font-size: 12px; font-weight: 700; }
.xgm-chip button { background: transparent; border: 0; color: #687991; font-weight: 800; padding: 1px 3px; }
.xgm-chip button:hover { color: var(--xgm-danger); }
.xgm-preview-line { background: #17243a; border-radius: 10px; color: #e8f1ff; font-family: Consolas, monospace; margin-top: 12px; overflow-wrap: anywhere; padding: 12px 14px; }

.xgm-stat-grid { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 16px 0; }
.xgm-stat { background: #f7f9fc; border: 1px solid var(--xgm-border); border-radius: 10px; padding: 12px; }
.xgm-stat strong { display: block; font-size: 20px; }
.xgm-stat span { color: var(--xgm-muted); font-size: 12px; }
.xgm-callout { background: #eef6ff; border: 1px solid #cce1ff; border-radius: 10px; color: #244f83; font-size: 13px; margin: 12px 0; padding: 11px 13px; }
.xgm-callout-warning { background: #fff8e8; border-color: #f0d99f; color: #7b510d; }
.xgm-checks { display: flex; flex-wrap: wrap; gap: 8px; }
.xgm-check { align-items: center; background: #f8fafc; border: 1px solid #d9e2ee; border-radius: 8px; display: inline-flex; font-size: 13px; font-weight: 600; gap: 6px; padding: 8px 10px; }
.xgm-check input { margin: 0; }

.xgm-map-tabs { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.xgm-map-tab { background: #fff; border: 1px solid #cbd6e5; border-radius: 8px; color: #41536c; font-size: 12px; font-weight: 800; padding: 8px 12px; }
.xgm-map-tab.is-active { background: var(--xgm-primary); border-color: var(--xgm-primary); color: #fff; }
.xgm-table-wrap { border: 1px solid var(--xgm-border); border-radius: 12px; max-height: 620px; overflow: auto; }
.xgm-table { border-collapse: collapse; font-size: 13px; width: 100%; }
.xgm-table th { background: #edf2f8; color: #3e5069; font-size: 11px; letter-spacing: .04em; padding: 10px; position: sticky; text-align: left; text-transform: uppercase; top: 0; z-index: 2; }
.xgm-table td { border-top: 1px solid #e4ebf3; padding: 9px 10px; vertical-align: middle; }
.xgm-table tr:hover td { background: #fbfdff; }
.xgm-table .xgm-time { color: #233a59; font-family: Consolas, monospace; font-weight: 800; white-space: nowrap; width: 74px; }
.xgm-codes-cell { line-height: 1.7; min-width: 250px; overflow-wrap: anywhere; }
.xgm-insert-code { background: #e7f8ef; border-radius: 4px; color: #08724e; font-family: Consolas, monospace; font-weight: 800; padding: 2px 4px; }
.xgm-break-code { background: #173f78; border-radius: 4px; color: #fff; font-family: Consolas, monospace; font-weight: 800; padding: 2px 5px; }
.xgm-row-actions { white-space: nowrap; width: 1%; }

.xgm-ad-card { background: #fff; border: 1px solid var(--xgm-border); border-radius: 11px; display: grid; gap: 10px; grid-template-columns: minmax(160px, 1.4fr) repeat(3, minmax(90px, .7fr)) auto; padding: 13px; }
.xgm-ad-card strong { display: block; }
.xgm-ad-card small { color: var(--xgm-muted); }
.xgm-ad-meta span { color: #53647a; display: block; font-size: 12px; }

.xgm-toast-stack { bottom: 18px; display: flex; flex-direction: column; gap: 8px; max-width: 380px; position: fixed; right: 18px; z-index: 999999; }
.xgm-toast { animation: xgm-in .2s ease-out; background: #17243a; border-radius: 9px; box-shadow: 0 10px 28px rgba(0,0,0,.2); color: #fff; font-size: 13px; padding: 12px 15px; }
.xgm-toast.is-error { background: #9d2534; }
.xgm-toast.is-success { background: #087550; }
@keyframes xgm-in { from { opacity: 0; transform: translateY(8px); } }

.xgm-modal-backdrop { align-items: center; background: rgba(12, 24, 42, .62); display: flex; inset: 0; justify-content: center; padding: 18px; position: fixed; z-index: 999998; }
.xgm-modal { background: #fff; border-radius: 14px; box-shadow: 0 22px 65px rgba(0,0,0,.28); max-height: 90vh; max-width: 620px; overflow: auto; padding: 20px; width: 100%; }
.xgm-modal h3 { margin: 0 0 8px; }
.xgm-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.xgm-loading { color: #52647b; padding: 36px; text-align: center; }
.xgm-sr-only { height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; clip: rect(0,0,0,0); white-space: nowrap; }
.xgm-footer-note { color: var(--xgm-muted); font-size: 12px; margin-top: 18px; text-align: center; }

@media (max-width: 900px) {
  .xgm-projectbar { grid-template-columns: 1fr 1fr; }
  .xgm-projectbar .xgm-actions { grid-column: span 2; }
  .xgm-grid-2, .xgm-grid-3 { grid-template-columns: 1fr; }
  .xgm-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .xgm-ad-card { grid-template-columns: 1fr 1fr; }
  .xgm-ad-card .xgm-actions { grid-column: span 2; }
}

@media (max-width: 620px) {
  .xgm-shell { border-radius: 0; }
  .xgm-topbar, .xgm-content { padding: 18px 14px; }
  .xgm-projectbar { align-items: stretch; grid-template-columns: 1fr; padding: 14px; }
  .xgm-projectbar .xgm-actions { grid-column: auto; }
  .xgm-projectbar .xgm-btn { flex: 1 1 calc(50% - 8px); }
  .xgm-steps { padding-left: 8px; }
  .xgm-step { padding-left: 9px; padding-right: 9px; }
  .xgm-step-number { display: none; }
  .xgm-form-grid { grid-template-columns: 1fr; }
  .xgm-form-grid .xgm-span-2 { grid-column: auto; }
  .xgm-stat-grid { grid-template-columns: 1fr 1fr; }
  .xgm-ad-card { grid-template-columns: 1fr; }
  .xgm-ad-card .xgm-actions { grid-column: auto; }
  .xgm-table th:nth-child(3), .xgm-table td:nth-child(3) { display: none; }
  .xgm-toast-stack { bottom: 10px; left: 10px; right: 10px; }
}

@media print {
  .xgm-topbar, .xgm-projectbar, .xgm-steps, .xgm-toolbar, .xgm-row-actions, .xgm-footer-note { display: none !important; }
  .xgm-shell, .xgm-card, .xgm-table-wrap { border: 0; box-shadow: none; max-height: none; }
  .xgm-content { padding: 0; }
  .xgm-table th { position: static; }
}
