@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

:root {
  --nex-site-max: 1320px;
  --nex-section-max: 1160px;
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-light: #94a3b8;
  --brand-blue: #0061ff;
  --brand-blue-hover: #0052d4;
  --brand-blue-light: rgba(0, 97, 255, 0.08);
  --brand-blue-border: rgba(0, 97, 255, 0.1);
  --shadow-sm: 0 2px 8px rgba(0, 97, 255, 0.03);
  --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.035);
  --success: #10b981;
  --danger: #ef4444;
  --warning: #d97706;
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  overflow-x: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 16px;
  line-height: 1.6;
}

body.is-locked {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: var(--brand-blue);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  padding: 9px 16px;
  transition: all 0.2s ease;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(248, 250, 252, 0.96);
  backdrop-filter: blur(10px);
  padding: 20px;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  display: grid;
  gap: 16px;
  width: min(440px, 100%);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.12);
  padding: 28px;
}

.login-brand {
  padding-left: 0;
  margin-bottom: 6px;
}

.login-hint {
  color: var(--text-light);
  font-size: 12px;
  font-weight: 700;
}

button:hover {
  background: var(--brand-blue-hover);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

a {
  color: var(--brand-blue);
  font-weight: 800;
  text-decoration: none;
}

.nex-container {
  width: 100%;
  max-width: var(--nex-site-max);
  margin: 0 auto;
  padding: 0 24px;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 40px;
  min-height: 100vh;
  padding-top: 40px;
  padding-bottom: 80px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: calc(100vh - 80px);
  padding: 24px 16px;
  border: 1px solid var(--brand-blue-border);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 8px;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(0, 97, 255, 0.08);
  color: var(--brand-blue);
}

.brand-icon svg,
.nav-icon,
.metric-icon svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.brand-icon svg {
  width: 18px;
  height: 18px;
}

.brand strong {
  display: block;
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.brand span {
  display: block;
  color: var(--text-light);
  font-size: 11px;
  font-weight: 700;
  margin-top: 1px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  justify-content: flex-start;
  width: 100%;
  border: 1px solid transparent;
  background: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  padding: 11px 14px;
  text-align: left;
}

.nav-item:hover {
  background: rgba(0, 97, 255, 0.04);
  color: var(--brand-blue);
  transform: none;
}

.nav-item.active {
  border-color: rgba(0, 97, 255, 0.15);
  background: var(--brand-blue-light);
  color: var(--brand-blue);
}

.nav-icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: auto;
  padding-top: 16px;
  padding-left: 8px;
  border-top: 1px solid #e2e8f0;
}

.sidebar-footer span {
  color: var(--text-light);
  font-size: 11px;
  font-weight: 700;
}

.sidebar-footer strong {
  color: var(--text-primary);
  font-size: 13px;
}

.refresh-link {
  justify-content: flex-start;
  min-height: auto;
  margin-top: 12px;
  padding: 4px 0;
  background: none;
  color: var(--text-light);
  font-size: 11px;
  font-weight: 700;
}

.refresh-link:hover {
  background: none;
  color: var(--brand-blue);
  transform: none;
}

.main {
  width: 100%;
  min-width: 0;
}

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

h1 {
  color: var(--text-primary);
  font-size: 24px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

h2 {
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 4px;
}

.topbar p {
  max-width: 720px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  margin-top: 6px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.ghost {
  border: 1px solid var(--brand-blue-border);
  background: rgba(0, 97, 255, 0.05);
  color: var(--brand-blue);
}

.ghost:hover {
  background: rgba(0, 97, 255, 0.1);
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

.metric,
.panel,
.table-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 16px;
  background: var(--bg-secondary);
  box-shadow: var(--shadow-md);
  transition: all 0.2s ease;
}

.metric:hover,
.panel:hover,
.table-card:hover {
  border-color: rgba(0, 97, 255, 0.14);
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.05);
}

.metric {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 20px;
  min-height: 112px;
  padding: 24px;
  align-items: center;
}

.metric-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
}

.metric-icon svg {
  width: 24px;
  height: 24px;
}

.metric-copy {
  display: flex;
  flex-direction: column;
}

.metric-blue {
  background: rgba(0, 97, 255, 0.08);
}

.metric-green {
  background: rgba(16, 185, 129, 0.08);
}

.metric-amber {
  background: rgba(234, 179, 8, 0.12);
}

.metric span {
  align-self: end;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  align-self: start;
  color: var(--text-primary);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.2;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 14px;
  margin-bottom: 20px;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(0, 97, 255, 0.1);
  border-radius: 10px;
  background: #fff;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  outline: none;
  padding: 9px 12px;
}

input,
select {
  min-height: 42px;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(0, 97, 255, 0.36);
  box-shadow: 0 0 0 3px rgba(0, 97, 255, 0.08);
}

.table-card,
.panel {
  padding: 24px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

thead tr {
  border-bottom: 2px solid rgba(0, 97, 255, 0.08);
}

tbody tr {
  border-bottom: 1px solid rgba(0, 97, 255, 0.04);
}

th {
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 800;
  padding: 12px 16px;
}

td {
  color: var(--text-primary);
  padding: 14px 16px;
  vertical-align: middle;
}

.customer {
  display: grid;
  gap: 2px;
}

.customer strong {
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--text-light);
  font-size: 11px;
  font-weight: 700;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 9px;
}

.pill.pending {
  border-color: rgba(217, 119, 6, 0.16);
  background: rgba(234, 179, 8, 0.12);
  color: var(--warning);
}

.pill.delivered {
  border-color: rgba(16, 185, 129, 0.16);
  background: rgba(16, 185, 129, 0.08);
  color: #059669;
}

.pill.error {
  border-color: rgba(239, 68, 68, 0.15);
  background: rgba(239, 68, 68, 0.08);
  color: var(--danger);
}

.empty {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  color: var(--text-light);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.empty.show {
  display: flex;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

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

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

.panel-title-row h2 {
  margin-bottom: 0;
}

.panel-wide,
.panel-full,
.form-actions {
  grid-column: 1 / -1;
}

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

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

.split {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 20px;
}

.guide-layout,
.email-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 20px;
  align-items: start;
}

.guide-card {
  align-content: start;
}

.step-list {
  display: grid;
  gap: 14px;
}

.step-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(0, 97, 255, 0.08);
  border-radius: 12px;
  background: #ffffff;
}

.step-item > span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-blue);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.step-item strong,
.guide-note strong {
  display: block;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 3px;
}

