:root {
    color-scheme: dark;
    --bg: #03110f;
    --bg2: #020807;
    --panel: rgba(11, 19, 19, .94);
    --panel2: rgba(13, 26, 26, .96);
    --input: rgba(6, 16, 16, .98);
    --line: #244442;
    --line2: rgba(96, 255, 219, .22);
    --text: #f6fff9;
    --soft: #dff7ed;
    --muted: #94aaa3;
    --accent: #35f4d0;
    --accent2: #7cff96;
    --accent-soft: rgba(53, 244, 208, .15);
    --green: #7cff96;
    --yellow: #ffd166;
    --red: #ff5d70;
    --blue: #6bd4ff;
    --shadow: 0 18px 50px rgba(0, 0, 0, .38);
    --radius: 22px;
}

body.theme-light {
    color-scheme: light;
    --bg: #eef9f6;
    --bg2: #ffffff;
    --panel: rgba(255, 255, 255, .94);
    --panel2: #ffffff;
    --input: #ffffff;
    --line: #c9e1dc;
    --line2: rgba(14, 131, 113, .20);
    --text: #10201e;
    --soft: #213936;
    --muted: #60736f;
    --accent: #0da58f;
    --accent2: #22c55e;
    --accent-soft: rgba(13, 165, 143, .12);
    --green: #16a34a;
    --yellow: #d97706;
    --red: #dc2626;
    --blue: #2563eb;
    --shadow: 0 18px 40px rgba(25, 70, 64, .12);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    font: 14px/1.45 system-ui, Segoe UI, Roboto, Arial, sans-serif;
    color: var(--text);
    background:
        radial-gradient(760px 420px at calc(100% - 64px) 42px, rgba(53, 244, 208, .15), transparent 60%),
        radial-gradient(820px 520px at 0% 0%, rgba(124, 255, 150, .10), transparent 58%),
        linear-gradient(180deg, var(--bg), var(--bg2));
}

button, input, textarea { font: inherit; }
a { color: inherit; }

.wrap { max-width: 1480px; margin: 0 auto; padding: 22px 16px 42px; }

.hero, .panel, .card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.hero { padding: 15px 15px 18px; margin-bottom: 18px; overflow: visible; position: relative; }
.topbar { position: relative; z-index: 12; display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: nowrap; margin-bottom: 0; }
.brand-corner { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.corner-logo { width: 64px; height: 64px; border: 1px solid var(--line2); border-radius: 18px; background: linear-gradient(145deg, rgba(53,244,208,.15), rgba(124,255,150,.08)); box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 12px 30px rgba(0,0,0,.20); display: grid; place-items: center; }
.corner-logo svg { width: 48px; height: 48px; }
.hero-main { position: relative; z-index: 1; text-align: center; max-width: 900px; margin: -2px auto 0; padding: 0; pointer-events: none; }
.hero-main h1 { margin: 0; font-size: clamp(28px, 4vw, 40px); line-height: 1.08; letter-spacing: -.025em; font-weight: 760; color: var(--text); }

.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.segmented { display: inline-flex; align-items: center; gap: 6px; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel2); }
.seg-btn { border: 0; background: transparent; color: var(--muted); padding: 8px 12px; border-radius: 999px; font-weight: 900; text-transform: uppercase; cursor: pointer; transition: .18s background, .18s color, .18s transform; }
.seg-btn:hover { color: var(--text); transform: translateY(-1px); }
.seg-btn.active { color: var(--text); background: var(--accent-soft); box-shadow: inset 0 0 0 1px rgba(53, 244, 208, .28); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 18px 0; flex-wrap: nowrap; }
.search-side { flex: 1 1 auto; min-width: 280px; position: relative; }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--accent); font-weight: 900; z-index: 1; }
.search-side .input { padding-left: 46px; }
.filter-side { flex: 0 0 auto; display: flex; align-items: center; justify-content: flex-end; gap: 10px; }

.input { width: 100%; min-width: 0; height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 14px; color: var(--text); background: var(--input); outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.btn { border: 1px solid var(--line); border-radius: 14px; min-height: 38px; padding: 9px 14px; color: var(--text); background: linear-gradient(180deg, var(--panel2), var(--input)); font-weight: 900; cursor: pointer; box-shadow: 0 8px 24px rgba(0,0,0,.14); transition: .18s transform, .18s border-color, .18s opacity; }
.btn:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, rgba(13,165,143,.80), rgba(14,99,87,.92)); border-color: rgba(53,244,208,.45); }
.btn.ghost { background: var(--panel2); }
.btn.danger { background: linear-gradient(135deg, rgba(168,42,58,.95), rgba(98,18,30,.96)); border-color: rgba(255,93,112,.48); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none !important; filter: grayscale(.35); }

