/* app.css — Module 4 base styles (desktop-first, min width 1024px per R4.5.4). */

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-width: 1024px;
    overflow: hidden;
    font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f4f6f8;
    color: #1f2933;
}

/* Header */
.app-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    background: #1f2933;
    color: #ffffff;
}

.app-header h1 { margin: 0; font-size: 20px; }

.app-version { font-size: 13px; color: #9aa5b1; font-weight: 600; }

/* Banners (R4.5.2) */
.banner { padding: 6px 12px; border-radius: 4px; font-size: 14px; }
.banner-error   { background: #dc2626; color: #ffffff; }
.banner-warning { background: #f59e0b; color: #1f2933; }
.banner-success { background: #16a34a; color: #ffffff; }

.hidden { display: none !important; }

.tabs {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    width: 75%;
    min-height: 0;
    margin: 18px auto;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
}

.tab-strip {
    display: flex;
    justify-content: flex-start;
    width: calc(100% + 2px);
    margin: -1px -1px 0;
    background: transparent;
    border: none;
}

.tab-button {
    position: relative;
    z-index: 1;
    padding: 9px 24px;
    background: #475569;
    color: #e2e8f0;
    border: 1px solid #cbd5e1;
    border-right-width: 0;
    border-bottom-color: transparent;
    cursor: pointer;
    font: inherit;
}

.tab-button:last-of-type { border-right-width: 1px; }
.tab-button:hover:not(.active) { background: #64748b; }
.tab-button:focus-visible { outline: 2px solid #2563eb; outline-offset: -3px; }
.tab-button.active {
    z-index: 2;
    background: #ffffff;
    color: #111827;
    font-weight: 700;
    border-bottom-color: transparent;
}

.tab-panels {
    display: flex;
    flex: 1;
    flex-direction: column;
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 16px;
    overflow: hidden;
    background: #ffffff;
    border: none;
}

.tab-panel { flex: 1; min-height: 0; overflow: hidden; }
.tab-panel[hidden] { display: none; }
.tab-stack { display: flex; flex-direction: column; gap: 16px; height: 100%; min-height: 0; overflow: hidden; }

.panel-hierarchy,
.panel-config-editor,
.panel-config-status {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.panel-add,
.panel-backup,
.panel-bird-peers,
.panel-audit {
    flex: 0 0 auto;
    min-height: 0;
    max-height: 40vh;
    display: flex;
    flex-direction: column;
}

.panel-hierarchy:not(.expanded),
.panel-config-status:not(.expanded) { flex: 0 0 auto; min-height: 0; }

.config-status-scroll { overflow-y: auto; }
.panel-config-status .panel-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.config-sections { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.config-section { border-bottom: 1px solid #d0d7de; }
.config-section:last-child { border-bottom: none; }
.config-section-toggle {
    width: 100%; display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 10px 16px; border: 0; background: #f8fafc;
    color: #1f2937; font: inherit; font-weight: 600; text-align: left; cursor: pointer;
}
.config-section-toggle::before { content: '▸ '; color: #6b7280; }
.config-section.expanded .config-section-toggle::before { content: '▾ '; }
.config-section-toggle span:first-of-type { flex: 1; }
.config-section:not(.expanded) .config-section-body { display: none; }
.section-count { white-space: nowrap; font-size: 12px; font-weight: 600; }
.config-section-body { min-height: 0; background: #ffffff; }
.config-editor-panes { min-height: 0; display: flex; padding: 12px 16px 8px; }
.config-readonly-panes { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; padding: 12px 16px; }
.readonly-pane {
    min-width: 0; max-height: 180px; overflow: auto; margin: 0; padding: 8px;
    border: 1px solid #d0d7de; border-radius: 4px; background: #ffffff;
    color: #1f2937; font: 13px/20px Consolas, Menlo, monospace; white-space: pre;
}
.readonly-diff { background: #f8fafc; color: #374151; }
.config-summary-body { display: grid; gap: 6px; padding: 10px 16px 14px; }
.config-summary-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 8px; border: 1px solid #e5e7eb; border-radius: 4px; font: 13px/20px Consolas, Menlo, monospace; }
.config-summary-row .section-count { color: #374151; }
.diff-scroll { flex: 1; min-width: 0; overflow: auto; overscroll-behavior: contain; border: 1px solid #d0d7de; border-radius: 4px; background: #ffffff; }
.diff-columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: flex-start;
    width: 100%;
    min-width: 0;
    position: relative;
}
.config-errors { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 2; }
.cfg-error-row { position: absolute; left: 0; background: rgba(220,38,38,0.12); border-left: 3px solid #dc2626; }
.config-pane {
    font-family: Consolas, Menlo, monospace; font-size: 13px; line-height: 20px;
    white-space: pre; overflow: auto; resize: none;
    border: none; outline: none; padding: 8px; background: #ffffff;
    width: 100%; min-width: 0; max-width: 100%;
}
.config-pane:focus { outline: none; }
.diff-overlay {
    position: relative; padding: 8px; background: #f8fafc;
    width: 100%; min-width: 0; max-width: 100%; overflow: hidden;
}
.diff-row { position: absolute; left: 8px; right: 8px; height: 20px; line-height: 20px; white-space: pre; }
.diff-add { background: #dcfce7; color: #166534; }
.diff-del { background: #fee2e2; color: #dc2626; }
.diff-chunk { color: #6b7280; font-weight: 600; margin-right: 10px; }
.diff-count { margin-left: auto; font-size: 13px; font-weight: 600; letter-spacing: 0.02em; }
.diff-count .add { color: #166534; }
.diff-count .del { color: #dc2626; }
.config-actions { display: flex; gap: 12px; align-items: center; padding: 0 16px 8px; flex-wrap: wrap; }
.diff-timer { font-size: 12px; color: #6b7280; }
.diff-timer.active { color: #f59e0b; font-weight: 600; }
.syntax-msg { font-size: 12px; color: #dc2626; font-weight: 600; }
.config-hint { padding: 0 16px 12px 16px; font-size: 12px; color: #9aa4b2; }

.panel-hierarchy .panel-body {
    flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
    padding: 8px 12px; border-top: 1px solid #d0d7de;
}

.panel-add:not(.expanded),
.panel-backup:not(.expanded),
.panel-bird-peers:not(.expanded),
.panel-audit:not(.expanded) { max-height: none; }
.panel-add .panel-body,
.panel-backup .panel-body,
.panel-bird-peers .panel-body,
.panel-audit .panel-body {
    flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
}
.panel-audit .panel-body { max-height: 32vh; }

.backup-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.backup-slots { font-weight: 600; }
.backup-list { display: grid; gap: 6px; min-height: 0; }
.backup-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto auto;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
}
.backup-name { font-family: Consolas, Menlo, monospace; white-space: nowrap; }
.backup-row .btn[disabled] { opacity: 0.55; cursor: wait; }

/* Panels */
.panel {
    background: #ffffff;
    border: 1px solid #d0d7de;
    border-radius: 8px;
    overflow: hidden;
}

.panel-title { display: flex; align-items: center; gap: 8px; margin: 0; padding: 12px 16px; font-size: 15px; background: #eef1f5; }

/* Collapsible hierarchy panel (R4.5.5) */
.panel-toggle {
    display: block;
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 600;
    text-align: left;
    background: #eef1f5;
    border: none;
    cursor: pointer;
}

.panel-toggle::before { content: "▸ "; }
.panel.expanded .panel-toggle::before { content: "▾ "; }

.panel-count {
    display: inline-block;
    min-width: 28px;
    margin-left: 16px;
    padding: 1px 8px;
    font-size: 13px;
    background: #dbeafe;
    color: #1d4ed8;
    border-radius: 10px;
}

.panel-body { padding: 12px 16px; border-top: 1px solid #d0d7de; }

.placeholder { color: #6b7280; font-size: 13px; }

/* Status badges (R4.1.2) */
.badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 12px; }
.badge-pending { background: #e5e7eb; color: #4b5563; }
.badge-applied { background: #dcfce7; color: #166534; }
.badge-other   { background: #fef3c7; color: #92400e; }

/* Diff highlight (R4.3.1) */
.diff {
    font-family: "Cascadia Mono", Consolas, Menlo, monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre;
}

.diff-add     { background: #dcfce7; }   /* added lines — green */
.diff-del     { background: #fee2e2; }   /* removed lines — red */
.diff-header  { background: #dbeafe; font-weight: 600; }  /* diff headers — accent */

/* ---- Forms, record tables, buttons (R4.1.2 / R4.2.x) ---- */

.form-row { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 220px; }

.field label { display: block; font-size: 13px; color: #6b7280; margin-bottom: 2px; }
.field input, .field select {
    width: 100%; padding: 6px 8px; font-size: 14px;
    border: 1px solid #d0d7de; border-radius: 4px; background: #ffffff;
}
.field input.invalid { border-color: #dc2626; background: #fef2f2; }

.form-msg { font-size: 13px; margin: 6px 0; min-height: 1em; }
.config-status-actions { gap: 8px; }
.form-msg.error { color: #dc2626; }
.form-msg.success { color: #16a34a; }
.form-msg.warning { color: #b45309; }

.record-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.record-table th, .record-table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid #e5e7eb; }
.record-table tr.editing { outline: 2px solid #2563eb; }

.btn {
    display: inline-block; padding: 4px 12px; font-size: 14px; cursor: pointer;
    border-radius: 4px; border: 1px solid transparent; background: #eef1f5;
}
.btn-primary { background: #2563eb; color: #ffffff; }
.btn-danger { background: #fee2e2; color: #dc2626; }

/* Manual refresh button in the header (icon only, no text). */
.app-header .btn-refresh {
    margin-left: auto;
    background: transparent;
    color: #ffffff;
    border: none;
    font-size: 20px;
    line-height: 1;
    padding: 6px 8px;
    cursor: pointer;
}
.btn-refresh:hover { transform: scale(1.1); }
.btn-refresh.spinning { animation: spin-refresh 0.8s linear infinite; }
@keyframes spin-refresh { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- */
/* Hierarchy tree — groups by AS:COMMUNITY value (variant A)       */
/* Lazy render: headers + counters only until a group is expanded  */
/* --------------------------------------------------------------- */

.hierarchy-group { margin-bottom: 4px; }
.hierarchy-group.editing { outline: 2px solid #2563eb; }

.group-header-row { display: flex; align-items: center; gap: 8px; padding: 6px 4px; cursor: pointer; }
.group-arrow { width: 14px; color: #6b7280; font-size: 12px; }
.group-name { font-weight: 600; font-size: 14px; }
.disabled-label { color: #9ca3af; text-decoration: line-through; }
.group-count { font-size: 12px; color: #6b7280; }
.group-desc { font-size: 12px; color: #9aa4b2; }

.hierarchy-group.collapsed .group-arrow::before { content: "▸ "; }
.hierarchy-group.expanded .group-arrow::before { content: "▾ "; }
.hierarchy-group.collapsed .group-body { display: none; }

.group-body { padding: 2px 16px; }

.network-row { display: flex; align-items: center; gap: 8px; padding: 4px; font-size: 14px; cursor: pointer; border-radius: 4px; }
.network-row:hover { background: #f1f5f9; }
.network-row.editing { outline: 2px solid #2563eb; }

.community-checkboxes { display: flex; gap: 4px; align-items: center; font-size: 12px; color: #6b7280; }

.inline-edit { display: flex; gap: 6px; align-items: center; padding: 4px; flex-wrap: wrap; background: #f8fafc; border-radius: 4px; margin-bottom: 4px; }
.inline-edit input, .inline-edit select {
    padding: 4px 6px; font-size: 13px; border: 1px solid #d0d7de; border-radius: 4px; background: #ffffff;
}
.inline-edit label { font-size: 12px; color: #6b7280; }

.add-row-btn { margin-top: 2px; }

/* "Добавление" form: single row — AS:COMMUNITY select + networks line (R4.2.3). */
.panel-add .panel-body { display: flex; flex-direction: column; }
.bulk-form-row { display: flex; gap: 12px; align-items: stretch; flex: 0 0 auto; min-height: 72px; }
.bulk-col-asc { width: 190px; flex-shrink: 0; display: flex; flex-direction: column; gap: 4px; }
.bulk-col-nets { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.bulk-input {
    width: 100%; flex: 1; min-height: 0; font-family: Consolas, Menlo, monospace; font-size: 13px; padding: 8px;
    border: 1px solid #d0d7de; border-radius: 4px; resize: none; overflow-x: hidden; white-space: pre-wrap;
}

/* "Добавить BGP Peer" panel (0.2.2): four fields, single row on wide screens. */
.bgp-form-row { display: flex; gap: 12px; flex-wrap: wrap; padding: 2px 0; }
.bgp-form-row .field { flex: 1; min-width: 150px; }
.bgp-form-row .field select + input { margin-top: 4px; }

/* Toast layer (0.4.3): every failed request must be visible to the operator. */
.toast-stack {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(420px, calc(100vw - 32px));
    pointer-events: none;
}
.toast {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.35;
    color: #ffffff;
    background: #1f2937;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.25);
    opacity: 1;
    transition: opacity 0.3s ease, transform 0.3s ease;
    overflow-wrap: anywhere;
}
.toast-error   { background: #dc2626; }
.toast-success { background: #16a34a; }
.toast-warning { background: #f59e0b; color: #1f2933; }
.toast-info    { background: #1f2937; }
.toast-hide    { opacity: 0; transform: translateY(6px); }

/* BIRD peers block (0.4.4): service protocols + live BGP session table. */
.peer-summary { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; font-size: 13px; }
.peer-service-list { display: grid; gap: 4px; margin-bottom: 10px; }
.peer-service-row {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) 80px 90px 110px 130px;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 13px;
}
.peer-service-name { font-family: Consolas, Menlo, monospace; }
.peer-service-head { color: #6b7280; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; margin: 2px 0 4px; }
.peer-table-wrap { overflow-x: auto; }
.peer-table { font-size: 13px; }
.peer-table th, .peer-table td { white-space: nowrap; }
.peer-table td.peer-error {
    color: #dc2626;
    max-width: 240px;
    white-space: normal;
    overflow-wrap: anywhere;
}
.peer-num { font-family: Consolas, Menlo, monospace; }
.peer-fsm { color: #6b7280; font-size: 12px; }
.peer-section-title { font-size: 13px; font-weight: 600; margin: 0 0 4px; }
.peer-missing { color: #b45309; }
