:root {
    color-scheme: light;
    --ink: #17212b;
    --muted: #66727e;
    --line: #d9e0e6;
    --surface: #ffffff;
    --canvas: #f3f5f7;
    --nav: #17232d;
    --green: #087f5b;
    --green-dark: #066548;
    --blue: #2463a7;
    --red: #c2413b;
    --amber: #a46708;
    --radius: 6px;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    letter-spacing: 0;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-width: 320px;
    background: var(--canvas);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.5;
    letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, .button { min-height: 36px; }
button { cursor: pointer; }

input, select, textarea {
    width: 100%;
    border: 1px solid #bcc7d0;
    border-radius: var(--radius);
    background: #fff;
    color: var(--ink);
    outline: none;
}

input, select { height: 40px; padding: 0 11px; }
textarea { resize: vertical; padding: 10px 11px; }
input[type="range"] { height: 30px; padding: 0; accent-color: var(--green); }
input[type="file"] { height: auto; padding: 8px; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36, 99, 167, .12); }

label { display: grid; gap: 6px; color: #36414b; font-weight: 600; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 2px; font-size: 22px; line-height: 1.3; }
h2 { margin-bottom: 16px; font-size: 16px; line-height: 1.35; }
p { color: var(--muted); }

.primary, .secondary, .ghost, .button, .nav-item, .segmented button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    padding: 0 14px;
    border: 1px solid transparent;
    text-decoration: none;
    white-space: nowrap;
}

