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

/* ── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:          #F4F6FA;
    --bg-white:    #FFFFFF;
    --bg-sidebar:  #1B1D3C;
    --bg-sidebar-hover: #272A52;
    --bg-sidebar-active: #323670;
    --bg-topbar:   #FFFFFF;
    --bg-input:    #F4F6FA;
    --accent:      #E8351A;
    --accent-light:#FF5540;
    --accent-bg:   rgba(232,53,26,0.08);
    --purple:      #6C63FF;
    --purple-bg:   rgba(108,99,255,0.08);
    --blue:        #3B82F6;
    --blue-bg:     rgba(59,130,246,0.08);
    --text:        #1A1D2E;
    --text-secondary: #5F6580;
    --text-dim:    #9098B1;
    --border:      #E5E7EB;
    --border-light:#F0F1F4;
    --success:     #10B981;
    --success-bg:  rgba(16,185,129,0.08);
    --warning:     #F59E0B;
    --warning-bg:  rgba(245,158,11,0.08);
    --danger:      #EF4444;
    --danger-bg:   rgba(239,68,68,0.08);
    --radius:      8px;
    --radius-lg:   12px;
    --shadow-sm:   0 1px 2px rgba(0,0,0,0.04);
    --shadow:      0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:   0 4px 12px rgba(0,0,0,0.07);
    --shadow-lg:   0 8px 24px rgba(0,0,0,0.1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-light); }

/* ── Login Page ──────────────────────────────────────────────────────── */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: url('/welcome2.webp') center center / cover no-repeat;
    position: relative;
    overflow: hidden;
}

.login-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

.login-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 16px;
    padding: 48px 44px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.4);
    text-align: center;
    position: relative;
    z-index: 1;
}

.login-card img {
    height: 56px;
    margin-bottom: 10px;
}

.login-card h1 {
    font-size: 1.35rem;
    font-weight: 800;
    margin-bottom: 2px;
    color: var(--text);
    letter-spacing: -0.3px;
}

.login-subtitle {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 36px;
    font-weight: 600;
}

.login-card .field { margin-bottom: 20px; text-align: left; }

.login-card label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 600;
}

.login-card input[type="text"],
.login-card input[type="password"] {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.92rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.login-card input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
}

.login-card .btn-login {
    width: 100%;
    padding: 12px;
    margin-top: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: all 0.2s;
}

.login-card .btn-login:hover {
    background: var(--accent-light);
    box-shadow: 0 4px 12px rgba(232,53,26,0.3);
}

.login-error {
    background: var(--danger-bg);
    border: 1px solid rgba(239,68,68,0.2);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 0.83rem;
    text-align: left;
}

/* ── Layout ──────────────────────────────────────────────────────────── */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ── Top Bar ─────────────────────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    z-index: 20;
    box-shadow: var(--shadow-sm);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
}

.topbar-logo img { height: 30px; }

.topbar-logo-text {
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: -0.3px;
    color: var(--text);
}

.topbar-logo-sub {
    font-size: 0.65rem;
    color: var(--accent);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-left: -4px;
}

.topbar-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
}

.topbar-breadcrumb {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
}

.topbar-username {
    font-size: 0.85rem;
    color: var(--text);
    font-weight: 600;
}

.topbar-signout {
    font-size: 0.78rem;
    color: var(--text-dim);
    font-weight: 500;
    transition: color 0.15s;
}

.topbar-signout:hover { color: var(--accent); }

.lang-switcher {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-right: 12px;
}
.lang-switcher a {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 3px 7px;
    border-radius: 4px;
    color: var(--text-dim);
    border: 1px solid transparent;
    text-decoration: none;
}
.lang-switcher a:hover { color: var(--text); }
.lang-switcher a.lang-active {
    color: var(--accent);
    border-color: var(--accent);
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
    width: 220px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 56px;
    bottom: 0;
    left: 0;
    z-index: 10;
    overflow-y: auto;
}

.sidebar-header { display: none; }

.sidebar nav {
    flex: 1;
    padding: 20px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-section-label {
    font-size: 0.62rem;
    color: rgba(255,255,255,0.35);
    text-transform: uppercase;
    letter-spacing: 1.8px;
    font-weight: 700;
    padding: 16px 12px 6px;
}

.nav-section-label:first-child { padding-top: 4px; }

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    color: rgba(255,255,255,0.6);
    font-size: 0.84rem;
    font-weight: 500;
    transition: all 0.15s;
    border-radius: var(--radius);
}

