/* Reusable UI pieces. Colours come only from theme variables. */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 8px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
  font-weight: 550; font-size: var(--text-md); white-space: nowrap; box-shadow: var(--shadow-sm);
}
.btn .icon { width: 15px; height: 15px; }
.btn:hover { border-color: var(--border-hover); background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger-border); }
.btn.outline { color: var(--brand); border-color: var(--brand-border); }
.btn.outline:hover { border-color: var(--brand); background: var(--brand-softer); }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--hover); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.loading { opacity: 0.75; cursor: progress; }
.btn.loading::before { content: ''; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
.btn.loading .icon { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.iconbutton { border: 0; background: transparent; color: var(--text-3); padding: 6px; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; }
.iconbutton:hover { background: var(--surface-3); color: var(--text-2); }
.linkbtn { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--brand); font-size: var(--text-sm); padding: 4px 0; }
.linkbtn:hover { text-decoration: underline; }
.linkbtn .icon { width: 15px; height: 15px; }

/* ---------- Cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); min-width: 0; }
.stat { padding: 19px 20px 16px; }
.stat-label { font-size: var(--text-md); color: var(--text-3); }
.stat-value { font-family: var(--font-display); font-size: 29px; font-weight: 750; letter-spacing: -1px; margin: 9px 0; }
.stat-foot { font-size: var(--text-xs); color: var(--text-4); }
.settings-section { padding: 23px; }
.settings-section h2 { margin: 0 0 5px; font-size: var(--text-lg); }
.settings-section > p { margin: 0 0 23px; font-size: var(--text-md); color: var(--text-3); }
.settings-section .row-between { padding: 10px 0; border-bottom: 1px solid var(--border); }
.settings-section .row-between strong.bad { color: var(--danger); }

/* ---------- Badges ---------- */
.badge .icon { width: 12px; height: 12px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 7px; border-radius: 4px; font-size: var(--text-xs); font-weight: 550; white-space: nowrap; background: var(--surface-3); color: var(--text-3); }
.badge.green { color: var(--success); background: var(--success-soft); }
.badge.amber { color: var(--warning); background: var(--warning-soft); }
.badge.blue { color: var(--info); background: var(--info-soft); }
.badge.red { color: var(--danger); background: var(--danger-soft); }
.dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; white-space: nowrap; }
th { background: var(--surface-2); font-size: var(--text-xs); letter-spacing: 0.3px; text-transform: uppercase; font-weight: 550; color: var(--text-4); padding: 12px 20px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
td { padding: 15px 20px; border-bottom: 1px solid var(--border); font-size: var(--text-md); color: var(--text-2); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td strong { color: var(--text); font-weight: 600; }
td small { display: block; font-size: var(--text-xs); color: var(--text-4); margin-top: 3px; }
.table-wrap .btn { margin: 3px; font-size: var(--text-xs); padding: 7px 10px; }
.table-footer { padding: 13px 22px; font-size: var(--text-xs); color: var(--text-4); flex-wrap: wrap; gap: 8px; }
/* Pager sits inside the table card as its footer. */
.card:has(+ .table-footer) { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.card + .table-footer { background: var(--surface); border: 1px solid var(--border); border-top-color: var(--border); margin-top: -1px; border-radius: 0 0 var(--radius-lg) var(--radius-lg); box-shadow: var(--shadow-sm); }
.rowactions { display: flex; align-items: center; justify-content: flex-end; }
table:has(.rowactions) th:last-child { text-align: right; }

/* Row "More" menu (native popover, positioned by main.js). */
.menu[popover] { position: fixed; inset: auto; margin: 0; min-width: 190px; padding: 6px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16); }
.menu .btn, .table-wrap .menu .btn { margin: 0; display: flex; width: 100%; justify-content: flex-start; border: 0; box-shadow: none; background: transparent; font-size: var(--text-sm); }
.menu .btn:hover { background: var(--hover); }
.empty { padding: 50px 25px; text-align: center; color: var(--text-3); }
.dnslist td { white-space: normal; word-break: break-all; }
.rtable { overflow-x: auto; }
.rtable td, .rtable th { white-space: nowrap; }

/* ---------- Search & filters ---------- */
.filters { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.filters-left { display: flex; flex-direction: column; gap: 12px; flex: 1; min-width: 250px; }
.filters > .btn { margin-left: auto; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.filterchip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); color: var(--text-2); font-size: var(--text-sm); font-weight: 500; }
.filterchip em { font-style: normal; font-size: var(--text-xs); min-width: 20px; padding: 1px 6px; border-radius: 999px; background: var(--surface-3); color: var(--text-3); text-align: center; }
.filterchip:hover { border-color: var(--border-hover); }
.filterchip.active { border-color: var(--brand); background: var(--brand-softer); color: var(--brand); }
.filterchip.active em { background: var(--brand-soft); color: var(--brand); }
.searchbox { display: flex; gap: 9px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 12px; width: 100%; max-width: 350px; }
.searchbox .icon { width: 16px; color: var(--text-4); }
.searchbox input { border: 0; outline: 0; background: transparent; width: 100%; height: 37px; font-size: var(--text-md); color: var(--text); }

/* ---------- Forms ---------- */
.field { margin-bottom: 17px; }
.field > label { display: block; font-size: var(--text-xs); font-weight: 600; margin-bottom: 6px; color: var(--text-2); }
select, .field input, .field textarea, .field select {
  width: 100%; max-width: 100%; min-height: var(--control-height); padding: 8px 11px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: var(--text-md);
}
.field textarea { min-height: 110px; resize: vertical; line-height: 1.7; }
.field input[type='file'] { padding: 8px; }
input::placeholder, textarea::placeholder { color: var(--text-4); opacity: 1; }
input[type='checkbox'] { width: auto; accent-color: var(--brand); }
.checkrow { display: flex; gap: 8px; align-items: flex-start; font-size: var(--text-xs); color: var(--text-3); margin-top: 18px; }
.checkrow input { margin-top: 3px; }

/* "news" + "@domain" as one control. */
.emailjoin { display: flex; align-items: stretch; }
.emailjoin input { flex: 1; min-width: 0; border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important; }
.emailjoin select { width: auto !important; flex: 0 1 auto; max-width: 62%; border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background-color: var(--surface-3); color: var(--text); font-size: var(--text-sm); padding: 8px 30px 8px 10px; cursor: pointer; }
.emailjoin input:focus-visible, .emailjoin select:focus-visible { outline-offset: -2px; }

/* Two-way segmented switch (also used with three options). */
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-3); border-radius: var(--radius-md); margin-bottom: 10px; }
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.seg { display: flex; align-items: center; justify-content: center; gap: 8px; border: 0; background: transparent; border-radius: var(--radius-sm); padding: 9px 10px; font-size: var(--text-sm); color: var(--text-2); }
.seg.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-md); }
.seg .icon { width: 16px; height: 16px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 12px; border-bottom: 1px solid var(--border); margin-bottom: 22px; padding-bottom: 12px; }
.tab { padding: 12px 0; border: 0; background: none; color: var(--text-3); font-size: var(--text-sm); border-bottom: 2px solid transparent; }
.tab.active { color: var(--brand); border-color: var(--brand); font-weight: 600; }

