* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; overflow: hidden; }
a { color: inherit; }
button, input, select { font: inherit; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.csg-main {
  min-height: 100vh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--cm-int-bg);
  color: var(--cm-int-text);
  font: 400 15px/1.5 var(--cm-int-font);
}

.csg-head {
  flex: 0 0 auto;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--cm-int-divider);
}

.csg-head h1 {
  margin: 0;
  color: var(--cm-int-text);
  font-size: 24px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.015em;
}

.csg-head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.csg-scroll-region { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 20px 24px 40px; }

.csg-btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: var(--cm-int-radius-md);
  background: transparent;
  color: var(--cm-int-text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}

.csg-btn:hover { background: rgba(233, 233, 237, 0.07); }
.csg-btn:active { background: rgba(233, 233, 237, 0.12); }
.csg-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.csg-btn-secondary { border-color: var(--cm-int-divider); }
.csg-btn-secondary:hover { border-color: var(--cm-int-divider-strong); }
.csg-btn-primary { border-color: var(--cm-int-accent); color: var(--cm-int-accent-hover); }
.csg-btn-primary:hover { background: rgba(145, 132, 217, 0.12); }
.csg-btn-quiet { color: var(--cm-int-text-subtle); }

.csg-section-heading { min-height: 25px; display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.csg-my-section { margin-bottom: 24px; }
.csg-my-section h2, .csg-browse-section > h2 { margin: 0 0 10px; font-size: 15px; font-weight: 600; line-height: 1.3; }
.csg-section-heading h2 { margin: 0; }
.csg-status { color: var(--cm-int-text-muted); font-size: 13px; }
.csg-status.ok { color: var(--cm-int-success); }
.csg-status.err { color: var(--cm-int-danger); }

.csg-my-styles { display: flex; flex-wrap: wrap; gap: 10px; }
.csg-my-card {
  width: min(220px, 100%);
  min-height: 70px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--cm-int-radius-md);
  background: var(--cm-int-surface);
  color: var(--cm-int-text);
  cursor: pointer;
}
.csg-my-card:hover { border-color: var(--cm-int-divider-strong); }
.csg-my-card.selected { background: var(--cm-int-surface-selected); }
.csg-my-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.csg-my-card-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; font-weight: 500; }
.csg-remove-btn { min-height: 20px; padding: 0; border: 0; background: transparent; color: var(--cm-int-text-subtle); font-size: 12px; cursor: pointer; }
.csg-remove-btn:hover { color: var(--cm-int-danger); }
.csg-tag { width: max-content; max-width: 100%; padding: 3px 10px; border-radius: 6px; background: #3f424d; color: #f3f5fe; font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csg-tag-accent { background: var(--cm-int-accent-soft); color: var(--cm-int-accent-ink); }
.csg-empty-inline { width: 100%; min-height: 86px; border: 1px dashed var(--cm-int-divider); border-radius: var(--cm-int-radius-md); }

.csg-browse-section { position: relative; }
.csg-browse-toolbar { position: relative; display: flex; align-items: stretch; gap: 10px; margin-bottom: 10px; }
.csg-searchbar { flex: 1 1 360px; max-width: 420px; min-width: 220px; }
.csg-searchbar input {
  width: 100%;
  height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--cm-int-divider);
  border-radius: var(--cm-int-radius-md);
  background: var(--cm-int-surface);
  color: var(--cm-int-text);
  outline: 0;
}
.csg-searchbar input::placeholder { color: var(--cm-int-text-muted); }
.csg-searchbar input:hover { border-color: var(--cm-int-divider-strong); }
.csg-searchbar input:focus-visible { border-color: var(--cm-int-accent); outline-offset: 0; }

.csg-mode-tabs { display: inline-flex; min-width: 0; overflow: hidden; border: 1px solid var(--cm-int-divider); border-radius: var(--cm-int-radius-md); }
.csg-mode-tab { min-height: 36px; padding: 6px 12px; border: 0; border-left: 1px solid var(--cm-int-divider); background: transparent; color: var(--cm-int-text); font-size: 14px; cursor: pointer; white-space: nowrap; }
.csg-mode-tab:first-child { border-left: 0; }
.csg-mode-tab:hover { background: rgba(233, 233, 237, 0.07); }
.csg-mode-tab.active { color: var(--cm-int-accent-hover); box-shadow: inset 0 0 0 1px var(--cm-int-accent); }

