:root {
    --ink: #17211b;
    --muted: #6d786f;
    --paper: #f5f6f2;
    --white: #fff;
    --line: #dde2dc;
    --green: #245c43;
    --green-soft: #e2eee7;
    --success: #245c43;
    --success-soft: #e2eee7;
    --amber: #9a671b;
    --amber-soft: #fff2d8;
    --red: #a13d3d;
    --red-soft: #fbe7e5;
    --sidebar-bg: #173d2d;
    --shadow: 0 12px 35px rgba(23, 33, 27, .07);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 230px;
    padding: 28px 18px;
    background: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
}
.brand { padding: 0 12px 30px; font-size: 21px; font-weight: 750; letter-spacing: 0; }
.brand img { display: block; max-width: 170px; max-height: 80px; object-fit: contain; }
nav { display: grid; gap: 5px; }
nav a {
    padding: 11px 13px;
    border-radius: 9px;
    color: #c9d7cf;
    text-decoration: none;
    font-size: 14px;
}
nav a:hover, nav a.active { background: rgba(255,255,255,.1); color: white; }
main { margin-left: 230px; padding: 42px clamp(24px, 5vw, 72px); max-width: 1500px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; color: var(--ink); font-size: clamp(28px, 3vw, 42px); letter-spacing: 0; }
h2 { color: var(--ink); font-size: 18px; letter-spacing: 0; }
.eyebrow { display: block; margin-bottom: 6px; color: var(--green); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 1.2px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.card {
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--white);
    box-shadow: var(--shadow);
}
.card-title { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin-bottom: 18px; }
.card-title h2 { margin: 0; }
.narrow { max-width: 780px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 24px; }
.stats article { padding: 22px; border: 1px solid var(--line); border-radius: 8px; background: white; box-shadow: var(--shadow); }
.stats span { display: block; color: var(--muted); font-size: 13px; }
.stats strong { display: block; margin-top: 8px; font-size: 29px; }
table { width: 100%; border-collapse: collapse; }
th { padding: 10px 12px; color: var(--muted); font-size: 11px; text-align: left; text-transform: uppercase; letter-spacing: .7px; }
td { padding: 14px 12px; border-top: 1px solid var(--line); font-size: 14px; }
td small { display: block; margin-top: 3px; color: var(--muted); }
.actions { display: flex; justify-content: flex-end; gap: 6px; }
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: white;
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}
.button:hover { border-color: #aeb9b1; }
.button.primary { border-color: var(--green); background: var(--green); color: white; }
.button.small { min-height: 32px; padding: 0 11px; font-size: 12px; }
.button.ghost { color: var(--muted); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.full-button { width: 100%; }
.badge { display: inline-block; padding: 5px 9px; border-radius: 99px; font-size: 11px; font-weight: 800; }
.badge.draft { background: var(--red-soft); color: var(--red); }
.badge.ready { background: var(--amber-soft); color: var(--amber); }
.badge.sent { background: #e7edf8; color: #3d5790; }
.badge.paid { background: var(--success-soft); color: var(--success); }
.badge.opened { background: #e3f1ea; color: #276044; }
.badge.unopened { background: #f0f1ef; color: #69716b; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: #445048; font-size: 12px; font-weight: 750; }
input, textarea, select {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #cfd6d0;
    border-radius: 8px;
    outline: none;
    background: white;
    color: var(--ink);
    font: inherit;
    font-size: 14px;
}
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(36,92,67,.1); }
textarea { resize: vertical; line-height: 1.55; }
.stack { display: grid; gap: 20px; }
.repeat-row { display: grid; grid-template-columns: 1fr 38px; gap: 8px; margin-top: 9px; }
.email-row { grid-template-columns: minmax(220px, 1fr) 170px 38px; }
.service-row { grid-template-columns: 1fr 180px 38px; }
.remove { border: 0; border-radius: 8px; background: #f0f2ef; color: var(--muted); font-size: 20px; cursor: pointer; }
.form-actions { display: flex; justify-content: flex-end; }
.hint { color: var(--muted); font-size: 12px; }
.example { display: grid; gap: 5px; margin: 22px 0; padding: 16px; border-radius: 10px; background: #f1f4f0; font-family: ui-monospace, monospace; font-size: 13px; }
.example strong { margin-bottom: 5px; font-family: inherit; }
.logo-preview { display: flex; align-items: center; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #f8faf7; }
.logo-preview img { max-width: 170px; max-height: 80px; object-fit: contain; }
.logo-preview span { color: var(--muted); font-size: 12px; font-weight: 750; }
.alert { margin-bottom: 22px; padding: 13px 16px; border-radius: 8px; background: var(--success-soft); color: var(--success); font-size: 14px; font-weight: 650; }
.alert.error { background: var(--red-soft); color: var(--red); }
.inline-filter { display: flex; gap: 8px; }
.inline-filter input { width: 110px; }
.preview-layout { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 20px; align-items: start; }
.readonly-box { min-height: 42px; padding: 11px 12px; border-radius: 8px; background: #f1f4f0; color: var(--ink); font-size: 14px; font-weight: 400; }
dl { display: grid; grid-template-columns: 1fr auto; gap: 12px; margin: 0; font-size: 13px; }
dt { color: var(--muted); }
dd { margin: 0; font-weight: 700; }
.attachments { display: grid; gap: 8px; }
.attachments a, .missing { padding: 11px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); font-size: 12px; text-decoration: none; }
.attachments a span { display: inline-block; margin-right: 8px; color: var(--green); font-weight: 800; }
.missing { border-color: #f0c4bf; background: var(--red-soft); color: var(--red); }
.danger-text { color: var(--red); }
.send-box { text-align: center; }
.send-box p { margin: 12px 0 0; }
.empty { padding: 30px; color: var(--muted); text-align: center; }
.check { display: flex; align-items: center; align-self: end; min-height: 42px; }
.check input { width: auto; }
.table-check { display: inline-flex; min-height: auto; gap: 7px; white-space: nowrap; }
td input[type="checkbox"], th input[type="checkbox"] { width: auto; }
code { padding: 2px 5px; border-radius: 5px; background: #edf0ec; }
.code-editor { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.html-editor { margin-top: 7px; overflow: hidden; border: 1px solid #cfd6d0; border-radius: 8px; background: #fff; }
.html-editor:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(36,92,67,.1); }
.html-editor-toolbar { display: flex; gap: 4px; padding: 7px; border-bottom: 1px solid var(--line); background: #f7f8f6; }
.html-editor-toolbar button { min-width: 34px; height: 32px; padding: 0 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; }
.html-editor-toolbar button:hover { border-color: var(--green); color: var(--green); }
.html-editor-content { min-height: 280px; padding: 16px; outline: 0; color: #222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 1.55; }
.html-editor-source { display: none; min-height: 280px; border: 0; border-radius: 0; box-shadow: none; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.html-editor.is-source .html-editor-content { display: none; }
.html-editor.is-source .html-editor-source { display: block; }
.email-preview-shell { max-width: 820px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.email-preview-meta { padding: 14px 20px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.email-preview-body { padding: 28px; color: #222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 1.55; }
.settings-layout { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); gap: 20px; align-items: start; }
.sidebar-user { margin-top: auto; padding: 18px 12px 0; border-top: 1px solid rgba(255,255,255,.14); }
.sidebar-user span { display: block; margin-bottom: 6px; color: #fff; font-size: 13px; font-weight: 700; }
.sidebar-user button { padding: 0; border: 0; background: transparent; color: #c9d7cf; cursor: pointer; font: inherit; font-size: 12px; }
.auth-body { min-height: 100vh; background: var(--sidebar-bg); }
.auth-main { display: grid; place-items: center; min-height: 100vh; margin: 0; padding: 24px; }
.auth-panel { width: min(100%, 420px); padding: 32px; border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.auth-panel h1 { margin-bottom: 24px; font-size: 28px; }
.auth-brand { min-height: 50px; margin-bottom: 28px; }
.auth-brand img { display: block; max-width: 190px; max-height: 90px; object-fit: contain; }
.auth-brand strong { color: var(--sidebar-bg); font-size: 20px; }

@media (max-width: 900px) {
    .sidebar { position: static; width: auto; padding: 18px; }
    .brand { padding: 0 8px 14px; }
    nav { display: flex; overflow-x: auto; }
    nav a { white-space: nowrap; }
    main { margin-left: 0; padding: 25px 18px; }
    .stats, .preview-layout, .settings-layout { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .full { grid-column: auto; }
    .email-row, .service-row { grid-template-columns: 1fr; }
    .email-row .remove, .service-row .remove { min-height: 38px; }
    .card { overflow-x: auto; }
}
