:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
    sans-serif;
  --ink: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --backdrop: #f6f8fb;
  --primary: #0369a1;
  --primary-dark: #075985;
  --primary-soft: #e0f2fe;
  --accent: #059669;
  --accent-soft: #ecfdf5;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --success: #147d4f;
  --success-bg: #ecfdf3;
  --warning: #946200;
  --warning-bg: #fff7df;
  --info-bg: #eff6ff;
  --shadow-sm: 0 1px 2px rgb(15 23 42 / 6%);
  --shadow-md: 0 10px 30px rgb(15 23 42 / 8%);
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--backdrop);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

button,
.button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 36px;
  padding: 0 13px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: normal;
  line-height: 1.2;
  gap: 6px;
  font-size: 14px;
  font-weight: 650;
  transition:
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease;
}

button:hover,
.button:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}

button.primary,
.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

button.primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

button.ghost {
  background: transparent;
}

button.danger {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #fecaca;
}

button:disabled,
button:disabled:hover {
  cursor: not-allowed;
  opacity: 0.48;
  border-color: var(--line);
}

button.active,
.campaign-row.active {
  border-color: var(--primary);
  color: var(--primary-dark);
  background: var(--primary-soft);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 9px 11px;
  background: white;
  color: var(--ink);
  min-height: 38px;
  line-height: 1.4;
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    background-color 180ms ease;
}

input:focus,
textarea:focus,
button:focus-visible,
.button:focus-visible {
  outline: 3px solid rgb(15 118 110 / 20%);
  outline-offset: 2px;
  border-color: var(--primary);
}

textarea {
  resize: vertical;
}

input:disabled,
textarea:disabled {
  background: var(--surface-soft);
  color: #475569;
  cursor: not-allowed;
}

input[type="file"] {
  padding: 8px;
}

.attachment-upload-button {
  position: relative;
  overflow: hidden;
}