.csg-more-filters { position: relative; z-index: 5; margin: 0; color: var(--cm-int-text-subtle); font-size: 13px; }
.csg-more-filters > summary { list-style: none; cursor: pointer; }
.csg-more-filters > summary::-webkit-details-marker { display: none; }
.csg-filter-trigger { min-height: 36px; display: inline-flex; align-items: center; padding: 6px 12px; border: 1px solid var(--cm-int-divider); border-radius: var(--cm-int-radius-md); color: var(--cm-int-text-subtle); white-space: nowrap; }
.csg-filter-trigger::after { content: " +"; margin-left: 4px; color: var(--cm-int-accent-hover); }
.csg-more-filters[open] .csg-filter-trigger { border-color: var(--cm-int-accent); color: var(--cm-int-text); }
.csg-more-filters[open] .csg-filter-trigger::after { content: " −"; }
.csg-more-filters-body { position: absolute; top: calc(100% + 8px); right: 0; width: min(680px, calc(100vw - 260px)); padding: 14px; border: 1px solid var(--cm-int-divider); border-radius: var(--cm-int-radius-md); background: var(--cm-int-surface); box-shadow: var(--cm-int-shadow); }
.csg-filter-row { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.csg-filter-row label { display: grid; gap: 5px; color: var(--cm-int-text-muted); font-size: 12px; }
.csg-filter-row select { min-width: 150px; min-height: 36px; padding: 6px 30px 6px 9px; border: 1px solid var(--cm-int-divider); border-radius: var(--cm-int-radius-md); background: var(--cm-int-bg); color: var(--cm-int-text); }
.csg-filter-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }

