* {
  box-sizing: border-box;
}

:root {
  --brand-50: #eef4ff;
  --brand-100: #dbe7ff;
  --brand-500: #3b82f6;
  --brand-600: #2563eb;
  --brand-700: #1d4ed8;
  --ink-900: #0f172a;
  --ink-800: #1e293b;
  --ink-600: #475569;
  --ink-500: #64748b;
  --line-200: #e2e8f0;
  --line-300: #cbd5e1;
  --bg-soft: #f3f7ff;
  --surface: #ffffff;
  --surface-muted: #f8fbff;
  --shadow-soft: 0 14px 34px rgba(15, 23, 42, 0.08);
  --shadow-strong: 0 20px 44px rgba(15, 23, 42, 0.14);
  --radius-xl: 16px;
  --radius-lg: 12px;
  --radius-md: 10px;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: radial-gradient(circle at 2% -8%, #dfeeff 0, rgba(223, 238, 255, 0) 48%),
    radial-gradient(circle at 100% 0%, #efe6ff 0, rgba(239, 230, 255, 0) 38%), var(--bg-soft);
  color: var(--ink-800);
}

.app-container {
  min-height: 100vh;
  background: transparent;
}

.hidden {
  display: none !important;
}

.card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
}

.login-card {
  width: min(430px, 100%);
  padding: 30px 26px;
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.65);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(3px);
}

.login-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(520px, 0.82fr);
  background: transparent;
}

.login-visual {
  position: relative;
  background: url("/images/bg.png") center center / cover no-repeat;
}

.login-visual-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(12, 30, 57, 0.45), rgba(13, 110, 253, 0.15));
}

.login-visual-caption {
  position: absolute;
  left: 52px;
  bottom: 54px;
  z-index: 2;
  color: #fff;
}

.visual-brand {
  font-size: 34px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.visual-sub {
  margin-top: 8px;
  font-size: 15px;
  opacity: 0.9;
}

.login-side {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 44px 56px;
  background: transparent;
}

.login-kicker {
  margin: 0 0 10px;
  color: #64748b;
  font-size: 12px;
  letter-spacing: 0.12em;
  font-weight: 700;
}

.login-title {
  margin: 0 0 10px;
  font-size: 34px;
  font-weight: 700;
  color: #111827;
}

.login-card .sub {
  margin-bottom: 20px;
}

#login-form .form-label {
  margin: 0 0 8px;
  color: #374151;
  font-weight: 600;
}

#login-form .form-control {
  height: 46px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line-300);
  padding: 10px 12px;
  margin-bottom: 14px;
  background: #fff;
}

#login-form .form-control:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 0.18rem rgba(59, 130, 246, 0.18);
}

#login-form .btn {
  margin-top: 6px;
  height: 46px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
}

h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.sub {
  margin: 0 0 16px;
  color: var(--ink-500);
}

.compact {
  margin-bottom: 8px;
}

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 14px;
  font-weight: 600;
}

input:not(.form-control):not(.form-select),
select:not(.form-control):not(.form-select),
textarea:not(.form-control):not(.form-select) {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
}

input:not(.form-control):not(.form-select):focus,
select:not(.form-control):not(.form-select):focus,
textarea:not(.form-control):not(.form-select):focus {
  outline: 0;
  border-color: #60a5fa;
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.2);
}

input[readonly] {
  background: #f8fafc;
  color: var(--ink-500);
}

button:not(.btn):not(.menu-item):not(.btn-close) {
  margin-top: 14px;
  border: 0;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: #2563eb;
  color: #fff;
}

button.secondary {
  margin-top: 0;
  background: #6b7280;
}

button.danger {
  background: #dc2626;
}

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

.error {
  margin-top: 10px;
  color: #dc2626;
  min-height: 20px;
}

.result {
  margin-top: 14px;
  min-height: 0;
}

.result:empty {
  display: none;
}

.result:not(:empty) {
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  background: #f8fafc;
}

.result.success {
  color: #0f5132;
  border-color: #badbcc;
  background: #d1e7dd;
}