/* ---------- Notices ---------- */
.info { display: flex; gap: 10px; align-items: flex-start; background: var(--brand-softer); border: 1px solid var(--brand-border); color: var(--text-2); padding: 13px 16px; border-radius: 8px; font-size: var(--text-xs); line-height: 1.7; margin: 20px 0; }
.info.amber { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning); }
.infoline { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.infoline .icon { width: 15px; height: 15px; flex: 0 0 auto; }
.review { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin: 12px 0; }
.chip { background: var(--surface-3); border-radius: 6px; padding: 3px 8px; font-size: var(--text-xs); color: var(--text); }
.chip em { font-style: normal; color: var(--text-3); margin-left: 4px; font-family: var(--font-body); }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 25px; background: var(--overlay); backdrop-filter: blur(3px); }
.modal { width: 570px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden; background: var(--surface); color: var(--text); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); }
.modal.wide { width: 850px; }
.modal.xl { width: 1200px; max-height: 94vh; }
.modal-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 22px 25px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-family: var(--font-display); font-size: 19px; letter-spacing: -0.5px; margin: 0; }
.modal-sub { margin: 4px 0 0; font-size: var(--text-sm); color: var(--text-3); }
.modal-x { width: 34px; height: 34px; border-radius: 8px; }
.modal-x .icon { width: 18px; height: 18px; }
.modal-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 23px 25px; }
.modal-foot { flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 10px; padding: 17px 25px; border-top: 1px solid var(--border); background: var(--surface-2); }
.modal-foot:empty { display: none; }
.foot-hint { margin-right: auto; align-self: center; font-size: var(--text-sm); color: var(--text-3); }
.modal .row-between strong { max-width: 65%; text-align: right; }
@media (max-width: 650px) {
  .modal-backdrop { padding: 12px; }
  .modal-head, .modal-body { padding: 18px; }
  .modal-foot { padding: 15px 18px; flex-wrap: wrap; }
}