.primary { border-color: var(--green); background: var(--green); color: #fff; font-weight: 650; }
.primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.secondary, .button.secondary { border-color: #b8c3cc; background: #fff; color: #293743; }
.secondary:hover, .button.secondary:hover { border-color: #8c9aa6; background: #f7f9fa; }
.ghost { background: transparent; color: #4a5966; border-color: transparent; }
.ghost:hover { background: rgba(23, 33, 43, .06); }
.wide { width: 100%; }
.muted { color: var(--muted); font-size: 13px; font-weight: 400; }
.hidden { display: none !important; }

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 5px;
    background: #15a676;
    color: #fff;
    font-weight: 800;
    font-size: 17px;
}

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel {
    width: min(380px, 100%);
    border: 1px solid var(--line);
    border-top: 4px solid var(--green);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 30px;
    box-shadow: 0 12px 36px rgba(26, 38, 49, .1);
}
.login-panel h1 { margin: 18px 0 24px; font-size: 24px; }
.login-panel form { display: grid; gap: 18px; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    background: var(--nav);
    color: #fff;
    border-bottom: 1px solid #0e171e;
}
.brand, .top-actions { display: flex; align-items: center; gap: 11px; }
.topbar .brand-mark { width: 30px; height: 30px; flex-basis: 30px; font-size: 15px; }
.topbar .ghost { color: #dbe3e9; }
.topbar .ghost:hover { background: rgba(255, 255, 255, .09); }
.queue-state { color: #cbd6dd; font-size: 13px; }
.queue-state i { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: #20c58a; }

.app-shell { min-height: calc(100vh - 58px); display: grid; grid-template-columns: 176px minmax(0, 1fr); }
.sidebar { background: #fff; border-right: 1px solid var(--line); padding: 18px 12px; }
.nav-item { width: 100%; justify-content: flex-start; margin-bottom: 5px; background: transparent; border: 0; color: #495661; font-weight: 600; }
.nav-item:hover { background: #f0f3f5; }
.nav-item.active { background: #e7f4ef; color: #076b4d; box-shadow: inset 3px 0 var(--green); }

.workspace { min-width: 0; padding: 28px 32px 50px; }
.view { display: none; max-width: 1280px; margin: 0 auto; }
.view.active { display: block; }
.view-heading { min-height: 54px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.view-heading p { margin: 2px 0 0; font-size: 13px; }

.compose-grid { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 20px; align-items: start; }
.compose-main, .send-panel, .settings-section, .table-wrap, .stats {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}
.compose-main { display: grid; gap: 20px; padding: 22px; }
.field-row.two { display: grid; grid-template-columns: minmax(230px, .8fr) minmax(260px, 1.2fr); gap: 16px; }
.field-block { display: grid; gap: 7px; }
.field-label-row { display: flex; justify-content: space-between; align-items: center; color: #36414b; font-weight: 600; }
.file-actions { display: flex; align-items: center; gap: 8px; min-height: 38px; flex-wrap: wrap; }
.attachment-button { width: max-content; }
.recipient-list { min-height: 42px; max-height: 150px; overflow: auto; display: flex; align-content: flex-start; flex-wrap: wrap; gap: 6px; padding-top: 2px; }
.recipient-chip { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; border: 1px solid #cbd6dd; border-radius: 4px; background: #f5f8fa; padding: 4px 5px 4px 8px; color: #394752; }
.recipient-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipient-chip button { min-width: 24px; min-height: 24px; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 3px; background: transparent; color: #74818c; }
.recipient-chip button:hover { background: #e0e6ea; color: var(--red); }

.send-panel { position: sticky; top: 78px; padding: 19px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; height: 38px; padding: 3px; border-radius: var(--radius); background: #e9edf0; margin-bottom: 18px; }
.segmented button { min-height: 32px; border: 0; background: transparent; color: #53616d; padding: 0 8px; }
.segmented button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(28, 40, 50, .15); }
#schedule-field { margin-bottom: 17px; }
.send-summary { margin: 8px 0 22px; border-top: 1px solid var(--line); }
.send-summary div { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid #edf0f2; }
.send-summary dt { color: var(--muted); }
.send-summary dd { margin: 0; font-weight: 700; text-align: right; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 16px; overflow: hidden; }
.stat { min-height: 84px; padding: 16px 18px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat strong { display: block; margin-top: 5px; font-size: 24px; line-height: 1.2; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid #e7ebee; text-align: left; vertical-align: middle; }
th { background: #f8f9fa; color: #5f6c77; font-size: 12px; font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfc; }
.task-title { display: block; max-width: 290px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.task-id { color: var(--muted); font-size: 12px; }
.status { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 7px; border-radius: 4px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.status.active { background: #e5f4ee; color: #087453; }
.status.scheduled { background: #e7eff9; color: #245b92; }
.status.paused { background: #fff1d6; color: #8c5806; }
.status.completed { background: #e9edf0; color: #4f5c67; }
.status.cancelled, .status.failed { background: #fae8e7; color: #a53631; }
.row-actions { display: flex; gap: 3px; flex-wrap: wrap; min-width: 175px; }
.row-actions button, .row-actions a { min-height: 30px; border: 0; background: transparent; color: var(--blue); padding: 4px 7px; text-decoration: none; border-radius: 4px; }
.row-actions button:hover, .row-actions a:hover { background: #eaf0f6; }
.empty-cell { padding: 40px 16px; text-align: center; color: var(--muted); }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.settings-section { display: grid; align-content: start; gap: 14px; padding: 22px; }
.settings-section h2 { margin-bottom: 2px; }
.settings-section button { justify-self: start; }
.config-list { margin: 0; }
.config-list div { display: grid; grid-template-columns: 88px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid #edf0f2; }
.config-list div:last-child { border-bottom: 0; }
.config-list dt { color: var(--muted); }
.config-list dd { margin: 0; overflow-wrap: anywhere; }

dialog { width: min(900px, calc(100% - 32px)); max-height: calc(100vh - 50px); padding: 0; border: 1px solid #bcc6ce; border-radius: var(--radius); color: var(--ink); box-shadow: 0 20px 70px rgba(22, 31, 39, .28); }
dialog::backdrop { background: rgba(14, 22, 28, .52); }
.dialog-head { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; padding: 15px 18px; background: #fff; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; }
.icon-button { width: 34px; height: 34px; min-height: 34px; border: 0; border-radius: 4px; background: transparent; color: #53616c; font-size: 24px; line-height: 1; }
.icon-button:hover { background: #eef1f3; }
#detail-content { padding: 18px; overflow: auto; }
.detail-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.detail-meta div { border-left: 3px solid #bdc8d0; padding: 6px 10px; }
.detail-meta span { display: block; color: var(--muted); font-size: 12px; }
.message-preview { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 220px; overflow: auto; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: #fafbfb; }
.error-text { max-width: 260px; color: var(--red); overflow-wrap: anywhere; }

#toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; max-width: min(380px, calc(100% - 40px)); transform: translateY(18px); opacity: 0; pointer-events: none; border-radius: var(--radius); background: #17232d; color: #fff; padding: 11px 15px; box-shadow: 0 8px 28px rgba(0, 0, 0, .22); transition: opacity .16s, transform .16s; }
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { background: #9f332e; }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: sticky; top: 58px; z-index: 8; display: flex; gap: 4px; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
    .nav-item { width: auto; min-width: 92px; justify-content: center; margin: 0; }
    .nav-item.active { box-shadow: inset 0 -3px var(--green); }
    .workspace { padding: 22px 18px 40px; }
    .compose-grid { grid-template-columns: 1fr; }
    .send-panel { position: static; }
    .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
    .topbar { padding: 0 14px; }
    .queue-state { display: none; }
    .workspace { padding: 18px 12px 34px; }
    .field-row.two { grid-template-columns: 1fr; }
    .compose-main { padding: 16px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stat:nth-child(2) { border-right: 0; }
    .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
    .detail-meta { grid-template-columns: 1fr; }
    .login-panel { padding: 24px 20px; }
}
