/* === MAIN.CSS ===
 * assets/css/main.css
 * НАЗНАЧЕНИЕ: Основные стили Telegram Mirror SPA Dashboard
 * ЭСТЕТИКА: Industrial/Utilitarian - JetBrains Mono + Inter
 * РАЗМЕР: ~500 строк
 */

/* ============================================
   FONTS
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Inter:wght@400;500;600;700&display=swap');

/* ============================================
   CSS VARIABLES - DARK (DEFAULT)
   ============================================ */
:root {
    --bg-primary: hsl(220, 15%, 6%);
    --bg-secondary: hsl(220, 13%, 9%);
    --bg-tertiary: hsl(220, 12%, 12%);
    --card-bg: hsl(220, 13%, 8%);
    --text-primary: hsl(0, 0%, 92%);
    --text-secondary: hsl(0, 0%, 65%);
    --text-muted: hsl(0, 0%, 45%);
    --border: hsl(220, 10%, 16%);
    --border-light: hsl(220, 10%, 20%);
    --color-primary: hsl(217, 91%, 60%);
    --color-secondary: hsl(262, 65%, 65%);
    --color-success: hsl(142, 71%, 45%);
    --color-warning: hsl(38, 92%, 50%);
    --color-danger: hsl(0, 84%, 60%);
    --color-info: hsl(199, 89%, 48%);
    --gradient-primary: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    --sidebar-width: 250px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --radius: 6px;
    --radius-sm: 4px;
    --font-mono: 'JetBrains Mono', monospace;
    --font-body: 'Inter', sans-serif;
}

/* ============================================
   LIGHT THEME OVERRIDES
   ============================================ */
html.light-theme {
    --bg-primary: hsl(220, 20%, 97%);
    --bg-secondary: hsl(220, 15%, 94%);
    --bg-tertiary: hsl(220, 12%, 90%);
    --card-bg: hsl(0, 0%, 100%);
    --text-primary: hsl(220, 20%, 12%);
    --text-secondary: hsl(220, 10%, 40%);
    --text-muted: hsl(0, 0%, 55%);
    --border: hsl(220, 15%, 85%);
    --border-light: hsl(220, 15%, 80%);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ============================================
   CUSTOM SCROLLBAR
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   THEME TOGGLE BUTTON
   ============================================ */
.tgm-theme-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.tgm-theme-btn:hover {
    background: var(--border);
    border-color: var(--border-light);
}

.tgm-theme-btn svg {
    width: 16px;
    height: 16px;
}

.tgm-icon-sun { display: none; }
.tgm-icon-moon { display: inline; }

html.light-theme .tgm-icon-sun { display: inline; }
html.light-theme .tgm-icon-moon { display: none; }

/* ============================================
   LOGIN SCREEN
   ============================================ */
.tgm-login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

.tgm-login-card {
    width: 360px;
    padding: 24px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    position: relative;
}

.tgm-login-card::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: var(--radius);
    padding: 1px;
    background: var(--gradient-primary);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    opacity: 0.4;
}

.tgm-login-title {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.tgm-login-subtitle {
    font-size: 12px;
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.tgm-login-card .tgm-input {
    width: 100%;
    margin-bottom: 12px;
}

.tgm-login-card .tgm-btn {
    width: 100%;
}

.tgm-login-error {
    color: var(--color-danger);
    font-size: 12px;
    text-align: center;
    margin-top: 8px;
}

/* ============================================
   APP LAYOUT
   ============================================ */
.tgm-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ============================================
   SIDEBAR
   ============================================ */
.tgm-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tgm-sidebar-header {
    padding: 14px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tgm-sidebar-logo {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.tgm-sidebar-logo span {
    color: var(--color-primary);
}

.tgm-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}

.tgm-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin: 2px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    border-left: 2px solid transparent;
    user-select: none;
}

.tgm-nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.tgm-nav-item.active {
    background: var(--bg-tertiary);
    color: var(--color-primary);
    border-left-color: var(--color-primary);
}

.tgm-nav-item svg,
.tgm-nav-item i {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}

.tgm-nav-item.active svg,
.tgm-nav-item.active i {
    opacity: 1;
}

.tgm-nav-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 10px;
}

.tgm-nav-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 10px 12px 4px;
}

