:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f7fb;
  color: #151923;
  --sidebar: #101624;
  --sidebar-soft: #172033;
  --border: #dfe5ee;
  --muted: #657386;
  --panel: #ffffff;
  --input: #f8fafc;
  --text: #151923;
  --x: #2f6fed;
  --instagram: #d9468f;
  --line: #20b45b;
  --media: #0ea5b7;
  --accent: var(--x);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f5f7fb;
}

body[data-module="x"] { --accent: var(--x); }
body[data-module="instagram"] { --accent: var(--instagram); }
body[data-module="line"] { --accent: var(--line); }
body[data-module="media"] { --accent: var(--media); }

h1, h2, p {
  margin: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  padding: 18px 14px;
  overflow: auto;
  background: var(--sidebar);
  color: #edf3fb;
}

.module-switcher {
  position: relative;
}

.module-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid #263249;
  border-radius: 8px;
  color: #f8fbff;
  background: #0c1321;
  text-align: left;
}

.module-button small {
  display: block;
  margin-top: 2px;
  color: #97a6ba;
  font-size: 12px;
}

.module-badge {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.module-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid #263249;
  border-radius: 8px;
  background: #0c1321;
  box-shadow: 0 20px 40px rgba(4, 7, 14, 0.35);
}

.module-menu button,
.feature-nav button {
  width: 100%;
  border: 0;
  color: #d8e1ec;
  background: transparent;
  text-align: left;
}

.module-menu button {
  padding: 10px;
  border-radius: 6px;
}

.module-menu button:hover,
.feature-nav button:hover {
  background: #1d2940;
}

.feature-nav {
  display: grid;
  align-content: start;
  gap: 6px;
}

.nav-group-title {
  margin: 14px 10px 4px;
  color: #75849a;
  font-size: 12px;
  font-weight: 800;
}

.feature-nav button {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  min-height: 42px;
  padding: 9px 10px;
  border-radius: 8px;
  font-weight: 700;
}

.feature-nav button.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 72%, #111827));
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
}

.sidebar-status {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #263249;
  border-radius: 8px;
  background: var(--sidebar-soft);
}

.sidebar-status p {
  color: #97a6ba;
  font-size: 12px;
  font-weight: 800;
}

.sidebar-status span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #cbd5e1;
}

.status-list {
  display: grid;
  gap: 8px;
}

.status-row {
  align-items: start;
}

.status-row span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.status-row small {
  color: #97a6ba;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-row strong {
  flex: 0 0 auto;
  color: #f8fbff;
  font-size: 12px;
}

.status-row.ok strong {
  color: #86efac;
}

.status-row.ng strong {
  color: #fca5a5;
}