.step-item p {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
}

.guide-note {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(0, 97, 255, 0.08);
  border-radius: 12px;
  background: #ffffff;
}

.panel-copy {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  margin-top: -4px;
}

.script-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.script-config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.code-textarea {
  min-height: 520px;
  border-radius: 12px;
  background: #0f172a;
  color: #dbeafe;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre;
  overflow: auto;
}

code {
  display: block;
  overflow-x: auto;
  border-radius: 8px;
  background: #f1f5f9;
  color: var(--text-secondary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  padding: 9px 10px;
}

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

.token-grid span {
  border: 1px solid rgba(0, 97, 255, 0.14);
  border-radius: 999px;
  background: rgba(0, 97, 255, 0.06);
  color: var(--brand-blue);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
}

.email-preview {
  position: sticky;
  top: 24px;
}

.mail-frame {
  display: grid;
  gap: 14px;
  min-height: 360px;
  border: 1px solid rgba(0, 97, 255, 0.08);
  border-radius: 12px;
  background: #ffffff;
  padding: 18px;
}

.mail-frame > strong {
  display: block;
  border-bottom: 1px solid #e2e8f0;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 800;
  padding-bottom: 12px;
}

#email-preview-body {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

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

.list-item {
  border: 1px solid rgba(0, 97, 255, 0.08);
  border-radius: 12px;
  background: #ffffff;
  padding: 14px;
}

.product-item {
  display: grid;
  gap: 8px;
}

.list-actions {
  margin-top: 4px;
}

.list-item strong {
  display: block;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 800;
}

.list-item small {
  display: block;
  color: var(--text-light);
  font-size: 11px;
  font-weight: 700;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

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

.row-actions button {
  min-height: 34px;
  border: 1px solid rgba(0, 97, 255, 0.14);
  background: rgba(0, 97, 255, 0.06);
  color: var(--brand-blue);
  font-size: 12px;
  padding: 7px 12px;
}

.row-actions button:hover {
  background: rgba(0, 97, 255, 0.1);
}

.toast {
  display: none;
  border-radius: 12px;
  margin-bottom: 20px;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 800;
}

.toast.show {
  display: block;
}

.toast.success {
  border: 1px solid rgba(16, 185, 129, 0.16);
  background: rgba(16, 185, 129, 0.08);
  color: #059669;
}

.toast.error {
  border: 1px solid rgba(239, 68, 68, 0.15);
  background: rgba(239, 68, 68, 0.08);
  color: #dc2626;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  .sidebar {
    position: relative;
    top: auto;
    min-height: auto;
  }

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

  .sidebar-footer {
    display: none;
  }

  .topbar,
  .top-actions,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  .settings-grid,
  .field-grid,
  .split,
  .guide-layout,
  .email-layout,
  .script-tools,
  .script-config-grid {
    grid-template-columns: 1fr;
  }

  .email-preview {
    position: static;
  }
}

@media (max-width: 560px) {
  .nex-container {
    padding: 0 14px;
  }

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

  .metric-grid {
    gap: 12px;
    margin-bottom: 24px;
  }

  .metric {
    padding: 18px;
  }

  .panel,
  .table-card {
    padding: 16px;
  }

  th,
  td {
    padding: 12px 10px;
  }
}