.custom-select { position: relative; min-width: 152px; }
.custom-select.open { z-index: 50000; }
.custom-select-btn { width: 100%; height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--input); color: var(--text); font: inherit; font-weight: 850; cursor: pointer; box-shadow: none; transform: none; }
.custom-select-btn:hover { transform: none; border-color: rgba(53,244,208,.44); }
.custom-select.open .custom-select-btn { border-color: var(--accent); border-bottom-left-radius: 0; border-bottom-right-radius: 0; box-shadow: 0 0 0 4px var(--accent-soft); }
.custom-select-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.custom-select-arrow { flex: 0 0 auto; width: 12px; height: 8px; margin-right: 2px; opacity: .95; background-repeat: no-repeat; background-position: center; background-size: 12px 8px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%2335f4d0' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); transition: transform .18s ease; }
.custom-select.open .custom-select-arrow { transform: rotate(180deg); }
.custom-select-menu { position: absolute; left: 0; right: 0; top: calc(100% - 1px); z-index: 60000; max-height: 260px; overflow: auto; border: 1px solid var(--accent); border-top: 0; border-bottom-left-radius: 14px; border-bottom-right-radius: 14px; background: var(--panel2); box-shadow: 0 16px 36px rgba(0,0,0,.32); }
.custom-option { width: 100%; display: block; padding: 10px 12px; border: 0; border-radius: 0; background: transparent; color: var(--text); text-align: left; font: inherit; font-weight: 760; cursor: pointer; box-shadow: none; transform: none; }
.custom-option:hover, .custom-option:focus, .custom-option.current { background: var(--accent-soft); color: var(--text); outline: none; transform: none; }
.custom-option + .custom-option { border-top: 1px solid rgba(255,255,255,.045); }
.danger-option { color: #ffd3d8; }

.page { display: none; }
.page.active { display: block; }
.table-panel { overflow: visible; position: relative; z-index: 40; }
.table-wrap { overflow: visible; }
.table { width: 100%; border-collapse: collapse; min-width: 980px; }
.table th { font-size: 12px; text-align: left; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); background: rgba(5,14,14,.32); padding: 13px 14px; border-bottom: 1px solid var(--line); }
.table td { padding: 13px 14px; border-bottom: 1px solid rgba(128,128,128,.13); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr { position: relative; }
.table tr:has(.row-select.open) { z-index: 200; }
.domain-link { font-weight: 900; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.muted { color: var(--muted); }
.muted-row { height: 70px; text-align: center; color: var(--muted); font-size: 15px; }

.status-badge { display: inline-flex; align-items: center; gap: 8px; min-width: 98px; justify-content: center; border-radius: 999px; padding: 7px 11px; font-weight: 950; font-size: 12px; letter-spacing: .06em; border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.055); color: var(--text); box-shadow: inset 0 1px 0 rgba(255,255,255,.04); }
.status-badge:before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 12px currentColor; }
.status-idle { color: var(--green); background: rgba(124,255,150,.10); border-color: rgba(124,255,150,.23); }
.status-processing { color: var(--blue); background: rgba(107,212,255,.10); border-color: rgba(107,212,255,.24); }
.status-taken { color: #c6b7ff; background: rgba(198,183,255,.10); border-color: rgba(198,183,255,.22); }
.status-down { color: var(--red); background: rgba(255,93,112,.11); border-color: rgba(255,93,112,.28); }
.status-unknown { color: var(--yellow); background: rgba(255,209,102,.10); border-color: rgba(255,209,102,.24); }
.row-select { min-width: 170px; }
.row-select.open { z-index: 70000; }
.row-select .custom-select-btn { height: 34px; border-radius: 12px; }
.row-select .custom-option { font-size: 12px; padding: 9px 10px; }
.dev-cell { display: none; }
body[data-dev-mode="on"] .dev-cell { display: table-cell; }
.dev-option { display: none; }
body[data-dev-mode="on"] .dev-option { display: block; }

.card { padding: 18px; margin-bottom: 18px; overflow: visible; position: relative; }
.form-card { overflow: visible; }
.card-heading h2 { margin: 0 0 6px; font-size: 24px; line-height: 1.15; }
.card-heading p { margin: 0; color: var(--muted); font-size: 14px; }
.domain-form { display: grid; gap: 10px; margin-top: 16px; }
.field-label { font-weight: 900; color: var(--soft); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.input-row { display: flex; gap: 15px; align-items: center; }
.wide-row .input { height: 42px; }
.wide-row .btn { min-width: 306px; flex: 0 0 306px; height: 42px; }
.check-row { display: flex; align-items: flex-start; gap: 9px; color: var(--soft); font-weight: 760; line-height: 1.35; }
.check-row input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--accent); }
.replace-card { border-color: rgba(255,93,112,.24); }

.toast { margin: 0 0 14px; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; background: var(--panel2); color: var(--text); font-weight: 850; }
.toast.success { border-color: rgba(124,255,150,.34); background: rgba(124,255,150,.10); }
.toast.error { border-color: rgba(255,93,112,.36); background: rgba(255,93,112,.10); color: #ffe7ea; }

.dev-panel { margin-top: 18px; padding: 18px; position: relative; z-index: 2; }
.technical-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.checks-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex: 0 0 auto; }
.checks-select { min-width: 210px; }
.raw-output { margin: 18px 0 0; min-height: 170px; max-height: 420px; overflow: auto; padding: 18px; border: 1px solid var(--line); border-radius: 14px; color: var(--soft); background: rgba(2,8,8,.72); font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; }
.theme-light .raw-output { background: #f7fbfa; }

.modal-backdrop { position: fixed; inset: 0; z-index: 90000; display: grid; place-items: center; padding: 20px; background: rgba(0,0,0,.58); backdrop-filter: blur(8px); }
.modal-card { width: min(520px, 100%); border: 1px solid var(--line); border-radius: 20px; padding: 22px; background: var(--panel2); box-shadow: var(--shadow); }
.modal-card h3 { margin: 0 0 8px; font-size: 22px; }
.modal-card p { margin: 0; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

[hidden] { display: none !important; }

@media (max-width: 1120px) {
    .topbar { align-items: flex-start; flex-wrap: wrap; }
    .controls { max-width: none; }
    .hero-main { margin-top: 8px; pointer-events: auto; }
    .hero-main h1 { font-size: 34px; }
}

@media (max-width: 820px) {
    .wrap { padding: 14px 10px 32px; }
    .topbar, .toolbar, .technical-head, .input-row { flex-direction: column; align-items: stretch; }
    .brand-corner { width: auto; }
    .controls { justify-content: flex-start; }
    .filter-side, .checks-actions { width: 100%; align-items: stretch; }
    .custom-select, .checks-select { width: 100%; }
    .wide-row .btn { width: 100%; }
    .table-wrap { overflow: auto; }
}

/* v4 fixes */
.hero {
    min-height: 132px;
    padding: 16px 16px 18px;
}
.topbar {
    display: block;
    min-height: 0;
    margin: 0;
}
.brand-corner {
    position: absolute;
    left: 16px;
    top: 16px;
    min-height: 0;
    z-index: 22;
}
.controls {
    position: absolute;
    right: 16px;
    top: 18px;
    z-index: 24;
    max-width: calc(100% - 112px);
}
.corner-logo {
    width: 64px;
    height: 64px;
    overflow: hidden;
    padding: 0;
}
.corner-logo img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 18px;
}
.hero-main {
    margin: 72px auto 0;
    max-width: 760px;
    pointer-events: none;
}
.hero-main h1 {
    font-size: clamp(30px, 3.15vw, 38px);
    line-height: 1.08;
    font-weight: 780;
    letter-spacing: -0.02em;
    white-space: normal;
}

/* Dropdowns: never leave menu visible after close and always float above lower panels */
.custom-select:not(.open) > .custom-select-menu,
.row-select:not(.open) [data-action-menu],
.custom-select-menu[hidden] {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}
.custom-select.open > .custom-select-menu,
.row-select.open [data-action-menu] {
    display: block !important;
    visibility: visible !important;
    pointer-events: auto !important;
}
.table-panel {
    z-index: 300;
}
.table-wrap,
.table,
.table tbody,
.table tr,
.table td {
    overflow: visible;
}
.table tr:has(.row-select.open) {
    z-index: 900;
}
.row-select.open {
    z-index: 90000;
}
.row-select .custom-select-menu {
    z-index: 90001;
}
.dev-panel {
    z-index: 1;
}

/* Light theme table cleanup */
.theme-light .table th {
    background: linear-gradient(180deg, #edf7f4, #e7f3ef);
    color: #526a64;
    border-bottom-color: #c6ded8;
}
.theme-light .table td {
    background: rgba(255,255,255,.72);
    border-bottom-color: rgba(102, 137, 130, .18);
}
.theme-light .table tr:last-child td {
    border-bottom: 0;
}
.theme-light .table-panel {
    background: rgba(255,255,255,.96);
}
.theme-light .custom-select-menu {
    background: #ffffff;
    box-shadow: 0 18px 42px rgba(34, 70, 64, .18);
}
.theme-light .custom-option + .custom-option {
    border-top-color: rgba(13, 165, 143, .10);
}
.theme-light .danger-option {
    color: #dc2626;
}

@media (max-width: 1120px) {
    .hero {
        min-height: 184px;
    }
    .brand-corner {
        position: relative;
        left: auto;
        top: auto;
        display: inline-flex;
    }
    .controls {
        position: relative;
        right: auto;
        top: auto;
        max-width: none;
        margin-left: 0;
        margin-top: 12px;
        justify-content: flex-start;
    }
    .topbar {
        display: flex;
        align-items: flex-start;
        flex-direction: column;
        gap: 0;
    }
    .hero-main {
        margin-top: 14px;
        pointer-events: auto;
    }
    .hero-main h1 {
        font-size: 34px;
    }
}


/* v5 form stability fixes */
.wide-row { gap: 15px; }
.wide-row .input { flex: 1 1 auto; min-width: 0; }
.wide-row .btn { min-width: 306px; flex: 0 0 306px; white-space: normal; line-height: 1.15; }
@media (max-width: 820px) {
    .wide-row .btn { min-width: 0; flex: 0 0 auto; width: 100%; }
}