.workspace {
  min-width: 0;
  padding: 30px clamp(18px, 3vw, 44px) 56px;
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.workspace-header h1 {
  margin-top: 4px;
  font-size: clamp(26px, 3vw, 38px);
  letter-spacing: 0;
}

.lead {
  margin-top: 8px;
  color: var(--muted);
}

.eyebrow, article span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.module-dashboard,
.feature-section {
  display: none;
}

.module-dashboard.active,
.feature-section.active {
  display: block;
}

.dashboard-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 168px;
  padding: 24px;
  border: 1px solid color-mix(in srgb, var(--accent) 26%, #dfe5ee);
  border-radius: 8px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 13%, #fff), #fff 58%),
    #fff;
  box-shadow: 0 16px 40px rgba(33, 43, 62, 0.08);
}

.dashboard-hero h2 {
  margin-top: 6px;
  font-size: clamp(24px, 3vw, 34px);
}

.dashboard-hero p:not(.eyebrow) {
  margin-top: 10px;
  max-width: 720px;
  color: #48566a;
  line-height: 1.7;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 10px;
  min-width: 280px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

article, .panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 18px;
  box-shadow: 0 12px 28px rgba(33, 43, 62, 0.05);
}

article strong {
  display: block;
  margin-top: 10px;
  color: var(--text);
  font-size: 30px;
  line-height: 1;
}

.panel {
  margin-top: 0;
}

.panel-title-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.form {
  display: flex;
  gap: 10px;
  margin: 14px 0;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.mode-option {
  display: grid;
  gap: 4px;
  min-height: 72px;
  padding: 12px;
  color: #2d3645;
  background: #eef3f8;
  text-align: left;
}

.mode-option.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.mode-option span {
  font-size: 13px;
  font-weight: 600;
  opacity: 0.82;
}

.source-media-row {
  display: none;
}

body[data-generate-mode="image_video"] .source-media-row {
  display: grid;
}

.video-duration-row,
.video-voice-row,
.video-dialogue-row {
  display: none;
}

body[data-generate-mode="text_video"] .video-duration-row,
body[data-generate-mode="image_video"] .video-duration-row,
body[data-generate-mode="text_video"] .video-voice-row,
body[data-generate-mode="image_video"] .video-voice-row,
body[data-generate-mode="text_video"] .video-dialogue-row,
body[data-generate-mode="image_video"] .video-dialogue-row {
  display: grid;
}

.source-media-box {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input);
}

.source-media-box span {
  flex: 1;
  min-width: 180px;
  color: #2d3645;
  word-break: break-word;
}

input, button, textarea, select {
  border: 1px solid #cfd8e4;
  border-radius: 6px;
  font: inherit;
}

input, select, textarea {
  flex: 1;
  min-width: 0;
  padding: 12px;
  color: var(--text);
  background: var(--input);
}

.compact-select {
  flex: 0 1 220px;
  padding: 10px;
}

textarea {
  min-height: 150px;
  resize: vertical;
  line-height: 1.7;
}

button {
  padding: 12px 16px;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

button.secondary {
  color: #263244;
  background: #eef3f8;
  border-color: #cfd8e4;
}

button.danger {
  color: #fff4f4;
  background: #c24141;
  border-color: #c24141;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  padding: 12px 16px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.button-link.secondary {
  color: #263244;
  background: #eef3f8;
  border-color: #cfd8e4;
}

pre {
  white-space: pre-wrap;
  min-height: 120px;
  margin: 0;
  padding: 14px;
  border-radius: 6px;
  background: #111827;
  color: #dbe6ef;
  line-height: 1.7;
}

.history {
  display: grid;
  gap: 10px;
}

.history div {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  background: var(--input);
}

.history p {
  margin-top: 6px;
  color: #526173;
}

.login-page {
  display: grid;
  place-items: center;
  background: #0f1215;
  color: #f4f7fb;
}

.login-box {
  width: min(420px, calc(100% - 32px));
  border: 1px solid #27303a;
  border-radius: 8px;
  padding: 24px;
  background: #171b21;
}

form, label {
  display: grid;
  gap: 10px;
}

form {
  margin-top: 18px;
}

label {
  color: #536174;
  font-weight: 700;
}

.error {
  margin-top: 12px;
  color: #ff9a9a;
}

.persona-form {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: end;
}

.persona-form .actions {
  grid-column: 1 / -1;
  justify-content: flex-start;
}

.persona-form .wide {
  grid-column: 1 / -1;
}

.compact-hidden {
  display: none;
}

.persona-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.persona-card {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.persona-card span {
  display: inline-block;
  margin-left: 8px;
  color: var(--accent);
  font-weight: 800;
}

.persona-card p {
  margin-top: 6px;
  color: #526173;
}

.media-results {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.media-results img,
.media-results video {
  width: 120px;
  height: 120px;
  border: 1px solid var(--border);
  border-radius: 6px;
  object-fit: cover;
  background: #eef3f8;
}

.media-results a {
  display: inline-flex;
  max-width: 140px;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  text-decoration: none;
}

.draft-media {
  margin-top: 10px;
}

.draft-media img, .draft-media video {
  width: min(220px, 100%);
  max-height: 180px;
  border: 1px solid var(--border);
  border-radius: 6px;
  object-fit: cover;
  background: #eef3f8;
}

.media-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  margin-top: 16px;
  min-width: 0;
}

.media-gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7faff;
}

.media-gallery-toolbar span {
  color: #263244;
  font-weight: 800;
}

.media-gallery-toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.media-gallery-toolbar-actions button {
  padding: 9px 12px;
}

.media-card {
  display: grid;
  grid-template-rows: auto auto minmax(104px, auto) auto;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.media-card-check {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-width: 0;
  color: #263244;
  font-size: 13px;
  font-weight: 800;
}

.media-card-check input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
}

.media-preview {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #eef3f8;
  color: #526173;
  text-decoration: none;
}

.media-preview img, .media-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-preview {
  padding: 12px;
  text-align: center;
  word-break: break-word;
}

.media-card-body {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.media-card-body span {
  color: var(--accent);
  font-weight: 800;
}

.media-card-body b,
.media-card-body span,
.media-card-body p {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-card-body p {
  color: #526173;
}

.media-card-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: stretch;
  min-width: 0;
}

.media-card-actions .button-link,
.media-card-actions button,
.media-card-actions select {
  width: 100%;
  min-width: 0;
}

.media-card-actions .media-card-select {
  grid-column: 1 / -1;
}

.media-card-actions [data-gallery-attach] {
  grid-column: 1 / -1;
}

.available-loras {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdff;
}

#loraAvailableList {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-height: 180px;
  overflow: auto;
}

.tag-button {
  padding: 8px 10px;
  color: #263244;
  background: #eef3f8;
  border-color: #cfd8e4;
  font-size: 13px;
  font-weight: 700;
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    z-index: 30;
    height: auto;
    max-height: 78vh;
    grid-template-rows: auto auto auto;
    gap: 10px;
    border-bottom: 1px solid #263249;
  }

  .feature-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sidebar-status {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sidebar-status p {
    grid-column: 1 / -1;
  }

  .status-list {
    grid-column: 1 / -1;
  }

  .workspace {
    padding: 20px 14px 40px;
  }

  .workspace-header,
  .dashboard-hero,
  .form,
  .persona-card,
  .panel-title-row {
    flex-direction: column;
    align-items: stretch;
  }

  .workspace-header,
  .dashboard-hero {
    display: grid;
    grid-template-columns: 1fr;
  }

  .quick-actions,
  .metric-grid,
  .mode-switch {
    grid-template-columns: 1fr;
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .feature-nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .feature-nav button {
    grid-template-columns: 24px max-content;
    flex: 0 0 auto;
    width: auto;
    min-width: 128px;
  }

  .sidebar-status {
    display: none;
  }

  .actions,
  .form {
    display: grid;
  }

  button,
  .button-link {
    width: 100%;
  }
}
