/* ============================================================
   NETWATCH — design tokens (compact, full-width, mobile-first)
   Palette: deep signal-room navy, cool surfaces, three status hues
   Type: JetBrains Mono for data/brand, Inter for reading text
   Signature: radar-pulse status dot on live/"up" rows
   ============================================================ */
:root {
    --bg-deep:      #0A0E14;
    --surface:      #121826;
    --surface-2:    #1A2233;
    --border:       #232C40;
    --text:         #E7ECF5;
    --text-muted:   #8592A8;
    --text-faint:   #56617A;

    --accent:       #4C8DFF;
    --accent-dim:   #274475;

    --up:           #35D07F;
    --up-dim:       #113322;
    --down:         #FF5C6C;
    --down-dim:     #3A1418;
    --warn:         #FFB454;
    --warn-dim:     #3A2A10;

    --mono: 'JetBrains Mono', 'Noto Sans Georgian', ui-monospace, monospace;
    --sans: 'Inter', 'Noto Sans Georgian', system-ui, -apple-system, sans-serif;

    --radius: 8px;
    --gutter: clamp(12px, 2.5vw, 28px);
}

[data-theme="light"] {
    --bg-deep:      #F3F5F9;
    --surface:      #FFFFFF;
    --surface-2:    #F0F3F8;
    --border:       #DBE1EB;
    --text:         #16202E;
    --text-muted:   #5B6B85;
    --text-faint:   #97A3B8;

    --accent:       #2F6FE0;
    --accent-dim:   #DCE8FF;

    --up:           #1B9C63;
    --up-dim:       #DEF5E9;
    --down:         #E23F51;
    --down-dim:     #FCE4E6;
    --warn:         #C97B0F;
    --warn-dim:     #FCF0DC;
}

* { box-sizing: border-box; }
input, select, textarea, button { max-width: 100%; }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

html, body {
    margin: 0;
    background: var(--bg-deep);
    background-image:
        radial-gradient(circle at 12% 0%, rgba(76,141,255,0.08), transparent 45%),
        radial-gradient(circle at 88% 8%, rgba(53,208,127,0.05), transparent 40%);
    color: var(--text);
    font-family: var(--sans);
    line-height: 1.45;
    min-height: 100vh;
    font-size: 14px;
    overflow-x: hidden;
    max-width: 100vw;
}