.result.failed {
  color: #842029;
  border-color: #f5c2c7;
  background: #f8d7da;
}

.app-shell {
  min-height: 100vh;
  position: relative;
  z-index: 1;
  background: transparent;
}

.top-nav {
  min-height: 68px;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid rgba(203, 213, 225, 0.78);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 10px 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 1030;
  backdrop-filter: blur(9px);
}

.nav-left,
.nav-right {
  display: flex;
  align-items: center;
}

.nav-right {
  justify-content: flex-end;
  margin-left: auto;
}

.brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--brand-500);
  margin-right: 8px;
  box-shadow: 0 0 0 5px rgba(59, 130, 246, 0.14);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink-900);
}

.nav-center {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 20px;
}

.menu-item {
  margin: 0;
  border: 0;
  background: transparent;
  color: var(--ink-500);
  border-radius: 999px;
  padding: 0.5rem 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  transition: all 0.15s ease-in-out;
}

.menu-item:hover {
  background: #eef2ff;
  color: var(--brand-700);
}

.menu-item.active {
  background: linear-gradient(135deg, var(--brand-600), #5b7cfa);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.24);
}

.menu-item:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.logout-btn {
  margin: 0;
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  font-weight: 600;
}

.content-wrap {
  padding: 24px 28px;
}

.panel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(4px);
}

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

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

.panel-actions button {
  margin-top: 0;
}

.panel-title {
  margin: 0;
  font-size: 20px;
  color: var(--ink-900);
  font-weight: 700;
}

.stack-form {
  margin-bottom: 12px;
}

.mail-form {
  margin-bottom: 12px;
}

.mail-field-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.mail-field-row-multiline {
  align-items: flex-start;
}

.mail-field-row label {
  width: 120px;
  margin: 0;
  flex: 0 0 120px;
}

.mail-field-row input,
.mail-field-row select,
.mail-field-row textarea {
  flex: 1;
}

.mail-recipient-mode-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mail-manual-input-wrap {
  flex: 1;
}

.mail-field-offset {
  margin-left: 134px;
  margin-bottom: 14px;
}

.mail-form-actions {
  justify-content: flex-end;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(200px, 1fr));
  gap: 12px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.form-actions button {
  margin-top: 0;
}

.filter-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.filter-row input {
  max-width: 280px;
}

.filter-row select {
  max-width: 320px;
}

.filter-row button {
  margin-top: 0;
}

#page-recipients .filter-row {
  margin-bottom: 16px;
}

#page-campaigns .filter-row {
  margin-bottom: 16px;
}

#page-recipients .panel-header {
  margin-bottom: 14px;
}

#page-campaigns .panel-header {
  margin-bottom: 14px;
}

#page-recipients .table-wrap {
  margin-top: 16px;
}

#page-campaigns .table-wrap {
  margin-top: 16px;
}

.table-wrap {
  position: relative;
  margin-top: 10px;
  border: 1px solid var(--line-200);
  border-radius: 14px;
  overflow: auto;
  background: var(--surface);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.table-loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 251, 255, 0.8);
  backdrop-filter: blur(1px);
}

.table-loading-content {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line-200);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-600);
  font-size: 13px;
  box-shadow: var(--shadow-soft);
}

.table-loading-content .spinner-border {
  width: 1rem;
  height: 1rem;
}

.data-table {
  width: 100%;
}

.data-table thead th {
  background: var(--surface-muted);
  border-bottom: 1px solid var(--line-200);
  text-align: left;
  padding: 10px 12px;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--ink-500);
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table tbody td {
  border-bottom: 1px solid #edf2f7;
  padding: 10px 12px;
  font-size: 13px;
}

.data-table tbody tr {
  transition: background-color 0.15s ease;
}

.data-table tbody tr:hover {
  background: #f8fbff;
}

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

.row-actions button {
  margin-top: 0;
}

.data-table .row-actions .btn-sm {
  min-height: 31px;
  padding: 0.25rem 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  line-height: 1.5;
  border-radius: 0.25rem;
  white-space: nowrap;
}

