:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #273549;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: clip;
}

code {
  background: rgba(148, 163, 184, 0.14);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.88em;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.hidden {
  display: none !important;
}

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

.small {
  font-size: 0.84rem;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Auth */
.auth-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px 16px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.auth-brand {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.auth-brand > div:last-child {
  min-width: 0;
}

.auth-brand h1 {
  margin: 0 0 4px;
  font-size: 1.35rem;
}

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #3b82f6);
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 260px;
}

.brand-row > div:last-child {
  min-width: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-sub {
  font-size: 0.82rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

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

.inline-form {
  display: inline-flex;
  margin: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 15px;
  min-height: 38px;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  color: var(--text);
  background: var(--surface-2);
  touch-action: manipulation;
}

.btn:hover {
  opacity: 0.92;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.btn-sm {
  padding: 6px 11px;
  min-height: 34px;
  font-size: 0.82rem;
}

.btn-full {
  width: 100%;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field > span,
.field-header > span {
  font-size: 0.86rem;
  font-weight: 600;
  color: #cbd5e1;
}

.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

input[type="text"],
input[type="password"],
input[type="file"],
textarea,
select {
  width: 100%;
  max-width: 100%;
  background: #0f172a;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
}

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

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
}

.inline-input {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.inline-input > input {
  flex: 1 1 180px;
  min-width: 0;
}

/* Alerts & Toast */
.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 14px;
  overflow-wrap: anywhere;
}

.alert-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fecaca;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  max-width: calc(100vw - 28px);
  z-index: 100;
  background: #1e293b;
  border: 1px solid var(--border);
  border-left: 4px solid var(--green);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  font-size: 0.9rem;
}

.toast.toast-error {
  border-left-color: var(--red);
}

/* Summary Bar */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.summary-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}

.summary-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.summary-value {
  font-size: 1.45rem;
  font-weight: 700;
}

.text-green {
  color: var(--green);
}

/* Campaign Cards */
.campaigns-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 16px;
}

.campaign-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.campaign-card.is-off {
  border-color: rgba(239, 68, 68, 0.35);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.card-head > div:first-child {
  min-width: 0;
  flex: 1 1 200px;
}

.card-title {
  margin: 0 0 4px;
  font-size: 1.08rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  max-width: 100%;
}

.badge-green {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
}

.badge-red {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
}

.badge-blue {
  background: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
}

.card-toggles {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mini-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
}

.card-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.tz-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tz-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.76rem;
  color: #cbd5e1;
}

.payload-preview {
  background: #0f172a;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.82rem;
  color: #cbd5e1;
  max-height: 66px;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.card-stats {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

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

.empty-state {
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #334155;
  transition: 0.2s;
  border-radius: 999px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: 0.2s;
  border-radius: 50%;
}

.switch input:checked + .slider {
  background-color: var(--green);
}

.switch input:checked + .slider:before {
  transform: translateX(20px);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal {
  width: 100%;
  max-width: 520px;
  max-height: calc(100dvh - 36px);
  margin: auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-lg {
  max-width: 720px;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.12rem;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 6px;
}

.toggles-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.toggle-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.toggle-box > div:first-child {
  min-width: 0;
  flex: 1 1 200px;
}

/* Timezone Picker */
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: #cbd5e1;
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 0.78rem;
  cursor: pointer;
  touch-action: manipulation;
}

.chip-btn:hover {
  border-color: var(--primary);
}

.chip-danger {
  color: #fca5a5;
}

.selected-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}

.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.45);
  color: #e0e7ff;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.8rem;
  max-width: 100%;
}

.selected-chip button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}

.tz-search-wrap {
  position: relative;
}

.tz-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 210px;
  overflow-y: auto;
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 30;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.tz-option {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.88rem;
  cursor: pointer;
}

.tz-option:hover {
  background: var(--surface-2);
}

/* Code Blocks */
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.code-block {
  margin: 0;
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 0.82rem;
  overflow-x: auto;
  color: #e2e8f0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-all;
}

/* Simulator Result */
.sim-result {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f172a;
  font-size: 0.9rem;
}

.sim-result.approved {
  border-color: rgba(16, 185, 129, 0.5);
}

.sim-result.rejected {
  border-color: rgba(239, 68, 68, 0.5);
}

.deploy-section {
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  flex-shrink: 0;
}

.global-section {
  margin-bottom: 24px;
}

.global-card {
  border-color: rgba(99, 102, 241, 0.45);
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.08), var(--surface) 45%);
}

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

.section-heading {
  margin: 0;
  font-size: 1rem;
  color: #cbd5e1;
  font-weight: 700;
}

/* Saved File Rows (Encrypt / Decrypt) */
.saved-file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.saved-file-info {
  min-width: 0;
  flex: 1 1 220px;
  overflow-wrap: anywhere;
}

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

/* Tablet & Mobile Breakpoints */
@media (max-width: 900px) {
  .topbar {
    position: static;
  }

  .topbar-inner {
    padding: 12px 16px;
  }

  .container {
    padding: 18px 16px 48px;
  }
}

@media (max-width: 640px) {
  .auth-card {
    padding: 22px 18px;
  }

  /* Prevent iOS Safari zoom on input focus */
  input[type="text"],
  input[type="password"],
  input[type="file"],
  textarea,
  select {
    font-size: 16px;
  }

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .topbar-actions .inline-form,
  .topbar-actions .inline-form .btn {
    width: 100%;
    grid-column: 1 / -1;
  }

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

  .summary-item {
    padding: 12px;
  }

  .summary-value {
    font-size: 1.25rem;
  }

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

  .campaign-card {
    padding: 14px;
  }

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

  .modal-backdrop {
    padding: 10px;
  }

  .modal {
    max-height: calc(100dvh - 20px);
    border-radius: 12px;
  }

  .modal-header {
    padding: 14px 16px;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    flex-direction: column-reverse;
  }

  .modal-footer .btn {
    width: 100%;
  }

  .saved-file-actions {
    width: 100%;
  }

  .toast {
    left: 14px;
    right: 14px;
    bottom: 14px;
    text-align: center;
  }
}

@media (max-width: 380px) {
  .summary-bar {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar-actions,
  .card-actions {
    grid-template-columns: minmax(0, 1fr);
  }
}