.csg-workspace { display: grid; grid-template-columns: minmax(430px, 1.35fr) minmax(300px, 1fr); gap: 16px; align-items: stretch; min-height: 480px; }
.csg-list-panel { min-width: 0; display: flex; flex-direction: column; border: 1px solid var(--cm-int-divider); border-radius: var(--cm-int-radius-md); overflow: hidden; }
.csg-table-wrap { min-width: 0; overflow: auto; }
.csg-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.csg-table th { height: 34px; padding: 7px 10px; border-bottom: 1px solid var(--cm-int-divider); color: var(--cm-int-text-muted); font-size: 11px; font-weight: 600; letter-spacing: 0.07em; text-align: left; text-transform: uppercase; }
.csg-table th:nth-child(1) { width: 60%; }
.csg-table th:nth-child(2) { width: 25%; }
.csg-table th:nth-child(3) { width: 82px; }
.csg-style-row { cursor: pointer; }
.csg-style-row td { height: 38px; padding: 5px 10px; border-bottom: 1px solid rgba(233, 233, 237, 0.06); color: var(--cm-int-text-subtle); font-size: 13.5px; vertical-align: middle; }
.csg-style-row:hover { background: rgba(233, 233, 237, 0.04); }
.csg-style-row.selected { background: var(--cm-int-surface-selected); }
.csg-style-name { display: block; color: var(--cm-int-text); font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csg-default-label { margin-left: 7px; color: var(--cm-int-accent-hover); font-size: 11px; font-weight: 500; }
.csg-save-btn { min-width: 62px; min-height: 28px; padding: 4px 10px; border: 1px solid var(--cm-int-divider); border-radius: 999px; background: transparent; color: var(--cm-int-text); font-size: 12px; cursor: pointer; white-space: nowrap; }
.csg-save-btn:hover { border-color: var(--cm-int-accent); color: var(--cm-int-accent-hover); }
.csg-save-btn.saved { border-color: transparent; background: #5d5294; color: #f5f4ff; }
.csg-list-footer { min-height: 48px; margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 12px; border-top: 1px solid var(--cm-int-divider); color: var(--cm-int-text-muted); font-size: 13px; }
.csg-pagination { display: flex; align-items: center; gap: 6px; }
.csg-page-btn { min-width: 34px; min-height: 34px; padding: 4px 8px; border: 0; border-radius: var(--cm-int-radius-sm); background: transparent; color: var(--cm-int-text-subtle); font-size: 13px; cursor: pointer; }
.csg-page-btn:hover { background: rgba(233, 233, 237, 0.07); }
.csg-page-btn.active { background: var(--cm-int-accent-soft); color: var(--cm-int-accent-ink); }
.csg-page-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.csg-page-ellipsis { color: var(--cm-int-text-muted); }

.csg-detail { min-width: 0; display: flex; flex-direction: column; padding: 20px 22px; border-radius: var(--cm-int-radius-md); background: var(--cm-int-surface); }
.csg-detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.csg-detail-head h3 { margin: 0; color: var(--cm-int-text); font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.csg-preview-meta { margin-top: 6px; color: var(--cm-int-text-muted); font-size: 12.5px; }
.csg-preview-close { min-height: 32px; padding: 4px 6px; font-size: 12px; }
.csg-preview-body { flex: 1 1 auto; display: grid; align-content: start; gap: 18px; padding: 20px 0; }
.csg-sample { display: grid; grid-template-columns: 78px minmax(0, 1fr); gap: 8px 12px; }
.csg-sample h4 { grid-column: 1 / -1; margin: 0 0 2px; color: var(--cm-int-text-muted); font-size: 11.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.csg-sample-label { color: var(--cm-int-text-muted); font-size: 12.5px; }
.csg-sample-output { min-width: 0; margin: 0; color: var(--cm-int-text); font: 400 13.5px/1.65 var(--cm-int-font); overflow-wrap: anywhere; }
.csg-sample-list { display: grid; gap: 10px; }
.csg-info-grid { grid-column: 1 / -1; display: grid; grid-template-columns: 94px minmax(0, 1fr); gap: 6px 12px; margin: 0; }
.csg-info-grid dt { color: var(--cm-int-text-muted); font-size: 12.5px; }
.csg-info-grid dd { min-width: 0; margin: 0; color: var(--cm-int-text-subtle); font-size: 13.5px; overflow-wrap: anywhere; }
.csg-detail-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding-top: 14px; border-top: 1px solid var(--cm-int-divider); }
.csg-empty { padding: 36px 18px; color: var(--cm-int-text-muted); font-size: 14px; line-height: 1.6; text-align: center; }

.csg-import-dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: min(820px, calc(100vh - 32px));
  padding: 0;
  border: 1px solid var(--cm-int-divider-strong);
  border-radius: var(--cm-int-radius-lg);
  background: var(--cm-int-surface);
  color: var(--cm-int-text);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.52);
  overflow: auto;
}
.csg-import-dialog::backdrop { background: rgba(7, 8, 15, 0.76); backdrop-filter: blur(3px); }
.csg-import-panel { padding: 24px; }
.csg-import-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.csg-import-head h2 { margin: 0; font-size: 21px; line-height: 1.25; letter-spacing: -0.015em; }
.csg-import-head p { max-width: 500px; margin: 7px 0 0; color: var(--cm-int-text-subtle); font-size: 14px; line-height: 1.55; }
.csg-import-close { flex: 0 0 auto; min-height: 32px; padding: 4px 6px; font-size: 12px; }
.csg-drop-zone {
  min-height: 184px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  border: 1px dashed var(--cm-int-divider-strong);
  border-radius: var(--cm-int-radius-md);
  background: var(--cm-int-bg);
  color: var(--cm-int-text-subtle);
  text-align: center;
  cursor: pointer;
}
.csg-drop-zone:hover, .csg-drop-zone.is-dragover { border-color: var(--cm-int-accent); background: rgba(145, 132, 217, 0.08); }
.csg-drop-zone:focus-visible { outline: 2px solid var(--cm-int-accent); outline-offset: 3px; }
.csg-drop-zone strong { color: var(--cm-int-text); font-size: 17px; font-weight: 600; }
.csg-drop-zone > span { font-size: 13px; }
.csg-drop-action { margin-top: 4px; padding: 7px 12px; border: 1px solid var(--cm-int-accent); border-radius: var(--cm-int-radius-md); color: var(--cm-int-accent-hover); font-weight: 500; }
.csg-import-file-name { color: var(--cm-int-text-muted); overflow-wrap: anywhere; }
.csg-import-file-name.has-file { color: var(--cm-int-success); }
.csg-import-status { min-height: 24px; padding-top: 8px; color: var(--cm-int-text-muted); font-size: 13px; }
.csg-import-status.err { color: var(--cm-int-danger); }
.csg-import-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 4px 0 20px; }
.csg-csl-help { padding-top: 20px; border-top: 1px solid var(--cm-int-divider); }
.csg-csl-help h3 { margin: 0; font-size: 16px; }
.csg-csl-help p, .csg-csl-help ol { color: var(--cm-int-text-subtle); font-size: 13.5px; line-height: 1.6; }
.csg-csl-help p { margin: 8px 0; }
.csg-csl-help ol { margin: 8px 0 16px; padding-left: 20px; }
.csg-csl-help .csg-btn { width: max-content; }