.data-table .row-actions .btn-sm.action-locked:disabled {
  opacity: 1;
  border-color: var(--line-300);
  background: #f8fafc;
  color: var(--ink-500);
  box-shadow: none;
  cursor: not-allowed;
}

#page-campaigns .row-actions .btn-sm,
#page-recipients .row-actions .btn-sm,
#page-assets .row-actions .btn-sm {
  min-width: 52px;
}

.asset-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line-200);
  background: #fff;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.1);
}

.asset-url {
  display: inline-block;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-list-wrap {
  margin-top: 0;
  min-height: 520px;
}

.template-editor-wrap,
.template-preview-wrap {
  border: 1px solid var(--line-200);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  overflow: hidden;
}

.template-editor-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.template-editor-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

#template-editor-modal .modal-body {
  padding-top: 12px;
}

.template-editor-modal-dialog {
  max-width: 96vw;
}

.template-editor-header .form-label {
  margin: 0;
  flex: 0 0 auto;
  white-space: nowrap;
}

.template-editor-header .form-control {
  flex: 1;
}

.template-modal-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  height: 70vh;
  min-height: 500px;
}

.template-html-editor {
  flex: 1;
  min-height: 300px;
  height: auto;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 13px;
  resize: none;
}

.template-preview-wrap {
  padding: 0;
  height: 100%;
}

.template-preview-frame {
  width: 100%;
  height: 100%;
  border: 0;
}

.template-asset-drawer {
  width: min(420px, 92vw);
  z-index: 2005;
}

.template-asset-drawer-backdrop {
  z-index: 2000;
}

.template-asset-drawer .offcanvas-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.template-asset-search {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-200);
}

.template-asset-list {
  flex: 1;
  overflow: auto;
  padding: 0 2px;
}

.template-asset-item {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #f1f5f9;
}

.template-asset-item:last-child {
  border-bottom: 0;
}

.template-asset-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line-200);
}

.template-asset-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.template-asset-name {
  font-size: 12px;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.campaign-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.campaign-status.draft {
  color: #6c757d;
}

.campaign-status.completed {
  color: #198754;
}

.campaign-status.processing {
  color: #198754;
}

.campaign-status.failed {
  color: #dc3545;
}

.campaign-status .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 rgba(34, 197, 94, 0.6);
  animation: processing-dot-pulse 1.2s ease-in-out infinite;
}

@keyframes processing-dot-pulse {
  0% {
    transform: scale(0.9);
    opacity: 0.9;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55);
  }
  70% {
    transform: scale(1);
    opacity: 1;
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
  }
  100% {
    transform: scale(0.9);
    opacity: 0.9;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}

.app-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-card {
  width: min(75vw, 1200px);
  height: 75vh;
  max-height: 75vh;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line-200);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-strong);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.modal-header h3 {
  margin: 0;
  font-size: 20px;
}

.modal-header button {
  margin-top: 0;
}

#delete-confirm-modal .btn-close:focus,
#delete-confirm-modal .btn-close:focus-visible {
  box-shadow: none;
  outline: none;
}

.campaign-modal-form,
.recipient-modal-form {
  height: calc(100% - 56px);
  display: flex;
  flex-direction: column;
}

.recipient-modal-grid {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.modal-field-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.modal-field-row-multiline {
  align-items: flex-start;
}

.modal-field-row label {
  width: 92px;
  margin: 0;
  flex: 0 0 92px;
}

.modal-field-row input,
.modal-field-row textarea {
  flex: 1;
}

.modal-field-row select {
  flex: 1;
}

.import-file-wrap {
  flex: 1;
}

.import-file-wrap input[type="file"] {
  width: 100%;
}

.modal-actions {
  margin-top: auto;
  justify-content: flex-end;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 16px;
}

.stat-card {
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  border: 1px solid var(--line-200);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow-soft);
}

.stat-label {
  margin: 0;
  font-size: 15px;
  color: #6b7280;
}

.stat-value {
  margin: 12px 0 0;
  font-size: 40px;
  font-weight: 700;
}

