:root {
    --bg: #f8f9fa;
    --text: #333;
    --card-bg: white;
    --card-shadow: 0 2px 4px rgba(0,0,0,0.05);
    --card-hover: 0 4px 8px rgba(0,0,0,0.1);
    --muted: #6c757d;
    --detail: #495057;
    --badge-gray-bg: #f1f3f5; --badge-gray: #495057;
    --badge-green-bg: #ebfbee; --badge-green: #2b8a3e;
    --badge-yellow-bg: #fff9db; --badge-yellow: #e67700;
    --badge-red-bg: #fff5f5; --badge-red: #c92a2a;
    --bar-bg: #e9ecef;
    --border-warn: #e67700;
    --border-danger: #c92a2a;
    --spark-stroke: #2b8a3e;
    --popup-bg: white;
    --popup-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.dark {
    --bg: #1a1a1a;
    --text: #e9ecef;
    --card-bg: #2d2d2d;
    --card-shadow: 0 2px 4px rgba(0,0,0,0.2);
    --card-hover: 0 4px 8px rgba(0,0,0,0.3);
    --muted: #adb5bd;
    --detail: #ced4da;
    --badge-gray-bg: #495057; --badge-gray: #e9ecef;
    --badge-green-bg: #2b8a3e; --badge-green: #ebfbee;
    --badge-yellow-bg: #e67700; --badge-yellow: #fff9db;
    --badge-red-bg: #c92a2a; --badge-red: #fff5f5;
    --bar-bg: #495057;
    --border-warn: #e67700;
    --border-danger: #ff6b6b;
    --spark-stroke: #51cf66;
    --popup-bg: #363636;
    --popup-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; }

body { background: var(--bg); color: var(--text); line-height: 1.6; padding: 20px;
    transition: background .3s, color .3s; }

.container { max-width: 1200px; margin: 0 auto; }

header { margin-bottom: 24px; display: flex; justify-content: space-between; align-items: flex-start; }
.header-left { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; margin-top: 2px; }
h1 { font-size: 24px; font-weight: 600; }
.summary { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hdr-btn { background: none; border: 1px solid var(--bar-bg); cursor: pointer; font-size: 11px;
    padding: 3px 7px; border-radius: 6px; transition: background .2s, border-color .2s;
    line-height: 1; font-weight: 700; color: var(--muted); letter-spacing: .5px; }
.hdr-btn:hover { background: var(--bar-bg); border-color: var(--muted); }
.add-btn { background: rgba(34,139,230,.08); border-color: rgba(34,139,230,.3); color: #228be6; display: none; }
.add-btn:hover { background: rgba(34,139,230,.15); border-color: rgba(34,139,230,.5); }

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

.host-card { background: var(--card-bg); border-radius: 8px; padding: 10px 15px;
    box-shadow: var(--card-shadow); cursor: pointer; height: 44px; overflow: hidden;
    transition: height .3s ease, transform .2s ease, box-shadow .2s ease, background .3s, border-color .3s;
    border-left: 3px solid transparent; }
.host-card:hover { transform: translateY(-2px); box-shadow: var(--card-hover); }
.host-card.expanded { height: auto; padding-bottom: 15px; }
.host-card.warn { border-left-color: var(--border-warn); }
.host-card.danger { border-left-color: var(--border-danger); }

.host-header { display: flex; justify-content: space-between; align-items: center; height: 24px; }
.host-name { display: flex; align-items: center; font-weight: 500; font-size: 15px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.host-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.ping-val { font-size: 12px; color: var(--muted); font-weight: 400; }
.ping-val.good { color: var(--badge-green); }
.ping-val.mid { color: var(--badge-yellow); }
.ping-val.bad { color: var(--badge-red); }

.warn-icon { display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; cursor: pointer; transition: transform .15s; flex-shrink: 0;
    animation: warnGlow 2.5s ease-in-out infinite; }
.warn-icon:hover { transform: scale(1.2); }
.warn-icon svg { display: block; width: 100%; height: 100%; }

@keyframes warnGlow {
    0%, 100% { filter: drop-shadow(0 0 0 rgba(230,119,0,0)); }
    50% { filter: drop-shadow(0 0 4px rgba(230,119,0,0.5)); }
}

.flag { width: 20px; height: 15px; margin-right: 8px; border-radius: 2px;
    display: inline-block; background-size: cover; background-position: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1); flex-shrink: 0; }
.flag.unknown { background-color: var(--badge-gray-bg); }

.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-gray { background: #adb5bd; }
.dot-green { background: #2b8a3e; animation: pulse 2s ease-in-out infinite; }
.dot-yellow { background: #e67700; animation: pulseYellow 2s ease-in-out infinite; }
.dot-red { background: #c92a2a; animation: pulseRed 2s ease-in-out infinite; }

.host-details { font-size: 13px; color: var(--detail); margin-top: 10px; display: none; }
.host-card.expanded .host-details { display: block; }
.host-details div { margin-bottom: 4px; }
.detail-label { color: var(--muted); margin-right: 4px; }

.detail-row-copy { display: flex; align-items: center; gap: 2px; }
.copy-btn { background: none; border: none; cursor: pointer; color: var(--muted); padding: 2px 4px;
    border-radius: 4px; display: inline-flex; align-items: center; justify-content: center;
    opacity: .35; transition: opacity .15s, color .15s, background .15s; flex-shrink: 0; line-height: 1; }
.copy-btn:hover { opacity: 1; background: var(--bar-bg); }
.copy-btn.copied { opacity: 1; color: var(--badge-green); }

.subnet-bar { height: 5px; border-radius: 3px; background: var(--bar-bg); margin-top: 5px; overflow: hidden; }
.subnet-fill { height: 100%; border-radius: 3px; transition: width .5s ease; }
.fill-green { background: #2b8a3e; } .fill-yellow { background: #e67700; }
.fill-red { background: #c92a2a; } .fill-gray { background: #adb5bd; }

.sparkline { display: inline-block; vertical-align: middle; margin-left: 4px; }
.sparkline svg { display: block; }

.badge { padding: 3px 8px; border-radius: 12px; font-size: 12px;
    font-weight: 500; }
.bg-gray { background: var(--badge-gray-bg); color: var(--badge-gray); }
.bg-green { background: var(--badge-green-bg); color: var(--badge-green); }
.bg-yellow { background: var(--badge-yellow-bg); color: var(--badge-yellow); }
.bg-red { background: var(--badge-red-bg); color: var(--badge-red); }

.footer { text-align: center; margin-top: 24px; font-size: 13px; color: var(--muted); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); grid-column: 1 / -1; }

.popup-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4); z-index: 999; animation: fadeIn .15s ease; }
.popup-box { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: var(--popup-bg); border-radius: 12px; padding: 20px 24px;
    box-shadow: var(--popup-shadow); z-index: 1000; max-width: 380px; width: 90%;
    animation: popupIn .2s ease; }
.popup-box h3 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.popup-box p { margin: 0; font-size: 13px; line-height: 1.6; color: var(--detail); }
.popup-box input[type="text"] { width: 100%; padding: 8px 12px; border: 1px solid var(--bar-bg); border-radius: 6px;
    background: var(--bg); color: var(--text); font-size: 14px; margin: 12px 0 8px; box-sizing: border-box; outline: none; }
.popup-box input[type="text"]:focus { border-color: #228be6; }
.popup-btn { padding: 8px; border: none; border-radius: 6px; font-size: 14px; cursor: pointer; font-weight: 600; }
.popup-box .submit-btn { width: 100%; background: #228be6; color: #fff; }
.popup-box .submit-btn:hover { background: #1c7ed6; }
.popup-box .submit-btn:disabled { opacity: .6; cursor: default; }
.popup-box .err-msg { color: #e03131; font-size: 12px; margin-bottom: 8px; display: none; }
.content-check-block { margin: 10px 0; padding: 10px 12px; background: var(--bg); border-radius: 6px; }
.content-check-block input[type="text"] { margin: 4px 0 0; }
.popup-box .btn-row { display: flex; gap: 8px; margin-top: 12px; }
.popup-box .btn-row button { flex: 1; }
.popup-box .btn-cancel { background: var(--bar-bg); color: var(--text); }
.popup-box .btn-danger { background: #e03131; color: #fff; }
.popup-box .btn-danger:hover { background: #c92a2a; }
.card-foot { display: none; align-items: center; justify-content: space-between; margin-top: 8px; }
.host-card.expanded .card-foot { display: flex; }
.card-act { width: 26px; height: 26px; border: none; border-radius: 6px;
    background: rgba(133,133,133,0.07); cursor: pointer; padding: 0;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    transition: background .15s, color .15s; font-size: 14px; color: var(--muted); line-height: 1; }
.card-act:hover { background: rgba(133,133,133,0.18); color: var(--text); }
.card-act.act-del:hover { background: rgba(224,49,49,0.18); color: #e03131; }
.del-btn { width: 26px; height: 26px; border: none; border-radius: 6px;
    background: rgba(224,49,49,0.07); cursor: pointer; padding: 0;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    transition: background .15s; font-size: 14px; color: var(--muted); line-height: 1; }
.del-btn:hover { background: rgba(224,49,49,0.18); color: #e03131; }
.or-sep { color: var(--muted); font-size: 13px; margin: 12px 0; font-weight: 600; letter-spacing: 2px; }
.inc-list { margin-top: 6px; max-height: 120px; overflow-y: auto; }
.inc-row { display: flex; align-items: center; font-size: 12px; padding: 2px 0; gap: 6px; }
.inc-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; flex-shrink: 0; animation: none !important; }
.inc-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inc-time { color: var(--muted); font-size: 11px; white-space: nowrap; flex-shrink: 0; }
.host-card[draggable="true"] { cursor: grab; }
.host-card[draggable="true"]:active { cursor: grabbing; }
.host-card.drag-over { border-top: 2px solid #228be6; margin-top: -2px; }
.add-web-btn { display: inline-block; padding: 8px 20px; border: 1px solid var(--bar-bg);
    border-radius: 6px; color: var(--muted); text-decoration: none; background: var(--card-bg); font-size: 13px; }
.add-web-btn:hover { background: rgba(34,139,230,.08); color: #228be6; border-color: rgba(34,139,230,.3); }

@keyframes popupIn { from { opacity:0; transform:translate(-50%,-45%); } to { opacity:1; transform:translate(-50%,-50%); } }

@keyframes pulse {
    0%   { box-shadow: 0 0 0 0 rgba(43,138,62,.6); }
    70%  { box-shadow: 0 0 0 8px rgba(43,138,62,0); }
    100% { box-shadow: 0 0 0 0 rgba(43,138,62,0); }
}
@keyframes pulseYellow {
    0%   { box-shadow: 0 0 0 0 rgba(230,119,0,.6); }
    70%  { box-shadow: 0 0 0 8px rgba(230,119,0,0); }
    100% { box-shadow: 0 0 0 0 rgba(230,119,0,0); }
}
@keyframes pulseRed {
    0%   { box-shadow: 0 0 0 0 rgba(201,42,42,.6); }
    70%  { box-shadow: 0 0 0 8px rgba(201,42,42,0); }
    100% { box-shadow: 0 0 0 0 rgba(201,42,42,0); }
}

@keyframes fadeIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } }
.fade-in { animation: fadeIn .3s ease forwards; }

@media (max-width: 768px) {
    .hosts-grid { grid-template-columns: 1fr; }
    .header-left { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* Серый стиль для хостов офлайн >24ч */
.host-card.long-offline {
    opacity: 0.4;
    filter: grayscale(70%);
}

/* Калькулятор покупки хостов */
.price-calc { margin: 16px 0; }
.price-calc-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.price-calc-label { font-size: 14px; font-weight: 600; }
.price-calc-controls { display: flex; align-items: center; gap: 12px; }
.price-calc-btn { width: 36px; height: 36px; border: 1px solid var(--bar-bg); background: var(--card-bg);
    color: var(--text); border-radius: 6px; font-size: 20px; font-weight: 600; cursor: pointer;
    display: flex; align-items: center; justify-content: center; transition: background .15s, border-color .15s; }
.price-calc-btn:hover { background: var(--bar-bg); border-color: var(--muted); }
.price-calc-btn:disabled { opacity: .4; cursor: default; }
.price-calc-qty { font-size: 18px; font-weight: 600; min-width: 60px; width: 60px; text-align: center;
    border: 1px solid var(--bar-bg); background: var(--card-bg); color: var(--text); border-radius: 6px;
    padding: 6px 8px; outline: none; transition: border-color .15s; }
.price-calc-qty:focus { border-color: #228be6; }
.price-calc-qty::-webkit-inner-spin-button, .price-calc-qty::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.price-calc-qty[type=number] { -moz-appearance: textfield; }
.price-breakdown { background: var(--bg); border-radius: 6px; padding: 12px; font-size: 13px; margin-bottom: 16px; }
.price-breakdown-row { display: flex; justify-content: space-between; margin-bottom: 6px; }
.price-breakdown-row:last-child { margin-bottom: 0; padding-top: 6px; border-top: 1px solid var(--bar-bg);
    font-weight: 600; font-size: 15px; }
.price-breakdown-label { color: var(--detail); }
.price-breakdown-value { font-weight: 500; }
.discount-badge { display: inline-block; background: var(--badge-green-bg); color: var(--badge-green);
    padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; margin-left: 6px; }
