/*
 * UI direction inspired by:
 * - tabler/tabler (GitHub): dashboard information hierarchy
 * - shadcn-ui/ui (GitHub): restrained card/form visual rhythm
 */

* {
    box-sizing: border-box;
}

:root {
    --font-ui: "Manrope", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --transition: 0.2s ease;
}

html.light-theme {
    --bg-base: #f3f6fb;
    --bg-elevated: #ffffff;
    --bg-soft: #eef3fb;
    --bg-nav: #f8faff;
    --line: #d5ddea;
    --line-strong: #c3cde0;
    --text-main: #142033;
    --text-sub: #52627e;
    --text-faint: #6e7c96;
    --accent: #1362ff;
    --accent-soft: #e8efff;
    --accent-strong: #0d51d4;
    --ok: #12845d;
    --warn: #bc6b08;
    --danger: #d64045;
    --shadow: 0 12px 34px rgba(16, 42, 95, 0.08);
}

html.dark-theme {
    --bg-base: #0e141f;
    --bg-elevated: #162031;
    --bg-soft: #131c2c;
    --bg-nav: #101a2b;
    --line: #2a3b58;
    --line-strong: #345079;
    --text-main: #e6edf9;
    --text-sub: #9eb0cb;
    --text-faint: #7f90ab;
    --accent: #5ea1ff;
    --accent-soft: #1b3359;
    --accent-strong: #86b8ff;
    --ok: #39c497;
    --warn: #ffb347;
    --danger: #ff6f75;
    --shadow: 0 20px 45px rgba(1, 8, 20, 0.4);
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font-ui);
    line-height: 1.55;
}

.background-glow {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(850px 300px at 10% -5%, rgba(19, 98, 255, 0.12), transparent 60%),
        radial-gradient(900px 320px at 100% 0%, rgba(18, 132, 93, 0.1), transparent 65%);
    z-index: 0;
}

.app-shell {
    position: relative;
    z-index: 1;
    max-width: 1440px;
    margin: 22px auto;
    padding: 0 18px 28px;
}

.app-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 14px 18px;
    margin-bottom: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    box-shadow: var(--shadow);
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-main);
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(150deg, var(--accent), #15a37b);
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.06em;
}

.brand-text {
    display: inline-flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-text strong {
    font-size: 15px;
    font-weight: 800;
}

.brand-text small {
    color: var(--text-faint);
    font-size: 11px;
    letter-spacing: 0.03em;
}

.top-nav {
    display: inline-flex;
    justify-content: center;
    gap: 8px;
}

.top-nav a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--bg-nav);
    color: var(--text-sub);
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
    transition: all var(--transition);
}

.top-nav a:hover {
    border-color: var(--line-strong);
    color: var(--text-main);
}

.top-nav a.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

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

.theme-switcher {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--bg-nav);
    color: var(--text-main);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
}

.theme-switcher:hover {
    border-color: var(--line-strong);
}

.theme-icon {
    font-size: 14px;
}

.app-main {
    display: grid;
    gap: 18px;
}

.card {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(19, 98, 255, 0.03), transparent 80%);
}

.card-body {
    padding: 18px;
}

.section-title {
    margin: 0;
    font-size: 16px;
    font-weight: 800;
}

.section-subtitle {
    margin: 3px 0 0;
    font-size: 12px;
    color: var(--text-sub);
}

.meta-text {
    font-size: 11px;
    color: var(--text-sub);
    font-weight: 600;
}

.collapsible-header {
    cursor: pointer;
    list-style: none;
}

.collapsible-header::-webkit-details-marker {
    display: none;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.status-item {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 12px;
    background: var(--bg-soft);
}

.status-item.ok {
    border-color: rgba(18, 132, 93, 0.4);
}

.status-item.fail {
    border-color: rgba(214, 64, 69, 0.4);
}

.status-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.status-title {
    font-size: 13px;
    font-weight: 700;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 46px;
    height: 22px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
}

.status-item.ok .status-pill {
    background: rgba(18, 132, 93, 0.14);
    color: var(--ok);
}

.status-item.fail .status-pill {
    background: rgba(214, 64, 69, 0.14);
    color: var(--danger);
}

.status-path {
    display: block;
    margin-top: 8px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-sub);
    word-break: break-all;
}

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