/* Sidebar footer - daemon status */
.tgm-sidebar-footer {
    margin-top: auto;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ============================================
   MAIN AREA
   ============================================ */
.tgm-main {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

/* ============================================
   SCREEN CONTAINERS
   ============================================ */
.tgm-screen {
    display: none;
    flex-direction: column;
    gap: 10px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.tgm-screen.active {
    display: flex;
}

/* ============================================
   CARDS
   ============================================ */
.tgm-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    box-shadow: var(--shadow-sm);
}

.tgm-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.tgm-card-title {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* ============================================
   METRIC CARDS
   ============================================ */
.tgm-metric {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    flex: 0 0 auto;
    white-space: nowrap;
}

.tgm-metric-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--color-primary);
    flex-shrink: 0;
}

.tgm-metric-icon svg {
    width: 16px;
    height: 16px;
}

.tgm-metric-value {
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.tgm-metric-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ============================================
   BUTTONS
   ============================================ */
.tgm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
    user-select: none;
}

.tgm-btn:hover {
    background: var(--border);
    border-color: var(--border-light);
}

.tgm-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tgm-btn svg {
    width: 14px;
    height: 14px;
}

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

.tgm-btn-primary:hover {
    background: hsl(217, 91%, 55%);
    border-color: hsl(217, 91%, 55%);
}

.tgm-btn-danger {
    background: transparent;
    border-color: var(--color-danger);
    color: var(--color-danger);
}

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

.tgm-btn-sm {
    padding: 4px 8px;
    font-size: 11px;
}

.tgm-btn-full {
    width: 100%;
}

/* ============================================
   INPUTS
   ============================================ */
.tgm-input,
.tgm-select,
.tgm-textarea {
    padding: 7px 10px;
    font-family: var(--font-body);
    font-size: 12px;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.15s;
}

.tgm-input:focus,
.tgm-select:focus,
.tgm-textarea:focus {
    border-color: var(--color-primary);
}

.tgm-input::placeholder,
.tgm-textarea::placeholder {
    color: var(--text-muted);
}

.tgm-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23737373' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

.tgm-textarea {
    resize: vertical;
    min-height: 60px;
    line-height: 1.5;
}

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

.tgm-form-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ============================================
   TABLES
   ============================================ */
.tgm-table-wrap {
    overflow-x: auto;
}

.tgm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.tgm-table th {
    text-align: left;
    padding: 6px 10px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.tgm-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.tgm-table tbody tr:nth-child(even) {
    background: var(--bg-secondary);
}

.tgm-table tbody tr:hover {
    background: var(--bg-tertiary);
}

/* ============================================
   TAGS & BADGES
   ============================================ */
.tgm-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.tgm-tag-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tgm-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 10px;
    font-weight: 700;
    border-radius: 9px;
    color: #fff;
    background: var(--color-primary);
    line-height: 1;
}

.tgm-badge-success { background: var(--color-success); }
.tgm-badge-warning { background: var(--color-warning); color: #000; }
.tgm-badge-danger { background: var(--color-danger); }

/* ============================================
   GRID
   ============================================ */
.tgm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.tgm-grid-2 { grid-template-columns: 1fr 1fr; }
.tgm-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.tgm-grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ============================================
   SECTION HEADERS
   ============================================ */
.tgm-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.tgm-section-title {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ============================================
   STATUS INDICATORS
   ============================================ */
.tgm-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}

.tgm-status-dot.running {
    background: var(--color-success);
    box-shadow: 0 0 6px var(--color-success);
    animation: tgm-pulse 2s infinite;
}

.tgm-status-dot.stopped {
    background: var(--color-danger);
}

.tgm-status-dot.degraded {
    background: var(--color-warning);
    animation: tgm-pulse-warning 2s infinite;
}

@keyframes tgm-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--color-success); }
    50% { opacity: 0.6; box-shadow: 0 0 8px var(--color-success); }
}

@keyframes tgm-pulse-warning {
    0%, 100% { opacity: 1; box-shadow: 0 0 4px var(--color-warning); }
    50% { opacity: 0.6; box-shadow: 0 0 8px var(--color-warning); }
}

/* ============================================
   STAR (FAVORITE)
   ============================================ */
.tgm-star {
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.15s;
}

.tgm-star:hover {
    color: var(--color-warning);
}

.tgm-star.active {
    color: var(--color-warning);
}

/* ============================================
   LOADING SPINNER
   ============================================ */
.tgm-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: tgm-spin 0.6s linear infinite;
}

.tgm-spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

.tgm-spinner-center {
    margin: 40px auto;
}

@keyframes tgm-spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.tgm-flex {
    display: flex;
    align-items: center;
}

.tgm-flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tgm-flex-col {
    display: flex;
    flex-direction: column;
}

.tgm-gap-4 { gap: 4px; }
.tgm-gap-6 { gap: 6px; }
.tgm-gap-10 { gap: 10px; }