.sidebar nav a:hover {
    background: var(--bg-sidebar-hover);
    color: rgba(255,255,255,0.9);
    text-decoration: none;
}

.sidebar nav a.active {
    background: var(--bg-sidebar-active);
    color: #fff;
    font-weight: 600;
}

.sidebar nav a svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.65;
}

.sidebar nav a.active svg { opacity: 1; }
.sidebar nav a.nav-external { color: rgba(255,255,255,0.45); }
.sidebar nav a.nav-external:hover { color: #F59E0B; }

.sidebar-footer { display: none; }

.nav-sidebar-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    margin-top: 16px;
    background: none;
    border: none;
    border-top: 1px solid rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.35);
    cursor: pointer;
    font-size: 13px;
    text-align: left;
}
.nav-sidebar-toggle:hover { color: rgba(255,255,255,0.7); background: var(--bg-sidebar-hover); }
.nav-sidebar-toggle svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-expand-btn {
    display: none;
    position: fixed;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    z-index: 200;
    background: var(--bg-sidebar);
    color: rgba(255,255,255,0.6);
    border: none;
    border-radius: 0 6px 6px 0;
    padding: 14px 6px;
    cursor: pointer;
    box-shadow: 2px 0 8px rgba(0,0,0,0.15);
}
.sidebar-expand-btn:hover { color: #fff; }
.sidebar-expand-btn svg { width: 16px; height: 16px; display: block; }

body.sidebar-collapsed .sidebar      { width: 0; min-width: 0; overflow: hidden; }
body.sidebar-collapsed .main-content { margin-left: 0; }
body.sidebar-collapsed .sidebar-expand-btn { display: block; }

/* ── Main Content ────────────────────────────────────────────────────── */
.main-content {
    margin-left: 220px;
    margin-top: 56px;
    flex: 1;
    padding: 36px 48px;
}

/* ── Page Header ─────────────────────────────────────────────────────── */
.page-header {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.page-header h2 {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
    color: var(--text);
}

.page-header p {
    color: var(--text-secondary);
    font-size: 0.88rem;
    max-width: 640px;
}

/* ── Inline form message ─────────────────────────────────────────────── */
.form-inline-msg {
    font-size: 0.82rem;
    margin-top: 6px;
    min-height: 1em;
}
.form-inline-msg--success { color: var(--success); }
.form-inline-msg--warning { color: var(--warning); }
.form-inline-msg--danger  { color: var(--danger);  }

/* ── Toast ───────────────────────────────────────────────────────────── */
.toast-msg {
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    animation: toast-in 0.2s ease;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Centered content area below page header */
.page-body {
    width: 100%;
}

/* ── Cards ───────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.card h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.card h3 svg { color: var(--text-secondary); }

/* ── Table toolbar (search + title) ─────────────────────────────────── */
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.table-toolbar h3 { margin-bottom: 0; }

.table-search {
    width: 240px;
    padding: 7px 12px;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}
.table-search:focus { border-color: var(--primary); }

/* ── Sortable headers ────────────────────────────────────────────────── */
th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
th.sortable:hover { color: var(--primary); }

/* ── Pagination ──────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.page-info { font-size: 0.82rem; color: var(--text-secondary); }
.page-btns { display: flex; gap: 8px; }

/* ── Tables ──────────────────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
}

.data-table th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
    background: transparent;
    white-space: nowrap;
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
    color: var(--text-secondary);
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr {
    transition: background 0.1s;
}

.data-table tbody tr:hover td {
    background: var(--bg);
}

.data-table .mono {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.82rem;
    color: var(--text);
    font-weight: 500;
}

/* ── Badges ──────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.badge-active {
    background: var(--success-bg);
    color: var(--success);
}

.badge-active::before { background: var(--success); }

.badge-inactive {
    background: rgba(144,152,177,0.1);
    color: var(--text-dim);
}

.badge-inactive::before { background: var(--text-dim); }

.badge-neutral {
    background: rgba(144,152,177,0.06);
    color: var(--text-dim);
    font-style: italic;
}

.badge-neutral::before { background: var(--text-dim); opacity: 0.4; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-white);
    color: var(--text-secondary);
    font-size: 0.84rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn:hover {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text);
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--accent-light);
    border-color: var(--accent-light);
    box-shadow: 0 2px 8px rgba(232,53,26,0.25);
}

.btn-danger {
    background: var(--danger-bg);
    border-color: rgba(239,68,68,0.2);
    color: var(--danger);
}

.btn-danger:hover {
    background: rgba(239,68,68,0.14);
}

.btn-success {
    background: var(--success-bg);
    border-color: rgba(16,185,129,0.2);
    color: var(--success);
}

.btn-success:hover {
    background: rgba(16,185,129,0.14);
}

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-xs { padding: 4px 10px; font-size: 0.74rem; }

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

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

.form-group label {
    font-size: 0.76rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.form-group-action {
    display: flex;
    align-items: flex-end;
}

.form-group input,
.form-group select {
    padding: 9px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.88rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-bg);
    background: var(--bg-white);
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* inline edit input */
.inline-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 5px 10px;
    color: var(--text);
    font-size: 0.82rem;
    font-family: inherit;
    outline: none;
    width: 180px;
    transition: border-color 0.15s;
}

.inline-input:focus {
    border-color: var(--accent);
    background: var(--bg-white);
}

/* ── Emergency panel ─────────────────────────────────────────────────── */
.emergency-panel {
    background: var(--bg-white);
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    margin-top: 4px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--danger);
}

.emergency-panel h3 {
    color: var(--danger);
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.emergency-panel p {
    color: var(--text-secondary);
    font-size: 0.86rem;
    margin-bottom: 20px;
    line-height: 1.6;
}

.btn-emergency {
    background: var(--danger);
    border: none;
    color: #fff;
    padding: 10px 28px;
    border-radius: var(--radius);
    font-size: 0.86rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    transition: all 0.2s;
}

.btn-emergency:hover {
    background: #DC2626;
    box-shadow: 0 4px 12px rgba(239,68,68,0.3);
}

/* ── Alerts ──────────────────────────────────────────────────────────── */
.alert {
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
}

.alert-success {
    background: var(--success-bg);
    border: 1px solid rgba(16,185,129,0.2);
    color: var(--success);
}

.alert-danger {
    background: var(--danger-bg);
    border: 1px solid rgba(239,68,68,0.2);
    color: var(--danger);
}

.alert-warning {
    background: var(--warning-bg);
    border: 1px solid rgba(245,158,11,0.2);
    color: var(--warning);
}

/* ── Confirm dialog ──────────────────────────────────────────────────── */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.confirm-box {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px 40px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.confirm-box h3 {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text);
}

.confirm-box p {
    color: var(--text-secondary);
    font-size: 0.88rem;
    margin-bottom: 28px;
    line-height: 1.6;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ── Utilities ───────────────────────────────────────────────────────── */
.text-dim  { color: var(--text-dim); }
.text-sm   { font-size: 0.82rem; }
.mono      { font-family: 'JetBrains Mono', monospace; }
.mt-2      { margin-top: 8px; }
.mt-4      { margin-top: 16px; }
.mb-2      { margin-bottom: 8px; }
.mb-4      { margin-bottom: 16px; }
.flex-end  { display: flex; justify-content: flex-end; }
.gap-2     { gap: 8px; }

/* ── HTMX indicators ────────────────────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

/* ── Scrollbar ───────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── InfraMonitor nav badge ──────────────────────────────────────────── */
.nav-alert-badge {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--danger);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* ── InfraMonitor alert banner ───────────────────────────────────────── */
.infra-alert-bar {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    z-index: 15;
    height: 36px;
    background: var(--danger);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 10px;
    font-size: 0.8125rem;
    font-weight: 500;
}
.infra-alert-bar--hidden { display: none; }
.infra-alert-bar-link {
    color: #fff;
    font-weight: 700;
    text-decoration: underline;
    margin-left: auto;
    white-space: nowrap;
}
body.has-infra-alert .sidebar      { top: 92px; }
body.has-infra-alert .main-content { margin-top: 92px; }
.infra-alert-bar-dismiss {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.5);
    color: #fff;
    border-radius: 4px;
    padding: 2px 6px;
    cursor: pointer;
    line-height: 0;
    margin-left: 8px;
    flex-shrink: 0;
}
.infra-alert-bar-dismiss:hover { background: rgba(255,255,255,0.15); }
