:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #101828;
    --muted: #7b8aa5;
    --line: #dce4f1;
    --blue: #3d82f5;
    --violet: #8a55ef;
    --pink: #ec3fa7;
    --green: #16b862;
    --amber: #f59e0b;
    --danger: #ef4444;
    --shadow: 0 16px 35px rgba(20, 35, 70, .10);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    min-height: 100%;
    color: var(--text);
    background: var(--bg);
    font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

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

button {
    cursor: pointer;
}

img {
    max-width: 100%;
    display: block;
}

.icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.16em;
}

.flash-stack {
    position: fixed;
    z-index: 80;
    top: 18px;
    right: 18px;
    display: grid;
    gap: 10px;
    max-width: min(420px, calc(100vw - 36px));
}

.flash {
    border-radius: 8px;
    padding: 11px 14px;
    box-shadow: var(--shadow);
    background: #fff;
    border: 1px solid var(--line);
}

.flash-success {
    color: #067647;
    border-color: #b8e6cc;
    background: #edfdf4;
}

.flash-error {
    color: #b42318;
    border-color: #ffd0c9;
    background: #fff3f1;
}

.btn {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 0;
    border-radius: 8px;
    padding: 9px 16px;
    color: #30405f;
    background: #eef3fa;
    font-weight: 700;
    white-space: nowrap;
    transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn.full {
    width: 100%;
}

.btn.gradient {
    color: #fff;
    background: linear-gradient(135deg, #3d82f5 0%, #914eea 100%);
}

.btn.primary {
    color: #fff;
    background: #3d82f5;
}

.btn.soft {
    background: #f0f4fa;
}

.btn.pink-soft {
    color: var(--pink);
    background: #ffe8f4;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    display: inline-grid;
    place-items: center;
    color: #63748f;
    background: #eef3fa;
}

.icon-btn.edit {
    color: var(--pink);
    background: #ffe8f4;
}

.icon-btn.danger {
    color: var(--danger);
    background: #feeceb;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 14px;
    color: var(--text);
    background: #fff;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

textarea {
    min-height: 96px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #8aaef8;
    box-shadow: 0 0 0 4px rgba(61, 130, 245, .10);
}

label span,
.field-label {
    display: block;
    margin: 0 0 8px;
    color: #233554;
    font-weight: 700;
}

label em {
    color: #8ea0bb;
    font-style: normal;
    font-weight: 500;
}

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

.center {
    text-align: center;
}

.login-page {
    min-height: 100vh;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 24px;
    padding: 42px 18px;
    background: radial-gradient(circle at 50% 0, #fff 0, #f4f7fb 45%, #eef3f8 100%);
}

.login-card,
.query-card,
.panel {
    width: min(100%, 650px);
    border-radius: 16px;
    background: var(--panel);
    box-shadow: var(--shadow);
    border: 1px solid rgba(220, 228, 241, .75);
}

.login-card {
    padding: 40px;
}

.admin-login-card {
    max-width: 560px;
}

.query-card {
    padding: 24px 30px;
}

.brand-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 28px;
    background: linear-gradient(135deg, #3d82f5, #8a55ef);
}

.brand-icon.admin {
    background: linear-gradient(135deg, #ec3fa7, #8a55ef);
}

.login-card h1,
.query-card h2 {
    margin: 0;
    text-align: center;
}

.login-card h1 {
    font-size: 27px;
    line-height: 1.2;
}

.login-subtitle {
    margin: 12px 0 30px;
    color: #46627f;
    text-align: center;
    font-size: 16px;
}

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

.inline-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    margin-top: 12px;
}

.admin-shell,
.editor-shell {
    width: min(1120px, calc(100vw - 32px));
    margin: 0 auto;
    padding: 30px 0 54px;
    display: grid;
    gap: 18px;
}

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

.topbar h1,
.topbar p {
    margin: 0;
}

.topbar p {
    margin-top: 4px;
    color: var(--muted);
}

.panel {
    width: 100%;
    padding: 24px 28px;
    box-shadow: 0 8px 24px rgba(20, 35, 70, .06);
}

.section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.section-head.compact {
    margin-bottom: 12px;
}

.section-head h1,
.section-head h2,
.panel h2 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.section-head p,
.panel > p {
    margin: 6px 0 0;
}

.head-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.settings-form {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.nav-link-box {
    margin-top: 18px;
    padding: 16px;
    border-radius: 12px;
    background: #f7f9fc;
    border: 1px solid #edf1f7;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: #8ea0bb;
}

.nav-link-box strong {
    color: #ff4fa3;
    word-break: break-all;
}

.generate-form {
    display: grid;
    grid-template-columns: 110px 100px auto;
    align-items: end;
    gap: 10px;
}

.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
}

.data-table th,
.data-table td {
    padding: 13px 10px;
    border-bottom: 1px solid #edf1f7;
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: #64748b;
    font-size: 13px;
    background: #f8fafc;
}

.copy-line,
.actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.actions form {
    margin: 0;
}

.actions select {
    min-height: 34px;
    padding: 5px 9px;
}

.status-pill,
.tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    padding: 3px 9px;
    font-size: 12px;
    font-weight: 800;
}

.status-unused {
    color: #7c5b00;
    background: #fff4c5;
}

.status-active {
    color: #057a45;
    background: #dff9eb;
}

.status-disabled {
    color: #b42318;
    background: #feeceb;
}

.tag {
    color: var(--pink);
    background: #ffe8f4;
}

.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.mini-form,
.simple-row {
    display: grid;
    grid-template-columns: 1fr 1.2fr 80px auto auto;
    gap: 8px;
    align-items: center;
}

.simple-list,
.banner-admin-list {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.check-line {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #334155;
    white-space: nowrap;
}

.check-line input {
    width: 16px;
    min-height: 16px;
    accent-color: #3d82f5;
}

.file-chip {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 8px;
    padding: 8px 12px;
    color: #46627f;
    background: #eef3fa;
    font-weight: 700;
    cursor: pointer;
}

.file-chip input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.file-chip.wide {
    width: fit-content;
}

.banner-admin-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.banner-admin-form input[name="url"],
.banner-admin-form input[name="image_url"] {
    grid-column: span 2;
}

.banner-admin-row {
    display: grid;
    grid-template-columns: 86px 1fr 78px auto auto auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border-radius: 12px;
    background: #f8fafc;
}

.thumb,
.banner-thumb,
.module-thumb {
    background: #eef3fa;
    color: #9aacbf;
    display: grid;
    place-items: center;
    overflow: hidden;
}

.thumb {
    width: 86px;
    height: 58px;
    border-radius: 8px;
}

.thumb img,
.banner-thumb img,
.module-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.banner-admin-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}

.stat-card {
    min-height: 78px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 12px;
}

.stat-card span {
    font-weight: 700;
    font-size: 13px;
}

.stat-card strong {
    display: block;
    font-size: 28px;
    line-height: 1;
}

.stat-card.blue {
    color: #2563eb;
    background: #e8f2ff;
}

.stat-card.green {
    color: #16a34a;
    background: #e8faef;
}

.stat-card.violet {
    color: #8a35d8;
    background: #f3e8ff;
}

.stat-card.amber {
    color: #d97706;
    background: #fff5cf;
}

.chart-wrap {
    margin-top: 18px;
    padding: 14px 18px 10px;
    border-radius: 12px;
    background: #f8fafc;
}

.chart-title {
    display: block;
    color: #8ea0bb;
    margin-bottom: 8px;
}

.bar-chart {
    height: 132px;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    align-items: end;
    gap: 10px;
}

.bar-item {
    min-width: 0;
    display: grid;
    justify-items: center;
    align-items: end;
    gap: 2px;
}

.bar {
    width: 28px;
    border-radius: 5px 5px 0 0;
    background: #5ca0f3;
}

.bar.today {
    background: #f45aa9;
}

.bar-value {
    color: #5f7ea6;
    font-weight: 800;
    line-height: 1;
}

.bar-label {
    color: #8ea0bb;
    font-size: 12px;
}

.friend-link-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.friend-link {
    border: 1px solid #cdd9ff;
    border-radius: 8px;
    padding: 6px 12px;
    color: #3559e0;
    background: #f2f5ff;
}

.banner-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-top: 12px;
}

.banner-item {
    min-width: 0;
    display: grid;
    grid-template-columns: 116px 1fr;
    gap: 12px;
    align-items: center;
    padding: 10px;
    border: 1px solid #e3e9f2;
    border-radius: 12px;
    background: #f8fafc;
}

.banner-thumb {
    height: 64px;
    border-radius: 8px;
}

.banner-item strong,
.banner-item p,
.banner-item span {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.banner-item p {
    margin: 2px 0;
    color: #7b8aa5;
}

.banner-item span {
    color: #ff4fa3;
}

.module-list {
    display: grid;
    gap: 12px;
}

.module-row {
    min-height: 88px;
    display: grid;
    grid-template-columns: 34px 110px 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 14px;
    border-radius: 12px;
    background: #f8fafc;
    transition: box-shadow .15s ease, transform .15s ease, opacity .15s ease;
}

.module-row.is-hidden {
    opacity: .65;
}

.module-row.is-dragging {
    opacity: .55;
    transform: scale(.995);
    box-shadow: 0 14px 28px rgba(20, 35, 70, .14);
}

.module-list.is-saving .module-row {
    pointer-events: none;
}

.drag-handle {
    width: 34px;
    height: 54px;
    border: 0;
    border-radius: 8px;
    display: grid;
    place-items: center;
    color: #9aacbf;
    background: #eef3fa;
    cursor: grab;
    touch-action: none;
}

.drag-handle:active {
    cursor: grabbing;
}

.sort-save-status {
    min-width: 72px;
    align-self: center;
    color: #8ea0bb;
    font-size: 13px;
    font-weight: 700;
    text-align: right;
}

.sort-save-status.is-ok {
    color: #16a34a;
}

.sort-save-status.is-error {
    color: var(--danger);
}

.module-thumb {
    width: 100px;
    height: 60px;
    border-radius: 8px;
}

.module-info {
    min-width: 0;
}

.module-info > div {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.module-info strong,
.module-info p {
    min-width: 0;
    overflow-wrap: anywhere;
}

.module-info p {
    margin: 4px 0;
    color: #52657f;
}

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

.empty-row,
.empty-state,
.public-empty {
    text-align: center;
    color: var(--muted);
    padding: 30px;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal.is-open {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .58);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(560px, 100%);
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    border-radius: 16px;
    padding: 24px;
    background: #fff;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
    display: grid;
    gap: 12px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-head h2 {
    margin: 0;
}

.type-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.type-option input {
    position: absolute;
    opacity: 0;
}

.type-option span {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    color: #111827;
    background: #fff;
    cursor: pointer;
}

.type-option input:checked + span {
    border-color: #ff56aa;
    color: #c3227a;
    background: #fff0f7;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.rich-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.rich-toolbar button {
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 5px 10px;
    color: #30405f;
    background: #f8fafc;
    font-weight: 700;
}

.rich-editor {
    min-height: 150px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    outline: none;
    background: #fff;
    overflow-wrap: anywhere;
}

.rich-editor:focus {
    border-color: #8aaef8;
    box-shadow: 0 0 0 4px rgba(61, 130, 245, .10);
}

.rich-editor:empty::before {
    content: attr(data-placeholder);
    color: #9aacbf;
}

.visible-check {
    margin-top: 4px;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.public-shell {
    min-height: 100vh;
    padding: 28px 12px;
    background:
        radial-gradient(circle at top, rgba(59, 130, 246, .10), transparent 36%),
        #eef3f8;
    display: flex;
    justify-content: center;
}

.phone-page {
    width: min(402px, 100%);
    min-height: 720px;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 30px rgba(20, 35, 70, .12);
}

.phone-top {
    min-height: 48px;
    display: grid;
    place-items: center;
    padding: 10px;
    color: #1d4ed8;
    font-size: 18px;
    font-weight: 900;
    background: #fff;
    border-bottom: 1px solid #e5edf7;
}

.phone-body {
    flex: 1;
    display: grid;
    align-content: start;
    gap: 12px;
    padding: 18px 12px 20px;
    background: linear-gradient(180deg, #f8fafc 0, #eef4fb 100%);
}

.public-module {
    color: inherit;
    display: block;
}

.public-module img {
    width: 100%;
    border: 1px solid #e3e9f2;
    border-radius: 10px;
    box-shadow: 0 8px 18px rgba(20, 35, 70, .08);
    object-fit: cover;
}

.public-caption {
    margin-top: 8px;
    padding: 9px 12px;
    border-radius: 8px;
    color: #263241;
    text-align: center;
    background: #fff;
    border: 1px solid #e3e9f2;
    box-shadow: 0 6px 14px rgba(20, 35, 70, .06);
}

.public-caption strong,
.public-caption span {
    display: block;
    overflow-wrap: anywhere;
}

.info-card {
    border-radius: 10px;
    padding: 14px 16px;
    text-align: center;
    color: #263241;
    background: #fff;
    border: 1px solid #e3e9f2;
    box-shadow: 0 6px 14px rgba(20, 35, 70, .06);
    overflow-wrap: anywhere;
}

.info-card h2 {
    margin: 0 0 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    font-size: 17px;
}

.rich-content {
    text-align: left;
}

.rich-content p,
.rich-content ul,
.rich-content ol,
.rich-content blockquote,
.rich-content h3,
.rich-content h4 {
    margin: 8px 0 0;
}

.rich-content ul,
.rich-content ol {
    padding-left: 20px;
}

.rich-content a {
    color: #2563eb;
    font-weight: 800;
    text-decoration: underline;
}

.info-card p {
    margin: 0;
    white-space: normal;
}

.phone-footer {
    padding: 18px 12px 30px;
    color: #64748b;
    text-align: center;
    font-size: 12px;
    background: #f8fafc;
    border-top: 1px solid #e5edf7;
}

.phone-footer a {
    color: #475569;
    text-decoration: none;
}

.phone-footer a:hover {
    color: #1d4ed8;
}

@media (max-width: 920px) {
    .admin-grid,
    .settings-form,
    .stats-grid,
    .banner-list {
        grid-template-columns: 1fr;
    }

    .section-head,
    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .generate-form,
    .mini-form,
    .simple-row,
    .banner-admin-form,
    .banner-admin-row {
        grid-template-columns: 1fr;
    }

    .banner-admin-form input[name="url"],
    .banner-admin-form input[name="image_url"] {
        grid-column: auto;
    }
}

@media (max-width: 640px) {
    .login-card {
        padding: 30px 22px;
    }

    .query-card {
        padding: 22px;
    }

    .inline-form,
    .type-grid,
    .two-col {
        grid-template-columns: 1fr;
    }

    .admin-shell,
    .editor-shell {
        width: min(100% - 20px, 1120px);
        padding-top: 14px;
    }

    .panel {
        padding: 18px;
        border-radius: 12px;
    }

    .nav-link-box {
        align-items: stretch;
        flex-direction: column;
    }

    .module-row {
        grid-template-columns: 34px 76px 1fr;
    }

    .module-thumb {
        width: 72px;
        height: 54px;
    }

    .module-actions {
        grid-column: 1 / -1;
        justify-content: flex-end;
    }

    .banner-item {
        grid-template-columns: 86px 1fr;
    }

    .flash-stack {
        left: 12px;
        right: 12px;
        top: 12px;
    }
}