.feedback {
    border: 1px solid;
    border-radius: var(--radius-md);
    padding: 12px 14px;
    font-size: 13px;
    font-weight: 600;
}

.feedback.success {
    color: var(--ok);
    border-color: rgba(18, 132, 93, 0.35);
    background: rgba(18, 132, 93, 0.08);
}

.feedback.danger {
    color: var(--danger);
    border-color: rgba(214, 64, 69, 0.35);
    background: rgba(214, 64, 69, 0.08);
}

.header-tools {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.hidden-form {
    display: none;
    align-items: center;
}

.form-grid {
    display: grid;
    gap: 12px;
}

.form-grid-12 {
    grid-template-columns: repeat(12, minmax(0, 1fr));
}

.add-form-grid {
    align-items: end;
}

.col-12 { grid-column: span 12; }
.col-9 { grid-column: span 9; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
.col-3 { grid-column: span 3; }
.col-2 { grid-column: span 2; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    color: var(--text-sub);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 11px;
    padding: 9px 12px;
    background: var(--bg-soft);
    color: var(--text-main);
    font: inherit;
    transition: all var(--transition);
}

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

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(19, 98, 255, 0.16);
    background: var(--bg-elevated);
}

.field-hint {
    font-size: 11px;
    color: var(--text-faint);
}

.actions-end {
    justify-content: flex-end;
}

.inline-check {
    justify-content: flex-end;
}

.checkline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 11px;
    padding: 0 12px;
    background: var(--bg-soft);
    font-size: 13px;
    color: var(--text-main);
    text-transform: none;
    letter-spacing: normal;
}

.checkline input {
    width: auto;
    min-height: auto;
    margin: 0;
}

.input-group {
    display: flex;
    gap: 8px;
}

.input-group input {
    flex: 1;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: 11px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:hover {
    background: var(--accent-strong);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-secondary {
    background: var(--bg-soft);
    border-color: var(--line);
    color: var(--text-main);
}

.btn-secondary:hover {
    border-color: var(--line-strong);
    background: var(--bg-elevated);
}

.btn-ghost {
    background: transparent;
    border-color: var(--line);
    color: var(--text-sub);
}

.btn-ghost:hover {
    border-color: var(--line-strong);
    color: var(--text-main);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    filter: brightness(1.05);
}

.btn-danger-ghost {
    border-color: rgba(214, 64, 69, 0.45);
    color: var(--danger);
}

.btn-danger-ghost:hover {
    background: rgba(214, 64, 69, 0.1);
    border-color: var(--danger);
}

.btn-block {
    width: 100%;
}

.bulk-details {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-soft);
    overflow: hidden;
}

.bulk-details summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 42px;
    padding: 10px 12px;
    cursor: pointer;
    list-style: none;
    color: var(--text-main);
    font-size: 13px;
    font-weight: 700;
}

.bulk-details summary::-webkit-details-marker {
    display: none;
}

.bulk-details summary small {
    color: var(--text-sub);
    font-size: 11px;
    font-weight: 600;
}

.bulk-details summary::after {
    content: "▾";
    font-size: 13px;
    color: var(--text-sub);
    transition: transform var(--transition);
}

.bulk-details[open] summary {
    border-bottom: 1px solid var(--line);
}

.bulk-details[open] summary::after {
    transform: rotate(180deg);
}

.bulk-details-body {
    padding: 12px;
}

.bulk-details-body textarea {
    min-height: 140px;
}

.empty-state {
    display: grid;
    gap: 4px;
    padding: 20px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-md);
    background: var(--bg-soft);
}

.empty-state.compact {
    padding: 14px;
}

