* {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    --bg: #101214;
    --surface: #171b20;
    --surface-2: #1f252c;
    --surface-3: #252d35;
    --line: #303943;
    --text: #edf2f7;
    --muted: #93a0ad;
    --soft: #c8d2dc;
    --blue: #28a7e8;
    --blue-2: #137fba;
    --green: #37c983;
    --amber: #f0b84d;
    --red: #f26b6b;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    border: 0;
}

.app-shell {
    max-width: 1440px;
    margin: 0 auto;
    padding: 18px 22px 32px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 12px 0 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 220px;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--blue);
    color: white;
    font-weight: 800;
}

.brand-title {
    font-weight: 700;
    letter-spacing: 0;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.nav {
    display: flex;
    gap: 8px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.nav a {
    color: var(--soft);
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
}

.nav a.active {
    background: var(--surface-3);
    color: var(--text);
}

.page-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin: 8px 0 18px;
}

.page-head h1 {
    margin: 0;
    font-size: 26px;
    letter-spacing: 0;
}

.page-head p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.account-panel {
    margin-bottom: 16px;
}

.account-layout {
    display: grid;
    grid-template-columns: minmax(360px, 1fr) minmax(360px, 0.9fr);
    gap: 16px;
    align-items: start;
}

.account-main,
.telegram-login-box {
    display: grid;
    gap: 12px;
}

.telegram-login-box {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #11161b;
    padding: 14px;
}

.account-list {
    display: grid;
    gap: 8px;
}

.account-item {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #11161b;
    padding: 11px 12px;
}

.account-item.selected {
    border-color: rgba(40, 167, 232, 0.5);
    background: rgba(40, 167, 232, 0.1);
}

.account-name {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-weight: 700;
    font-size: 14px;
}

.account-meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 4px;
}

.account-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.telegram-code-step {
    display: none;
    gap: 12px;
}

.telegram-code-step .field {
    margin: 0;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(360px, 0.9fr) minmax(480px, 1.1fr);
    gap: 16px;
    align-items: start;
}

.full-row {
    grid-column: 1 / -1;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
}

.panel-header {
    min-height: 54px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel-title {
    font-weight: 700;
    font-size: 14px;
}

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

.panel-body {
    padding: 16px;
}

.toolbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    margin-bottom: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 36px;
    padding: 8px 12px;
    border-radius: 7px;
    cursor: pointer;
    color: var(--text);
    background: var(--surface-3);
    transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
    background: #303a44;
}

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

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

.btn-danger {
    background: #7f2f35;
    color: #fff;
}

.btn-danger:hover {
    background: #9b3840;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--soft);
}

.btn-sm {
    min-height: 30px;
    padding: 6px 10px;
    font-size: 12px;
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.input,
.select,
.textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #11161b;
    color: var(--text);
    outline: none;
}

.input,
.select {
    min-height: 38px;
    padding: 8px 11px;
}

.textarea {
    min-height: 140px;
    padding: 12px;
    resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
    border-color: var(--blue);
}

.field label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 6px;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.target-list {
    max-height: 610px;
    overflow: auto;
    padding-right: 4px;
}

.target-block {
    border-bottom: 1px solid #252d35;
    padding-bottom: 6px;
    margin-bottom: 6px;
}

.target-block:last-child {
    border-bottom: 0;
}

.target-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 7px;
    cursor: pointer;
}

.target-item:hover {
    background: #20262d;
}

.target-item.selected {
    background: rgba(40, 167, 232, 0.12);
    border-color: rgba(40, 167, 232, 0.42);
}

.target-item.disabled {
    opacity: 0.48;
    cursor: not-allowed;
}

.target-item.disabled:hover {
    background: transparent;
}

.target-item input {
    width: 17px;
    height: 17px;
    accent-color: var(--blue);
}

.topic-list {
    margin-left: 28px;
    padding: 2px 0;
}

.target-name {
    font-size: 14px;
    font-weight: 650;
}

.target-meta {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 9px;
    max-height: 286px;
    overflow: auto;
}

.upload-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-bottom: 8px;
}

.compact-status {
    min-height: 18px;
    margin-top: 0;
    margin-bottom: 8px;
}

.image-item {
    position: relative;
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    background: #10151a;
    cursor: pointer;
}

.image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.image-item.selected {
    border-color: var(--blue);
}

.image-delete-btn {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 2;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: rgba(127, 47, 53, 0.94);
    color: #fff;
    cursor: pointer;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
}

.image-item:hover .image-delete-btn,
.image-delete-btn:focus {
    opacity: 1;
}

.image-delete-btn:hover {
    background: #9b3840;
}

.image-item.selected::after {
    content: "OK";
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 10px;
    font-weight: 800;
    padding: 3px 5px;
    border-radius: 6px;
    background: var(--blue);
    color: #fff;
}

.preview {
    min-height: 112px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #11161b;
    padding: 12px;
}

.preview img {
    max-width: 180px;
    max-height: 180px;
    border-radius: 7px;
    display: none;
    margin-bottom: 10px;
}

.preview-text {
    white-space: pre-wrap;
    color: var(--soft);
    font-size: 14px;
}

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

.status {
    margin-top: 10px;
    color: var(--muted);
    font-size: 13px;
}

.result-list {
    margin-top: 12px;
    display: grid;
    gap: 6px;
    max-height: 240px;
    overflow: auto;
}

.result-item {
    padding: 8px 10px;
    border-radius: 7px;
    font-size: 13px;
}

.result-item.success {
    background: rgba(55, 201, 131, 0.13);
    color: #86e7b7;
}

.result-item.failed {
    background: rgba(242, 107, 107, 0.12);
    color: #ff9c9c;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    color: #bde8ff;
    background: rgba(40, 167, 232, 0.16);
}

.badge-muted {
    color: #bcc6cf;
    background: #303842;
}

.badge-success {
    color: #9ff0c6;
    background: rgba(55, 201, 131, 0.14);
}

.form-stack {
    display: grid;
    gap: 13px;
}

.time-add-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.time-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    min-height: 28px;
    margin-top: 8px;
}

.time-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(40, 167, 232, 0.15);
    color: #a9ddff;
    font-size: 12px;
}

.time-chip button {
    background: transparent;
    color: #a9ddff;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.interval-row {
    display: grid;
    grid-template-columns: 1fr 120px;
    gap: 8px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--soft);
    font-size: 13px;
}

.check-row input {
    accent-color: var(--blue);
}

.scenario-list {
    display: grid;
    gap: 9px;
}

.scenario-item {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #11161b;
    padding: 13px;
}

.scenario-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-weight: 750;
}

.scenario-meta {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.55;
    margin-top: 5px;
}

.scenario-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.scenario-account-select {
    width: 220px;
    min-height: 30px;
    padding: 5px 9px;
    font-size: 12px;
}

.empty-state,
.loading {
    color: var(--muted);
    padding: 24px;
    text-align: center;
}

.split-stack {
    display: grid;
    gap: 16px;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(100%, 420px);
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    padding: 24px;
}

.login-brand {
    margin-bottom: 22px;
}

@media (max-width: 960px) {
    .topbar,
    .page-head,
    .send-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .workspace,
    .field-grid,
    .scenario-item,
    .account-layout,
    .account-item,
    .upload-row {
        grid-template-columns: 1fr;
    }

    .nav {
        width: 100%;
    }

    .nav a {
        flex: 1;
        text-align: center;
    }
}