/* ---------- Toast ---------- */
#toast { position: fixed; bottom: 25px; left: calc(50% + 100px); transform: translateX(-50%); z-index: 200; max-width: 90vw; padding: 12px 20px; border-radius: 9px; background: var(--toast-bg); color: var(--toast-text); font-size: var(--text-sm); box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#toast.show { opacity: 1; }
@media (max-width: 650px) { #toast { left: 50%; } }

/* ---------- Email body editor & previews ---------- */
.bodycard { border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--surface); }
.bodyhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 10px 4px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.bodytabs { display: flex; gap: 20px; }
.bodycard .tab { padding: 10px 0; }
.bodycard textarea { width: 100%; min-height: 380px; border: 0; border-radius: 0; padding: 14px 16px; resize: vertical; font-size: var(--text-sm); line-height: 1.6; background: var(--surface); color: var(--text); }
.bodycard textarea[name='html'] { font-family: var(--font-mono); }
#email-preview, #campaign-preview { display: block; width: 100%; min-height: 380px; border: 0; background: var(--preview-bg); }
.textpreview { white-space: pre-wrap; margin: 0; padding: 14px 16px; font: 13px/1.6 var(--font-mono); color: var(--text-2); max-height: 420px; overflow: auto; }
.modal.xl #campaign-preview, .modal.xl .textpreview { min-height: 520px; max-height: none; }

/* ---------- Timeline ---------- */
.timeline { border-left: 1px solid var(--border); margin: 18px 0 0 6px; padding-left: 20px; }
.timeline div { position: relative; padding-bottom: 22px; }
.timeline div::before { content: ''; position: absolute; left: -27px; top: 2px; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); border: 3px solid var(--surface); box-sizing: content-box; }
.timeline p { font-size: var(--text-xs); color: var(--text-3); margin: 2px 0; }

/* ---------- Loading skeleton ---------- */
.sk { display: block; border-radius: 6px; max-width: 100%; background: linear-gradient(90deg, var(--surface-3) 25%, var(--hover) 50%, var(--surface-3) 75%); background-size: 200% 100%; animation: sk-shimmer 1.3s ease-in-out infinite; }
.pagehead .sk + .sk, .hcell .sk + .sk, .sk-card .sk + .sk { margin-top: 10px; }
.sk-card { padding: 20px; }
.sk-card .sk:first-child { margin-bottom: 18px; }
.sk-row { display: flex; gap: 24px; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.sk-row:last-child { border-bottom: 0; }
.sk-head { background: var(--surface-2); padding: 14px 20px; }
@keyframes sk-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sk { animation: none; } }