.empty-state h3 {
    margin: 0;
    font-size: 15px;
}

.empty-state p {
    margin: 0;
    color: var(--text-sub);
    font-size: 13px;
}

.domain-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.domain-card {
    display: grid;
    gap: 7px;
    text-decoration: none;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: linear-gradient(180deg, var(--bg-soft), transparent 90%);
    padding: 14px;
    transition: all var(--transition);
}

.domain-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.domain-name {
    color: var(--text-main);
    font-size: 14px;
    font-weight: 800;
    word-break: break-all;
}

.domain-count {
    color: var(--text-sub);
    font-size: 12px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 11px 10px;
    text-align: left;
    vertical-align: top;
    font-size: 13px;
}

th {
    background: var(--bg-soft);
    color: var(--text-sub);
    font-weight: 800;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tr:last-child td {
    border-bottom: none;
}

tr.dragging {
    opacity: 0.55;
}

.rules-table {
    border-collapse: separate;
    border-spacing: 0 8px;
    min-width: 980px;
}

.rules-table thead th {
    background: transparent;
    border-bottom: 1px solid var(--line-strong);
    padding: 8px 10px 12px;
    position: sticky;
    top: 0;
    z-index: 2;
}

.rules-table tbody td {
    background: linear-gradient(180deg, var(--bg-soft), rgba(0, 0, 0, 0) 180%);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    padding: 12px 10px;
    vertical-align: middle;
}

.rules-table tbody td:first-child {
    border-left: 1px solid var(--line);
    border-radius: 12px 0 0 12px;
}

.rules-table tbody td:last-child {
    border-right: 1px solid var(--line);
    border-radius: 0 12px 12px 0;
}

.rules-table tbody tr:hover td {
    background: var(--bg-elevated);
    border-color: var(--line-strong);
}

.rules-table tbody tr.dragging td {
    box-shadow: inset 0 0 0 1px var(--accent);
}

.rules-table .empty-cell {
    border: 1px dashed var(--line-strong);
    border-radius: 12px;
    background: var(--bg-soft);
    padding: 26px 12px;
}

.mono {
    font-family: var(--font-mono);
}

.break-word {
    overflow-wrap: anywhere;
}

.empty-cell {
    text-align: center;
    padding: 30px 12px;
    color: var(--text-sub);
}

.row-actions {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 8px;
}

.row-actions form {
    margin: 0;
}

.row-actions .btn {
    min-height: 32px;
    padding: 0 10px;
    font-size: 12px;
}

.link-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.path-text {
    display: inline-block;
    max-width: 290px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.target-text {
    display: inline-block;
    max-width: 500px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.visit-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-left: 0;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: var(--bg-elevated);
    text-decoration: none;
    color: var(--text-sub);
    font-size: 11px;
    vertical-align: middle;
}

.visit-link:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.state-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 58px;
    height: 26px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    border: 1px solid transparent;
}

.state-pill.on {
    background: rgba(18, 132, 93, 0.14);
    border-color: rgba(18, 132, 93, 0.38);
    color: var(--ok);
}

.state-pill.off {
    background: rgba(214, 64, 69, 0.14);
    border-color: rgba(214, 64, 69, 0.38);
    color: var(--danger);
}

.type-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 50px;
    height: 26px;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    background: var(--bg-elevated);
    color: var(--text-main);
}

.type-301 {
    border-color: rgba(18, 132, 93, 0.35);
    background: rgba(18, 132, 93, 0.08);
    color: var(--ok);
}

.type-302 {
    border-color: rgba(19, 98, 255, 0.35);
    background: rgba(19, 98, 255, 0.1);
    color: var(--accent);
}

.color-tag {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid var(--line);
}