.attachment-upload-button input {
  inset: 0;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

.attachment-upload-button span {
  color: inherit;
  font-size: inherit;
  margin: 0;
}

.attachment-upload-button.disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

label span,
.editor-field > span,
.hint {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.panel-copy {
  color: var(--muted);
  margin: 8px 0 18px;
  line-height: 1.5;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: var(--surface-soft);
  position: sticky;
  top: 0;
  z-index: 1;
}

.shell,
.login-view,
.app-view {
  min-height: 100vh;
}

.login-view {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.login-panel h1,
.sidebar h1,
.topbar h2 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-view {
  display: grid;
  grid-template-columns: 240px 1fr;
}

.sidebar {
  background: #0f172a;
  border-right: 0;
  color: #e2e8f0;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 100vh;
  position: sticky;
  top: 0;
  z-index: 6;
}

.sidebar p {
  color: #94a3b8;
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.4;
}

.sidebar .eyebrow {
  color: #67e8f9;
}

.sidebar h1 {
  color: #ffffff;
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.sidebar nav button {
  justify-content: flex-start;
  background: transparent;
  border-color: transparent;
  color: #cbd5e1;
}

.sidebar nav button:hover,
.sidebar button.ghost:hover {
  background: #1e293b;
  border-color: #334155;
  box-shadow: none;
  color: #ffffff;
}

.sidebar nav button.active {
  background: #0e7490;
  border-color: #0891b2;
  box-shadow: inset 3px 0 0 #67e8f9;
  color: #ffffff;
}

.sidebar button.ghost {
  border-color: #334155;
  color: #cbd5e1;
  margin-top: auto;
}

.content {
  min-width: 0;
}

.topbar {
  height: 74px;
  background: rgb(255 255 255 / 94%);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 4;
}

.topbar h2 {
  font-size: 22px;
  line-height: 1.2;
}

.user-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  padding: 8px 12px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.workspace {
  padding: 22px 24px 28px;
  display: grid;
  gap: 16px;
  max-width: 1440px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  min-width: 0;
  box-shadow: var(--shadow-sm);
}

.panel h3 {
  font-size: 17px;
  line-height: 1.25;
  margin: 0 0 14px;
}

.grid {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.7fr);
}

.members-layout {
  grid-template-columns: minmax(0, 1.55fr) minmax(340px, 430px);
}

.members-layout > .panel {
  align-self: start;
}

.import-layout {
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
}

.schedule-layout {
  grid-template-columns: 1fr;
}

.recipient-import-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(280px, 0.65fr);
  gap: 18px;
  align-items: start;
  min-width: 0;
}

.recipient-csv-field textarea {
  min-height: 280px;
}

.recipient-import-actions,
.recipient-validation {
  grid-column: 1 / -1;
}

.schedule-page-grid {
  grid-template-columns: minmax(0, 1fr);
}

.schedule-page-grid .preview iframe {
  min-height: 360px;
}

.stack {
  display: grid;
  gap: 14px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  min-width: 0;
}

.surface-toolbar {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 0;
  box-shadow: var(--shadow-sm);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 3px;
  min-height: 92px;
  padding: 14px;
}

.summary-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-card strong {
  color: var(--ink);
  font-size: 28px;
  line-height: 1.05;
}

.summary-card small {
  color: var(--muted);
  font-size: 12px;
}

.search-field {
  width: min(420px, 100%);
}

.toolbar.tight {
  margin-bottom: 0;
}

.search {
  max-width: 100%;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  max-width: 100%;
  background: #ffffff;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 70%);
}

tbody tr {
  transition: background-color 160ms ease;
}

tbody tr:hover {
  background: #f8fafc;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.actions.wrap {
  flex-wrap: wrap;
}

.attachment-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 14px;
}

.attachment-section .section-header.compact {
  margin-bottom: 0;
}

.attachment-section h3 {
  font-size: 15px;
}

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

.attachment-item {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 10px 12px;
  min-width: 0;
}

.attachment-item strong,
.attachment-item span {
  display: block;
}

.attachment-item strong {
  overflow-wrap: anywhere;
}

.attachment-item span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.full-width {
  width: 100%;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.section-header.compact {
  margin-bottom: 18px;
}

.section-header h3 {
  margin: 0 0 4px;
}

.section-header p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.section-header > button,
.section-header > .button {
  flex-shrink: 0;
  min-width: 150px;
  white-space: nowrap;
}

.sticky-panel {
  align-self: start;
  position: sticky;
  top: 110px;
}

.result {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 6px;
  padding: 12px;
  min-height: 120px;
  overflow: auto;
}

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

.campaign-list.spacious {
  gap: 12px;
}

.campaign-row {
  height: auto;
  align-items: flex-start;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
}

.campaign-row small {
  color: var(--muted);
}

.campaign-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, auto);
  gap: 16px;
  align-items: center;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.campaign-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
}

.campaign-card::before {
  background: var(--primary);
  border-radius: 999px;
  bottom: 14px;
  content: "";
  left: 0;
  position: absolute;
  top: 14px;
  width: 4px;
}

.campaign-card[data-status="draft"]::before {
  background: var(--primary);
}

.campaign-card[data-status="scheduled"]::before,
.campaign-card[data-status="sending"]::before {
  background: #d97706;
}

.campaign-card[data-status="sent"]::before {
  background: var(--accent);
}

.campaign-card[data-status="failed"],
.campaign-card[data-status="canceled"] {
  background: #fffafa;
}

.campaign-card[data-status="failed"]::before,
.campaign-card[data-status="canceled"]::before {
  background: var(--danger);
}

.card-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.campaign-card h4 {
  margin: 0;
}

.campaign-card p {
  margin: 0 0 6px;
  color: var(--muted);
}

.campaign-card small,
.mini-list small {
  color: var(--muted);
}

.card-actions {
  justify-content: flex-end;
}

.card-actions button {
  min-height: 34px;
}

.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.metrics span {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #475569;
  font-size: 12px;
  padding: 4px 8px;
}

.badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #475569;
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 8px;
  text-transform: capitalize;
  white-space: nowrap;
}

.badge-success {
  background: var(--success-bg);
  border-color: #b7ebc6;
  color: var(--success);
}

.badge-warning {
  background: var(--warning-bg);
  border-color: #ffe3a3;
  color: var(--warning);
}

.badge-danger {
  background: var(--danger-bg);
  border-color: #ffc9c5;
  color: var(--danger);
}

.badge-info {
  background: var(--info-bg);
  border-color: #bfdbfe;
  color: #1d4ed8;
}