.tgm-mt-6 { margin-top: 6px; }
.tgm-mt-10 { margin-top: 10px; }
.tgm-mb-10 { margin-bottom: 10px; }

.tgm-text-muted { color: var(--text-muted); }
.tgm-text-secondary { color: var(--text-secondary); }
.tgm-text-success { color: var(--color-success); }
.tgm-text-danger { color: var(--color-danger); }
.tgm-text-warning { color: var(--color-warning); }

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

.tgm-text-sm { font-size: 11px; }
.tgm-text-xs { font-size: 10px; }
.tgm-text-center { text-align: center; }
.tgm-text-right { text-align: right; }

.tgm-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tgm-nowrap { white-space: nowrap; }
.tgm-hidden { display: none !important; }
.tgm-w-full { width: 100%; }

/* ============================================
   DASHBOARD
   ============================================ */
.tgm-dashboard {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tgm-metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.tgm-metric-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.tgm-metric-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: hsla(217, 91%, 60%, 0.1);
    border-radius: var(--radius-sm);
    color: var(--color-primary);
}

.tgm-metric-icon svg {
    width: 18px;
    height: 18px;
}

.tgm-metric-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}

.tgm-metric-label {
    font-size: 11px;
    color: var(--text-muted);
}

.tgm-dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 10px;
}

.tgm-chart-card .tgm-card-body {
    height: 250px;
}

/* ============================================
   DAEMON INFO ROWS (dashboard + settings)
   ============================================ */
.tgm-daemon-row,
.tgm-settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 5px 0;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}

.tgm-daemon-row:last-child,
.tgm-settings-row:last-child {
    border-bottom: none;
}

.tgm-daemon-row > span:first-child,
.tgm-settings-row > span:first-child {
    color: var(--text-muted);
    flex-shrink: 0;
}

.tgm-daemon-row > span:last-child,
.tgm-settings-row > span:last-child {
    color: var(--text-primary);
    text-align: right;
}

.tgm-daemon-status {
    font-size: 13px;
    font-weight: 600;
    padding: 6px 0;
}

.tgm-status-ok { color: var(--color-success); }
.tgm-status-err { color: var(--color-danger); }

/* ============================================
   SETTINGS PAGE
   ============================================ */
.tgm-settings-page {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tgm-settings-section .tgm-section-header {
    cursor: pointer;
    user-select: none;
    justify-content: flex-start;
}

.tgm-settings-section .tgm-section-arrow {
    display: inline-block;
    transition: transform 0.15s;
    font-size: 10px;
}

.tgm-settings-section.collapsed .tgm-section-body {
    display: none;
}

.tgm-settings-section.collapsed .tgm-section-arrow {
    transform: rotate(-90deg);
}

.tgm-settings-actions {
    padding-top: 8px;
}

.tgm-theme-switch {
    display: flex;
    gap: 6px;
}

.tgm-theme-switch .tgm-btn {
    padding: 4px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
    width: auto;
    height: auto;
}

.tgm-theme-switch .tgm-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.tgm-daemon-info {
    display: flex;
    flex-direction: column;
}

/* ============================================
   TAGS PAGE
   ============================================ */
.tgm-tag-row {
    display: grid;
    grid-template-columns: 12px 1fr 80px 2fr 50px auto auto auto;
    gap: 10px;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}

.tgm-tag-row:hover {
    background: var(--bg-tertiary);
}

.tgm-tag-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tgm-tag-name {
    font-weight: 600;
    color: var(--text-primary);
}

.tgm-tag-type {
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
}

.tgm-tag-value {
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tgm-tag-count {
    color: var(--text-muted);
    text-align: center;
}

/* ============================================
   LOGS
   ============================================ */
.tgm-logs-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 8px;
    flex-wrap: wrap;
}

.tgm-logs-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 400px;
    overflow-y: auto;
}

.tgm-log-row {
    display: grid;
    grid-template-columns: 140px 60px 60px 1fr;
    gap: 8px;
    padding: 3px 6px;
    font-size: 11px;
    font-family: var(--font-mono);
    border-radius: 2px;
}

.tgm-log-time { color: var(--text-muted); }
.tgm-log-level { font-weight: 600; }
.tgm-log-channel { color: var(--text-secondary); }
.tgm-log-message { color: var(--text-primary); }
.tgm-log-error .tgm-log-level { color: var(--color-danger); }
.tgm-log-warning .tgm-log-level { color: var(--color-warning); }
.tgm-log-info .tgm-log-level { color: var(--color-primary); }
.tgm-log-debug .tgm-log-level { color: var(--text-muted); }

/* ============================================
   CHECKBOX LABEL
   ============================================ */
.tgm-checkbox-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}