.stat-value em {
  margin-left: 8px;
  font-size: 22px;
  font-style: normal;
  color: #9ca3af;
  font-weight: 500;
}

.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  align-items: center;
}

.import-actions input[type="file"] {
  max-width: 280px;
}

.import-actions button {
  margin-top: 0;
}

.recipient-list {
  margin-top: 10px;
  border: 1px solid var(--line-200);
  border-radius: 12px;
  background: #fff;
  max-height: 340px;
  overflow: auto;
}

.import-preview {
  max-height: 260px;
}

.recipient-table {
  width: 100%;
}

.recipient-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8f9fa;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid #dee2e6;
  padding: 8px 10px;
}

.recipient-table td {
  font-size: 13px;
  padding: 7px 10px;
  border-bottom: 1px solid #f3f4f6;
  word-break: break-all;
}

.recipient-preview-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid #e5e7eb;
  font-size: 12px;
  color: #6b7280;
}

.link-btn {
  margin-top: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #2563eb;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.docs-frame {
  width: 100%;
  height: 72vh;
  border: 1px solid var(--line-200);
  border-radius: 12px;
  background: #fff;
}

.btn {
  border-radius: 10px;
  font-weight: 600;
}

.btn-primary {
  border: 1px solid var(--brand-600);
  background: linear-gradient(135deg, var(--brand-600), #5b7cfa);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.24);
}

.btn-primary:hover,
.btn-primary:focus-visible {
  border-color: var(--brand-700);
  background: linear-gradient(135deg, var(--brand-700), #4f6df1);
}

.btn-outline-primary {
  border-color: #c7d7fe;
  color: var(--brand-700);
}

.btn-outline-primary:hover {
  background: #edf3ff;
  color: var(--brand-700);
  border-color: #b4cafb;
}

.btn-outline-secondary {
  border-color: var(--line-300);
  color: var(--ink-600);
}

.btn-outline-secondary:hover {
  background: #f8fafc;
  border-color: #b9c5d4;
  color: var(--ink-800);
}

.form-control,
.form-select {
  border-color: var(--line-300);
  border-radius: 10px;
}

.form-control:focus,
.form-select:focus {
  border-color: #95b4ff;
  box-shadow: 0 0 0 0.18rem rgba(37, 99, 235, 0.16);
}

.modal-content {
  border-radius: 14px;
  border: 1px solid var(--line-200);
  box-shadow: var(--shadow-strong);
}

@media (max-width: 1240px) {
  .login-layout {
    grid-template-columns: minmax(0, 1fr) minmax(440px, 0.95fr);
  }

  .login-side {
    padding: 34px;
  }

  .visual-brand {
    font-size: 28px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .nav-left,
  .nav-right {
    min-width: 0;
  }

  .template-modal-workspace {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .template-asset-drawer {
    width: min(94vw, 420px);
  }
}

@media (max-width: 900px) {
  .login-layout {
    display: block;
    background: linear-gradient(120deg, rgba(13, 110, 253, 0.12), rgba(99, 102, 241, 0.08)),
      url("/images/bg.png") center center / cover no-repeat;
    padding: 16px;
  }

  .login-visual {
    display: none;
  }

  .login-side {
    min-height: calc(100vh - 32px);
    padding: 10px;
    background: transparent;
  }

  .login-card {
    width: 100%;
    max-width: 460px;
    padding: 26px 22px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.72);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.14);
  }

  .top-nav {
    min-height: 0;
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 16px;
  }

  .nav-left,
  .nav-right {
    min-width: 0;
  }

  .nav-center {
    width: 100%;
    flex-wrap: wrap;
    margin-left: 0;
  }

  .content-wrap {
    padding: 16px;
  }

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

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

  .mail-field-row {
    flex-direction: column;
    align-items: stretch;
  }

  .mail-field-row label {
    width: auto;
    flex: 0 0 auto;
    margin-bottom: 6px;
  }

  .mail-field-offset {
    margin-left: 0;
  }

  .filter-row {
    flex-direction: column;
  }

  .template-html-editor {
    min-height: 240px;
  }

  .template-preview-frame {
    height: 260px;
  }
}