.stepper {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.stepper button {
  flex: 1 1 170px;
  min-height: 42px;
}

.stepper button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 390px);
  gap: 18px;
  min-width: 0;
}

.help-panel {
  align-self: start;
}

.placeholder-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

code {
  background: #eef2f7;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: #334155;
  padding: 2px 6px;
}

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

.mini-list > div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  display: grid;
  gap: 3px;
}

.schedule-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
  display: grid;
  gap: 12px;
  align-self: start;
}

.validation-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 14px;
}

.validation-card strong {
  display: block;
  margin-bottom: 4px;
}

.validation-card p {
  color: var(--muted);
  margin: 0;
}

.validation-card ul {
  margin: 10px 0 0;
  padding-left: 18px;
}

.validation-card li {
  margin: 4px 0;
}

.validation-ok {
  background: var(--success-bg);
  border-color: #b7ebc6;
}

.validation-error {
  background: var(--danger-bg);
  border-color: #ffc9c5;
}

.callout {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  padding: 12px;
}

.lock-callout {
  margin-bottom: 18px;
}

.callout span {
  color: var(--muted);
  line-height: 1.45;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.status-grid > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.status-grid strong {
  display: block;
  font-size: 28px;
}

.status-grid span {
  color: var(--muted);
}

.status-section {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding-top: 18px;
}

.failed-recipient-table table {
  min-width: 900px;
}

.reason-cell {
  max-width: 460px;
  overflow-wrap: anywhere;
}

.empty {
  color: var(--muted);
  margin: 0;
}

.table-empty {
  padding: 12px;
}

.empty-state {
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  gap: 4px;
  padding: 18px;
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

.field-note {
  color: var(--muted);
  display: inline-block;
  font-size: 12px;
  margin-top: 6px;
}

.editor-field {
  display: grid;
  gap: 8px;
}

.editor-toolbar {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 6px 6px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
}

.editor-toolbar button {
  min-width: 36px;
  padding: 0 10px;
}

.editor-format {
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 36px;
  padding: 0 10px;
}

.rich-editor {
  background: white;
  border: 1px solid var(--line);
  border-radius: 0 0 6px 6px;
  min-height: 260px;
  outline: none;
  overflow-wrap: anywhere;
  overflow-y: auto;
  padding: 14px;
}

.rich-editor:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(3 105 161 / 12%);
}

.rich-editor img {
  display: block;
  height: auto;
  margin: 10px 0;
  max-width: 100%;
}

.editor-actions {
  display: flex;
  justify-content: flex-end;
}

.editor-image-input {
  height: 1px;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  width: 1px;
}

.read-only-editor .rich-editor {
  background: var(--surface-soft);
  border-radius: 6px;
  color: #475569;
}

.preview iframe {
  width: 100%;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #17202a;
  color: white;
  padding: 12px 14px;
  border-radius: 6px;
  box-shadow: 0 12px 40px rgb(15 23 42 / 20%);
}

[x-cloak],
[x-show="false"] {
  display: none !important;
}

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

  .sidebar {
    min-height: auto;
    position: sticky;
    top: 0;
    z-index: 5;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    gap: 12px;
    padding: 14px 16px;
  }

  .sidebar > div p:not(.eyebrow) {
    display: none;
  }

  .sidebar nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .sidebar button.ghost {
    margin-top: 0;
  }

  .topbar {
    backdrop-filter: none;
    position: static;
  }

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

  .grid.two {
    grid-template-columns: 1fr;
  }

  .members-layout,
  .import-layout,
  .recipient-import-layout,
  .schedule-layout {
    grid-template-columns: 1fr;
  }

  .page-grid,
  .campaign-card {
    grid-template-columns: 1fr;
  }

  .topbar {
    height: auto;
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .sidebar,
  .topbar,
  .workspace {
    padding: 16px;
  }

  .section-header {
    flex-direction: column;
  }

  .section-header .actions,
  .section-header button,
  .section-header .button {
    width: 100%;
  }

  .section-header .actions.wrap {
    display: grid;
    grid-template-columns: 1fr;
  }

  .section-header .actions.wrap > button,
  .section-header .actions.wrap > .button {
    flex: none;
    width: 100%;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .actions.wrap > button,
  .actions.wrap > .button {
    flex: 1 1 180px;
  }
}