.color-tag-none { background: transparent; }
.color-tag-green { background: #17b66f; }
.color-tag-red { background: #ff646c; }
.color-tag-blue { background: #2e89ff; }
.color-tag-yellow { background: #ffc94b; }
.color-tag-purple { background: #8a7bff; }

.modal {
    position: fixed;
    inset: 0;
    z-index: 999;
    background: rgba(7, 13, 24, 0.52);
    backdrop-filter: blur(3px);
}

.modal-content {
    max-width: 960px;
    width: calc(100% - 36px);
    margin: 40px auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    box-shadow: var(--shadow);
    padding: 16px;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg-soft);
    color: var(--text-main);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.icon-btn:hover {
    border-color: var(--line-strong);
}

.modal-actions {
    margin-top: 14px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.login-wrap {
    min-height: calc(100vh - 170px);
    display: grid;
    place-items: center;
}

.login-card {
    width: 100%;
    max-width: 460px;
}

.login-head {
    justify-content: flex-start;
}

.log-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 58px;
    height: 24px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.log-badge.info {
    color: #0f8bd6;
    background: rgba(15, 139, 214, 0.16);
    border-color: rgba(15, 139, 214, 0.4);
}

.log-badge.warning {
    color: var(--warn);
    background: rgba(188, 107, 8, 0.16);
    border-color: rgba(188, 107, 8, 0.4);
}

.log-badge.security {
    color: #ca4e7c;
    background: rgba(202, 78, 124, 0.14);
    border-color: rgba(202, 78, 124, 0.38);
}

.log-badge.error {
    color: var(--danger);
    background: rgba(214, 64, 69, 0.14);
    border-color: rgba(214, 64, 69, 0.38);
}

.log-badge.raw {
    color: var(--text-sub);
    background: var(--bg-soft);
    border-color: var(--line);
}

.log-context {
    max-width: 700px;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-sub);
}

@media (max-width: 1100px) {
    .col-9,
    .col-6,
    .col-8,
    .col-4,
    .col-3,
    .col-2 {
        grid-column: span 6;
    }

    .app-header {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .top-nav {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .header-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 760px) {
    .app-shell {
        margin: 14px auto;
        padding: 0 10px 20px;
    }

    .card-header,
    .card-body {
        padding: 12px;
    }

    .form-grid-12 {
        grid-template-columns: 1fr;
    }

    .col-12,
    .col-9,
    .col-6,
    .col-8,
    .col-4,
    .col-3,
    .col-2 {
        grid-column: span 1;
    }

    .header-tools {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .input-group {
        flex-direction: column;
    }

    .input-group .btn {
        width: 100%;
    }

    .rules-table {
        min-width: 0;
        border-spacing: 0;
    }

    .rules-table tbody td {
        background: transparent;
        border-top: none;
        border-bottom: 1px solid var(--line);
        padding-top: 11px;
        padding-bottom: 11px;
    }

    .rules-table tbody td:first-child,
    .rules-table tbody td:last-child {
        border-left: none;
        border-right: none;
        border-radius: 0;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr {
        border: 1px solid var(--line);
        border-radius: 12px;
        margin-bottom: 10px;
        overflow: hidden;
    }

    td {
        position: relative;
        border-bottom: 1px solid var(--line);
        padding: 11px 10px 11px 42%;
        min-height: 40px;
        text-align: right;
    }

    td:last-child {
        border-bottom: none;
    }

    td::before {
        content: attr(data-label);
        position: absolute;
        left: 10px;
        top: 11px;
        width: 35%;
        color: var(--text-sub);
        font-size: 11px;
        font-weight: 700;
        text-align: left;
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }

    td[data-label="操作"] {
        padding-left: 10px;
        text-align: left;
    }

    td[data-label="操作"]::before {
        display: none;
    }

    .row-actions {
        width: 100%;
    }

    .row-actions .btn {
        flex: 1;
    }

    .link-cell {
        justify-content: flex-end;
        gap: 6px;
    }

    .path-text,
    .target-text {
        max-width: 100%;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        word-break: break-word;
    }

    .modal-content {
        width: calc(100% - 16px);
        margin: 18px auto;
        padding: 10px;
    }
}
