:root {
    --bg: #f3f5f7;
    --card: #ffffff;
    --text: #17212b;
    --muted: #5d6975;
    --line: #dce3ea;
    --primary: #0d7a5f;
    --primary-dark: #0a5a47;
    --error-bg: #fde8e8;
    --error-text: #7f1d1d;
    --success-bg: #eafaf1;
    --success-text: #14532d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(180deg, #edf2f6 0%, #f7f9fb 100%);
    color: var(--text);
}

.topbar {
    background: #0f1720;
    color: #fff;
    border-bottom: 3px solid var(--primary);
}

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

.brand-wrap {
    display: grid;
    gap: 0.25rem;
}

.brand-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.brand-logo {
    width: 34px;
    height: 34px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
    padding: 3px;
}

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

.tenant-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: #dbe5f0;
}

.nav {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.nav a {
    color: #dbe5f0;
    text-decoration: none;
    padding: 0.35rem 0.55rem;
    border-radius: 0.4rem;
}

.nav a:hover {
    background: #1f2a36;
}

.container {
    max-width: 1200px;
    margin: 1.25rem auto;
    padding: 0 1rem 2rem;
    display: grid;
    gap: 1rem;
}

.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 0.75rem;
    padding: 1rem;
    box-shadow: 0 6px 14px rgba(15, 23, 32, 0.04);
}

.panel.narrow {
    max-width: 460px;
    margin: 2rem auto;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.85rem;
}

.stat-card {
    background: #f8fbfd;
    border: 1px solid #e0ebf2;
    border-radius: 0.65rem;
    padding: 0.8rem;
}

.stat-card h2 {
    margin: 0;
    color: var(--primary-dark);
}

.stat-card p {
    margin: 0.3rem 0 0;
    color: var(--muted);
}

.form-grid,
.form-inline {
    display: grid;
    gap: 0.75rem;
}

.form-inline {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    align-items: end;
}

label {
    display: grid;
    gap: 0.35rem;
    font-weight: 600;
    color: #24313d;
}

input,
textarea,
select,
button {
    font: inherit;
    padding: 0.55rem 0.65rem;
    border-radius: 0.45rem;
    border: 1px solid #cbd5df;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13, 122, 95, 0.18);
}

textarea {
    resize: vertical;
}

button,
.button-link,
.link-button {
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary);
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

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

button:disabled {
    background: #8da3b4;
    border-color: #8da3b4;
    cursor: not-allowed;
}

.link-button {
    padding: 0.45rem 0.75rem;
}

.secondary {
    background: #415a70;
    border-color: #415a70;
}

.danger {
    background: #b42318;
    border-color: #b42318;
}

.danger:hover {
    background: #8f1c14;
    border-color: #8f1c14;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.93rem;
}

th,
td {
    text-align: left;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid #e3e9ef;
    vertical-align: top;
}

th {
    color: #354657;
    font-weight: 700;
}

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

.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.compact-form {
    display: grid;
    gap: 0.4rem;
    margin-bottom: 0.45rem;
}

.mono {
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.8rem;
    word-break: break-all;
}

.status-pill {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.1;
}

.status-sent {
    background: #dcfce7;
    color: #166534;
}

.status-failed {
    background: #fee2e2;
    color: #991b1b;
}

.status-queued {
    background: #e2e8f0;
    color: #334155;
}

.alert {
    border-radius: 0.6rem;
    padding: 0.75rem 0.85rem;
    margin-bottom: 0.8rem;
    border: 1px solid transparent;
}

.alert.error {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: #fecaca;
}

.alert.success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: #bbf7d0;
}

.result-card {
    margin-top: 1rem;
    border: 1px solid #dae5ef;
    border-radius: 0.6rem;
    padding: 0.85rem;
    background: #f7fafc;
}

.result-card pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.82rem;
}

.signature-preview-wrap {
    display: grid;
    gap: 0.5rem;
}

.signature-preview {
    max-width: 320px;
    max-height: 120px;
    width: auto;
    height: auto;
    border: 1px solid #d6e0ea;
    border-radius: 0.45rem;
    background: #fff;
    padding: 0.5rem;
}

.dns-help {
    border: 1px solid #d7e3ee;
    background: #f7fbff;
    border-radius: 0.55rem;
    padding: 0.75rem 0.85rem;
}

.dns-help p {
    margin: 0.35rem 0;
}

.builder-group {
    display: grid;
    gap: 0.55rem;
    margin-top: 0.85rem;
}

.builder-group h3 {
    margin: 0;
}

.builder-rows {
    display: grid;
    gap: 0.6rem;
}

.placeholder-row {
    border: 1px solid #d8e4ee;
    border-radius: 0.5rem;
    background: #fbfdff;
    padding: 0.55rem;
}

.placeholder-row.is-selected {
    border-color: #0d7a5f;
    box-shadow: 0 0 0 2px rgba(13, 122, 95, 0.16);
}

.pdf-builder-wrap {
    border: 1px solid #d2dfeb;
    border-radius: 0.55rem;
    background: #f8fbff;
    overflow: hidden;
}

.pdf-builder-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
    border-bottom: 1px solid #d8e5f0;
    padding: 0.55rem;
    background: #eef5fb;
}

.pdf-builder-toolbar .is-active {
    background: #0a5a47;
    border-color: #0a5a47;
}

.pdf-page-stage-wrap {
    padding: 0.65rem;
    overflow: auto;
}

.pdf-page-stage {
    position: relative;
    margin: 0 auto;
    border: 1px solid #cedae6;
    background: #fff;
    box-shadow: 0 8px 18px rgba(15, 23, 32, 0.08);
    min-height: 280px;
}

.pdf-builder-canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.pdf-builder-overlay {
    position: absolute;
    inset: 0;
    cursor: crosshair;
}

.pdf-placeholder-box {
    position: absolute;
    border: 2px solid #1d7ff0;
    border-radius: 0.3rem;
    background: rgba(29, 127, 240, 0.13);
    cursor: move;
    user-select: none;
}

.pdf-placeholder-box.is-selected {
    border-color: #0d7a5f;
    background: rgba(13, 122, 95, 0.14);
    box-shadow: 0 0 0 2px rgba(13, 122, 95, 0.2);
}

.pdf-placeholder-label {
    display: inline-block;
    padding: 0.12rem 0.28rem;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.2;
    border-bottom-right-radius: 0.32rem;
    background: rgba(13, 17, 23, 0.75);
    color: #fff;
    max-width: calc(100% - 10px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pdf-placeholder-resize {
    position: absolute;
    right: -6px;
    bottom: -6px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: #0d7a5f;
    cursor: nwse-resize;
    box-shadow: 0 0 0 1px rgba(13, 17, 23, 0.24);
}

@media (max-width: 900px) {
    .topbar-inner {
        align-items: flex-start;
        flex-direction: column;
    }

    .nav {
        width: 100%;
    }
}