[data-theme="light"] html, [data-theme="light"] body, html[data-theme="light"], body[data-theme="light"] {
    background-image:
        radial-gradient(circle at 12% 0%, rgba(47,111,224,0.05), transparent 45%),
        radial-gradient(circle at 88% 8%, rgba(27,156,99,0.04), transparent 40%);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- top bar ---------- */
.topbar {
    border-bottom: 1px solid var(--border);
    background: rgba(10, 14, 20, 0.85);
    backdrop-filter: blur(6px);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-inner {
    width: 100%;
    margin: 0;
    padding: 10px var(--gutter);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}
.brand { display: flex; align-items: center; gap: 8px; }
.topbar-left-group { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0; }
.status-badge-row { display: flex; flex-wrap: wrap; gap: 5px; }
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 9px;
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    line-height: 1.3;
    border: 1px solid transparent;
}
.status-badge:hover { text-decoration: none; filter: brightness(1.15); }
.badge-icon { font-size: 10px; opacity: 0.9; }
.badge-active { border-color: currentColor; }
.badge-down { background: rgba(240, 90, 90, 0.16); color: var(--down); }
.badge-up { background: rgba(60, 190, 120, 0.16); color: var(--up); }
.badge-unknown { background: rgba(154, 164, 178, 0.14); color: var(--text-faint); }
.badge-total { background: var(--surface-2); color: var(--text-muted); }
.badge-paused { background: rgba(77, 141, 255, 0.16); color: #6fa8ff; }
.badge-reminder { background: rgba(240, 180, 80, 0.16); color: var(--warn); }
.brand-mark {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--up);
    box-shadow: 0 0 0 0 rgba(53,208,127,0.6);
    animation: brand-pulse 2.4s ease-out infinite;
    flex-shrink: 0;
}
@keyframes brand-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(53,208,127,0.55); }
    70%  { box-shadow: 0 0 0 9px rgba(53,208,127,0); }
    100% { box-shadow: 0 0 0 0 rgba(53,208,127,0); }
}
.brand-text {
    font-family: var(--mono);
    letter-spacing: 0.06em;
    font-size: 13px;
    color: var(--text);
}
.brand-text b { color: var(--accent); font-weight: 700; }
.sync-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 2px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
    border-top-color: var(--text-muted);
    opacity: 0.7;
    transition: opacity 0.2s ease;
    flex-shrink: 0;
}
.sync-indicator.syncing {
    opacity: 1;
    border-color: var(--accent);
    border-top-color: transparent;
    animation: sync-spin 0.7s linear infinite;
}
@keyframes sync-spin {
    to { transform: rotate(360deg); }
}
.topnav { display: flex; gap: 8px; align-items: center; font-size: 13px; flex-wrap: wrap; }
.topnav-btn {
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 7px 13px;
    font-size: 12.5px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    background: var(--surface);
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
    white-space: nowrap;
}
.topnav-btn:hover { color: var(--text); border-color: var(--accent); text-decoration: none; background: var(--surface-2); }
.topnav-active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.topnav-active:hover { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.topnav-danger { border-color: rgba(255,92,108,0.3); color: var(--down); }
.topnav-danger:hover { color: #ff8a95 !important; border-color: var(--down); background: var(--down-dim); }

.topnav-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 9px;
    font-size: 17px;
    line-height: 1;
    text-decoration: none;
    border: none;
    cursor: pointer;
    color: #fff;
    flex-shrink: 0;
    transition: filter 0.15s ease, transform 0.1s ease;
}
.topnav-icon-btn:hover { filter: brightness(1.18); text-decoration: none; color: #fff; }
.topnav-icon-btn:active { transform: scale(0.94); }
.topnav-icon-btn.topnav-active { box-shadow: inset 0 0 0 2px rgba(255,255,255,0.65); }
.tnib-theme     { background: #d6336c; }
.tnib-logo      { background: #7cb305; }
.tnib-home      { background: #e03131; }
.tnib-add       { background: #2f9e44; }
.tnib-groups    { background: #495057; }
.tnib-structure { background: #495057; }
.tnib-archive   { background: #1971c2; }
.tnib-shares    { background: #f08c00; }
.tnib-trash     { background: #7048e8; }
.tnib-users     { background: #ae3ec9; }
.tnib-account   { background: #e64980; }
.tnib-add-reminder { background: #f59f00; }
.tnib-crm       { background: #0c8599; }
.tnib-navback, .tnib-navforward { background: #4263eb; }

/* ---------- ძებნის ველი (topbar-ში, ყველა გვერდზე) ---------- */
.dash-search-wrap {
    position: relative;
    max-width: 420px;
    margin-bottom: 16px;
}
.dash-search-wrap.topbar-search {
    max-width: none;
    flex: 1 1 200px;
    min-width: 120px;
    margin: 0 4px;
}
.dash-search-wrap svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); pointer-events: none; opacity: 0.5; }
.dash-search-input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    padding: 10px 34px 10px 34px;
    border-radius: var(--radius);
    outline: none;
    box-sizing: border-box;
}
.dash-search-input:focus { border-color: var(--accent); }
.dash-search-input::placeholder { color: var(--text-faint); }
.dash-search-clear {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-faint); cursor: pointer;
    font-size: 16px; line-height: 1; padding: 4px 6px; display: none;
}
.dash-search-clear:hover { color: var(--text); }
.tnib-logout    { background: #e8590c; }

/* ---------- layout (full-width, fluid) ---------- */
.page { width: 100%; margin: 0; padding: 18px var(--gutter) 40px; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}
.page-head h1 {
    font-family: var(--mono);
    font-size: 18px;
    margin: 0 0 3px;
    letter-spacing: 0.01em;
}
.page-head p { margin: 0; color: var(--text-muted); font-size: 12.5px; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--accent);
    color: #051022;
    border: none;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.15s ease;
    white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-danger { background: var(--down); color: #2a0c0f; }

/* ---------- summary strip ---------- */
.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}
.stat-card .num {
    font-family: var(--mono);
    font-size: 20px;
    font-weight: 700;
    line-height: 1.1;
}
.stat-card .label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}
.stat-up .num { color: var(--up); }
.stat-down .num { color: var(--down); }
.stat-warn .num { color: var(--warn); }

/* ---------- device table ---------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; font-size: 12.5px; }
thead th {
    font-family: var(--mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    white-space: nowrap;
}
thead th:first-child { border-top-left-radius: var(--radius); }
thead th:last-child { border-top-right-radius: var(--radius); }
tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.12s ease; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td .device-name { font-weight: 600; }
td .device-ip { font-family: var(--mono); color: var(--text-muted); font-size: 11.5px; }

/* status pill + radar pulse dot */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px 3px 7px;
    border-radius: 999px;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.status-up   { background: var(--up-dim);   color: var(--up); }
.status-down { background: var(--down-dim); color: var(--down); }
.status-unknown { background: rgba(133,146,168,0.12); color: var(--text-muted); }

.pulse-dot { position: relative; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.pulse-dot.up { background: var(--up); }
.pulse-dot.down { background: var(--down); }
.pulse-dot.unknown { background: var(--text-faint); }
.pulse-dot.up::after {
    content: '';
    position: absolute; inset: -4px;
    border-radius: 50%;
    border: 1px solid var(--up);
    animation: radar 1.8s ease-out infinite;
}
@keyframes radar {
    0%   { transform: scale(0.6); opacity: 0.9; }
    100% { transform: scale(2.4); opacity: 0; }
}

.latency-bar-track {
    width: 60px; height: 4px; border-radius: 2px;
    background: var(--surface-2); overflow: hidden;
}
.latency-bar-fill { height: 100%; border-radius: 2px; }

.uptime-num { font-family: var(--mono); font-weight: 600; }
.uptime-good { color: var(--up); }
.uptime-mid  { color: var(--warn); }
.uptime-bad  { color: var(--down); }

.row-actions { display: flex; gap: 10px; font-size: 12px; flex-wrap: wrap; }
.row-actions a { color: var(--text-muted); }
.row-actions a:hover { color: var(--accent); }
.row-actions .danger:hover { color: var(--down); }

.empty-state {
    text-align: center;
    padding: 36px 18px;
    color: var(--text-muted);
}
.empty-state h3 { color: var(--text); font-family: var(--mono); margin-bottom: 6px; font-size: 14px; }

/* ---------- forms ---------- */
.form-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    max-width: 440px;
}
.field { margin-bottom: 12px; }
.field label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 500;
}
.field input, .field select, .field textarea {
    width: 100%;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
}
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--accent);
    outline: none;
}
.field-hint { font-size: 11px; color: var(--text-faint); margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; }

.alert {
    padding: 9px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 14px;
    border: 1px solid;
}
.alert-error { background: var(--down-dim); border-color: rgba(255,92,108,0.35); color: #ffb3ba; }
.alert-success { background: var(--up-dim); border-color: rgba(53,208,127,0.35); color: #a9f0c8; }

.auth-wrap {
    max-width: 340px;
    margin: 8vh auto 0;
    padding: 0 16px;
}
.auth-wrap .form-panel { max-width: none; }
.auth-title { text-align: center; margin-bottom: 18px; }
.auth-title .brand-mark { display: inline-block; }

/* ---------- detail page ---------- */
.back-link { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; display: inline-block; }
.detail-head {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 16px; flex-wrap: wrap;
}
.detail-head h1 { font-family: var(--mono); font-size: 19px; margin: 0; }
.log-table td, .log-table th { font-family: var(--mono); font-size: 12px; }

.footer {
    width: 100%;
    margin: 0;
    padding: 14px var(--gutter) 28px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
    color: var(--text-faint);
    font-size: 11px;
}
.footer-dim code { color: var(--text-muted); }

/* ---------- group overview grid (shared class for index.php cards) ---------- */
.grp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}
.grp-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    display: block;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s ease;
}
.grp-card:hover { border-color: var(--accent); text-decoration: none; }
.grp-title {
    font-family: var(--mono);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.grp-title .arrow { color: var(--text-faint); font-weight: 400; }
.grp-stats { display: flex; gap: 14px; }
.grp-num { font-family: var(--mono); font-size: 19px; font-weight: 700; line-height: 1.1; }
.grp-lbl { font-size: 9.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.grp-up { color: var(--up); }
.grp-down { color: var(--down); }

/* ============================================================
   Responsive breakpoints
   ============================================================ */
@media (max-width: 900px) {
    .status-badge-row { width: 100%; }
    .topbar-search { width: 100%; order: 2; margin: 0; }
}

@media (max-width: 640px) {
    :root { --gutter: 12px; }
    .topbar-inner { padding: 8px var(--gutter); }
    .brand-text { font-size: 12px; }
    .status-badge-row { justify-content: flex-start; gap: 4px; }
    .status-badge { padding: 3px 7px; font-size: 11px; }
    .topnav { gap: 6px; font-size: 12px; width: 100%; justify-content: flex-start; }
    .topnav-icon-btn { width: 34px; height: 34px; font-size: 15px; border-radius: 7px; }
    .page { padding-top: 14px; }
    .page-head { flex-direction: column; align-items: stretch; }
    .page-head .btn { width: 100%; justify-content: center; }
    .stat-row { grid-template-columns: repeat(2, 1fr); }
    .grp-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
    .grp-card { padding: 8px 10px; }
    .grp-num { font-size: 16px; }
    .grp-stats { gap: 10px; }
    table, thead { display: block; }
    thead { display: none; }
    tbody { display: block; }
    tbody tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 2px 14px;
        padding: 10px 12px;
    }
    td {
        display: block;
        padding: 4px 0;
        border: none;
        font-size: 12.5px;
        width: auto;
        box-sizing: border-box;
        min-width: 0;
    }
    /* მოწყობილების სახელი, სტატუსი (პორტების სია) და ქმედებების ღილაკები — მთელ სიგანეზე */
    td:first-child, td:last-child, td[data-label="სტატუსი"] { grid-column: 1 / -1; }
    td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 10px;
        color: var(--text-faint);
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }
    .form-panel { padding: 14px; max-width: none; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; justify-content: center; }
    .auth-wrap { margin-top: 6vh; }
}

@media (max-width: 380px) {
    .stat-row { grid-template-columns: 1fr 1fr; }
}

/* მოქმედების იკონ-ღილაკები — გამოიყენება device_table.php-ში და
   device_live_area.php-ში ერთნაირი ზომით (მოწყობილება/პორტი/სენსორი) */
.row-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    border-radius: 7px;
    border: none;
    color: #fff;
    font-size: 13px;
    text-decoration: none;
    line-height: 1;
    background: #495057;
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.1s ease;
}
.row-icon-btn:hover { filter: brightness(1.18); color: #fff; text-decoration: none; }
.row-icon-btn:active { transform: scale(0.94); }

/* იგივე, მთავარი მენიუს "ფერადი კვადრატის" სტილი — მთელ საიტზე,
   ყოველ მოწყობილების/პორტის/სენსორის მწკრივზე, title-ატრიბუტის
   მიხედვით (HTML-ის შეხების გარეშე, რადგან ეს ღილაკები 3 ცალკე
   ფაილშია დუბლირებული) */
.row-icon-btn[title="შემოწმება ახლავე"] { background: #2f9e44; }
.row-icon-btn[title="ისტორია"] { background: #f59f00; }
.row-icon-btn[title="ბარათი — დამატებითი ინფო"] { background: #1971c2; }
.row-icon-btn[title="გაზიარება"] { background: #f08c00; }
.row-icon-btn[title="რედაქტირება"] { background: #495057; }
.row-icon-btn[title="ასლის შექმნა"] { background: #0c8599; }
.row-icon-btn[title="დაპაუზება"] { background: #7048e8; }
.row-icon-btn[title="გაგრძელება"] { background: #2f9e44; }