@media (min-width: 1600px) {
  .csg-main { font-size: 16px; }
  .csg-head { min-height: 68px; padding-inline: 28px; }
  .csg-head h1 { font-size: 22px; }
  .csg-scroll-region { padding: 24px 28px 44px; }
  .csg-btn { min-height: 40px; padding-inline: 14px; font-size: 15px; }
  .csg-my-section h2, .csg-browse-section > h2 { font-size: 16px; }
  .csg-status, .csg-more-filters { font-size: 14px; }
  .csg-my-card { width: min(240px, 100%); min-height: 82px; padding: 10px 15px; }
  .csg-my-card-title { font-size: 15.5px; }
  .csg-remove-btn, .csg-tag { font-size: 12.5px; }
  .csg-searchbar { max-width: 480px; }
  .csg-searchbar input, .csg-mode-tab { height: 40px; font-size: 15px; }
  .csg-workspace { min-height: 520px; gap: 18px; }
  .csg-table th { height: 38px; font-size: 12px; }
  .csg-style-row td { height: 42px; font-size: 14.5px; }
  .csg-style-name { font-size: 15px; }
  .csg-save-btn { min-height: 30px; font-size: 12.5px; }
  .csg-list-footer { min-height: 52px; font-size: 14px; }
  .csg-detail { padding: 24px 26px; }
  .csg-detail-head h3 { font-size: 19px; }
  .csg-preview-meta, .csg-sample-label, .csg-info-grid dt { font-size: 13px; }
  .csg-sample-output, .csg-info-grid dd { font-size: 14px; }
  .csg-empty { font-size: 15px; }
}

@media (max-width: 1080px) {
  .csg-workspace { grid-template-columns: minmax(360px, 1fr) minmax(280px, 0.85fr); }
  .csg-head-actions .csg-btn-quiet { display: none; }
}

@media (max-width: 860px) {
  body { overflow: auto; }
  .csg-main { height: auto; min-height: 100vh; }
  .csg-scroll-region { overflow: visible; }
  .csg-browse-toolbar { flex-wrap: wrap; }
  .csg-searchbar { max-width: none; }
  .csg-mode-tabs { max-width: 100%; overflow-x: auto; }
  .csg-workspace { grid-template-columns: 1fr; }
  .csg-detail { min-height: 420px; }
}

@media (max-width: 720px) {
  .csg-head { min-height: 58px; padding: 10px 16px; }
  .csg-head h1 { font-size: 20px; }
  .csg-scroll-region { padding: 18px 16px 32px; }
  .csg-head-actions .csg-btn-secondary { min-height: 44px; }
  .csg-my-card { width: 100%; min-height: 92px; }
  .csg-remove-btn { min-height: 44px; padding-inline: 8px; }
  .csg-browse-toolbar { display: grid; grid-template-columns: 1fr; }
  .csg-searchbar { min-width: 0; }
  .csg-searchbar input, .csg-mode-tab, .csg-filter-row select, .csg-filter-row .csg-btn { min-height: 44px; }
  .csg-filter-row { display: grid; grid-template-columns: 1fr; }
  .csg-filter-row label, .csg-filter-row select { width: 100%; }
  .csg-more-filters-body { position: static; width: 100%; margin-top: 8px; box-shadow: none; }
  .csg-filter-trigger { width: 100%; min-height: 44px; justify-content: space-between; }
  .csg-filter-actions { width: 100%; margin-left: 0; }
  .csg-filter-actions .csg-btn { flex: 1 1 auto; }
  .csg-table th:nth-child(1) { width: 58%; }
  .csg-table th:nth-child(2) { width: 24%; }
  .csg-table th:nth-child(3) { width: 74px; }
  .csg-style-row td { height: 44px; }
  .csg-detail-actions { align-items: stretch; flex-direction: column; }
  .csg-detail-actions .csg-btn { min-height: 44px; width: 100%; }
  .csg-import-dialog { width: calc(100vw - 24px); max-height: calc(100vh - 24px); }
  .csg-import-panel { padding: 20px; }
  .csg-drop-zone { min-height: 170px; }
}

@media (max-width: 480px) {
  .csg-head { align-items: flex-start; }
  .csg-head-actions { margin-left: auto; }
  .csg-head-actions .csg-btn-secondary { max-width: 165px; padding-inline: 10px; }
  .csg-mode-tab { padding-inline: 10px; }
  .csg-table th:nth-child(2), .csg-style-row td:nth-child(2) { display: none; }
  .csg-table th:nth-child(1) { width: auto; }
  .csg-table th:nth-child(3) { width: 76px; }
  .csg-sample { grid-template-columns: 64px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .csg-main * { scroll-behavior: auto !important; transition-duration: 1ms !important; }
}
