:root {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #212529;
    background: #f4f6f9;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: #212529;
    background: #f4f6f9;
    font-size: 16px;
    line-height: 1.5;
}

button, input { font: inherit; }
.theme-toggle { margin-left:auto; margin-right:.65rem; white-space:nowrap; }

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-container { width: 100%; max-width: 400px; }

.card {
    background: #fff;
    border: 1px solid rgba(0, 0, 0, .125);
    border-radius: .25rem;
    box-shadow: 0 .125rem .25rem rgba(0, 0, 0, .075);
}

.card-header {
    padding: .75rem 1.25rem;
    background: rgba(0, 0, 0, .03);
    border-bottom: 1px solid rgba(0, 0, 0, .125);
}

.card-header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 500;
    text-align: center;
}

.card-body { padding: 1.25rem; }
.card-body h2 { margin: 0 0 1.25rem; font-size: 1.25rem; font-weight: 400; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: inline-block; margin-bottom: .5rem; font-weight: 500; }

.form-control {
    display: block;
    width: 100%;
    height: calc(1.5em + .75rem + 2px);
    padding: .375rem .75rem;
    color: #495057;
    background: #fff;
    border: 1px solid #ced4da;
    border-radius: .25rem;
    outline: none;
}

.form-control:focus {
    border-color: #80bdff;
    box-shadow: 0 0 0 .2rem rgba(0, 123, 255, .25);
}

.code-input { text-align: center; font-size: 1.5rem; letter-spacing: .35rem; }

.btn {
    display: inline-block;
    padding: .375rem .75rem;
    border: 1px solid transparent;
    border-radius: .25rem;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

.btn-primary { color: #fff; background: #007bff; border-color: #007bff; }
.btn-primary:hover { background: #0069d9; border-color: #0062cc; }
.btn-outline-secondary { color: #6c757d; background: transparent; border-color: #6c757d; }
.btn-outline-secondary:hover { color: #fff; background: #6c757d; }
.btn-outline-light { color: #f8f9fa; background: transparent; border-color: #f8f9fa; }
.btn-outline-light:hover { color: #343a40; background: #f8f9fa; }
.btn-link { color: #007bff; background: transparent; }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: .25rem .5rem; font-size: .875rem; }

.alert {
    margin-bottom: 1rem;
    padding: .75rem 1.25rem;
    border: 1px solid transparent;
    border-radius: .25rem;
}

.alert-success { color: #155724; background: #d4edda; border-color: #c3e6cb; }
.alert-danger { color: #721c24; background: #f8d7da; border-color: #f5c6cb; }

.navbar { padding: .6rem 1rem; background: #343a40; border-bottom: 1px solid #495057; }
.navbar-container { display: flex; align-items: center; max-width: 1140px; min-height: 40px; margin: 0 auto; }
.navbar-brand {
    flex: 0 0 auto;
    min-height: 40px;
    padding-left: 48px;
    color: #fff;
    background: url('/assets/lan-dashboard-logo.png?v=4') left center / 40px 40px no-repeat;
    font-size: 1.2rem;
    font-weight: 500;
    line-height: 40px;
    text-decoration: none;
    white-space: nowrap;
}
.navbar-menu { display: flex; align-items: center; justify-content: space-between; flex: 1 1 auto; margin-left: 2rem; }
.navbar-links { display: flex; align-items: center; gap: .35rem; }
.nav-link { padding: .4rem .7rem; color: rgba(255, 255, 255, .72); border-radius: .2rem; text-decoration: none; }
.nav-link:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav-link.active { color: #fff; background: rgba(255,255,255,.14); }
.navbar-logout { margin: 0; }
.navbar-toggler { display: none; padding: .3rem .65rem; color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.5); border-radius: .25rem; }
.container { width: 100%; max-width: 1140px; margin: 0 auto; padding: 0 15px; }
.dashboard-container { padding-top: 2rem; padding-bottom: 2rem; }
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { margin: 0; font-size: 1.75rem; font-weight: 500; }
.page-header p { margin: .25rem 0 0; color: #6c757d; }
.mb-0 { margin-bottom: 0; }
.page-header-row { display: flex; align-items: end; justify-content: space-between; gap: 1rem; }
.summary-inline { display: flex; gap: .5rem; }
.device-page-actions { display: flex; align-items: flex-end; flex-direction: column; gap: .75rem; }
.btn:disabled { cursor: not-allowed; opacity: .65; }
.badge { display: inline-block; padding: .35rem .55rem; border-radius: .25rem; font-size: .8rem; font-weight: 600; }
.badge-success { color: #fff; background: #28a745; }
.badge-secondary { color: #fff; background: #6c757d; }
.badge-info { color: #fff; background: #17a2b8; }
.badge-danger { color:#fff; background:#dc3545; }
.btn-danger { color:#fff; background:#dc3545; border-color:#dc3545; }
.device-new-badge { margin-left: .35rem; }
.table-responsive { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: #fff; }
.table th, .table td { padding: .75rem; border-top: 1px solid #dee2e6; text-align: left; vertical-align: middle; white-space: nowrap; }
.table thead th { border-top: 0; border-bottom: 2px solid #dee2e6; background: #f8f9fa; font-size: .875rem; }
.text-monospace { font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: .875rem; }
.status-dot { display: inline-block; width: .65rem; height: .65rem; margin-right: .45rem; border-radius: 50%; }
.status-dot.online { background: #28a745; }
.status-dot.offline { background: #adb5bd; }
.name-form { display: flex; gap: .4rem; min-width: 250px; }
.type-form { display: flex; gap: .4rem; min-width: 235px; }
.type-form select { min-width: 150px; }
.form-control-sm { height: calc(1.5em + .5rem + 2px); padding: .25rem .5rem; font-size: .875rem; }
.empty-cell { padding: 2rem !important; color: #6c757d; text-align: center !important; }
.device-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.device-card { min-width: 0; overflow: hidden; }
.device-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1rem 1.1rem; border-bottom: 1px solid rgba(0, 0, 0, .125); background: rgba(0, 0, 0, .03); }
.device-card-header h2 { margin: 0 0 .15rem; overflow-wrap: anywhere; font-size: 1.1rem; font-weight: 600; }
.device-type-label { color: #6c757d; font-size: .8rem; }
.device-status { flex: 0 0 auto; padding: .2rem .45rem; border: 1px solid #ced4da; border-radius: .25rem; background: #fff; font-size: .75rem; }
.device-status.is-online { color: #155724; border-color: #c3e6cb; background: #d4edda; }
.device-status.is-offline { color: #495057; background: #e9ecef; }
.device-card-toggle { display:none; color:#007bff; background:transparent; border:0; padding:.2rem 0; font-size:.8rem; cursor:pointer; }
.device-details { display: grid; grid-template-columns: 1fr 1fr; padding: .35rem 1.1rem; }
.device-details div { min-width: 0; padding: .65rem 0; border-bottom: 1px solid #eee; }
.device-details div:nth-child(odd) { padding-right: .75rem; }
.device-details span, .device-details strong { display: block; }
.device-details span { margin-bottom: .15rem; color: #6c757d; font-size: .72rem; text-transform: uppercase; }
.device-details strong { overflow-wrap: anywhere; font-size: .86rem; font-weight: 500; }
.device-card-actions { display: grid; gap: .8rem; padding: .9rem 1.1rem 1.1rem; }
.device-form label { display: block; margin-bottom: .3rem; font-size: .8rem; font-weight: 500; }
.input-action { display: flex; gap: .4rem; }
.input-action .form-control { min-width: 0; }
.vpn-section { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid #dee2e6; }
.vpn-section .page-header h2 { margin: 0; font-size: 1.4rem; font-weight: 500; }
.vpn-card { border-color: #b8daff; }
.metric-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:1rem; margin-bottom:1rem; }
.metric { display:flex; align-items:center; gap:1rem; min-height:112px; padding:1rem; overflow:hidden; border-top-width:4px; }
.metric span{display:block;color:#6c757d;font-size:.8rem;text-transform:uppercase}.metric strong{font-size:1.8rem;font-weight:600}
.metric-icon { display:grid; place-items:center; flex:0 0 52px; width:52px; height:52px; border-radius:50%; font-size:1.55rem; }
.metric-blue { border-top-color:#007bff; background:linear-gradient(135deg,#fff 65%,#e8f2ff); }.metric-blue .metric-icon{color:#0069d9;background:#dbeaff}
.metric-green { border-top-color:#28a745; background:linear-gradient(135deg,#fff 65%,#e4f6e8); }.metric-green .metric-icon{color:#218838;background:#d9f0df}
.metric-cyan { border-top-color:#17a2b8; background:linear-gradient(135deg,#fff 65%,#e1f5f8); }.metric-cyan .metric-icon{color:#117a8b;background:#d5f0f4}
.metric-orange { border-top-color:#fd7e14; background:linear-gradient(135deg,#fff 65%,#fff0e2); }.metric-orange .metric-icon{color:#d86709;background:#ffe5cf}
.health-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:1rem; }
.status-list div { display:flex; justify-content:space-between; gap:1rem; padding:.55rem 0; border-bottom:1px solid #eee; }.status-list div:last-child{border:0}.status-list span{color:#6c757d}.status-list strong{text-align:right}
.section-title { display:flex; align-items:center; gap:.55rem; }.section-title>i{color:#007bff;font-size:1.1rem}
.status-list span>i { width:1.2rem; margin-right:.3rem; color:#6c757d; text-align:center; }
.status-list strong>i { margin-right:.2rem; }.status-ok{color:#28a745}.status-error{color:#dc3545}
.status-list .health-item { display:grid; grid-template-columns:1fr auto; gap:.35rem 1rem; }
.health-progress { grid-column:1/-1; width:100%; height:.55rem; overflow:hidden; border:0; border-radius:999px; background:#e9ecef; }
.health-progress::-webkit-progress-bar { border-radius:999px; background:#e9ecef; }
.health-progress::-webkit-progress-value { border-radius:999px; background:linear-gradient(90deg,#28a745 0%,#ffc107 60%,#dc3545 100%); }
.health-progress::-moz-progress-bar { border-radius:999px; background:linear-gradient(90deg,#28a745 0%,#ffc107 60%,#dc3545 100%); }
.filter-bar { display:grid; grid-template-columns:2fr 1fr 1fr auto auto auto; align-items:center; gap:.75rem; padding:1rem; margin-bottom:1rem; }
.filter-bar label,.alert-options label{white-space:nowrap;font-size:.875rem}.notes-control{height:auto;resize:vertical}.inventory-form{display:grid;gap:.4rem;padding-bottom:.8rem;border-bottom:1px solid #eee}.alert-options{display:flex;flex-wrap:wrap;gap:.75rem}.archived-row{display:flex;justify-content:space-between;align-items:center;gap:1rem;padding:.5rem 0;border-bottom:1px solid #eee}.archived-row:last-child{border:0}
.filter-result { color:#6c757d; font-size:.875rem; white-space:nowrap; }
.section-heading-row { display:flex; align-items:center; justify-content:space-between; gap:1rem; }
.device-detail-link { justify-self:start; text-decoration:none; }
.detail-summary { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:1rem; }
.detail-summary div { padding:.8rem; border:1px solid #e5e5e5; border-radius:.25rem; background:#fff; }
.detail-summary span,.detail-summary strong { display:block; }
.detail-summary span { margin-bottom:.25rem; color:#6c757d; font-size:.75rem; text-transform:uppercase; }
.history-device-link { color:#007bff; text-decoration:none; }
.device-type-icon { width:1.25rem; color:#007bff; text-align:center; }
.history-table-controls { display:grid; grid-template-columns:minmax(220px,2fr) minmax(150px,1fr) 110px; gap:.75rem; align-items:end; margin-bottom:1rem; }
.history-table-controls label { display:grid; gap:.25rem; color:#495057; font-size:.8rem; }
.history-table-controls label:first-child { position:relative; }
.history-table-controls label:first-child i { position:absolute; left:.75rem; bottom:.65rem; color:#6c757d; }
.history-table-controls label:first-child input { padding-left:2rem; }
.history-table-footer { display:flex; align-items:center; justify-content:space-between; gap:1rem; margin-top:.75rem; color:#6c757d; font-size:.875rem; }
.history-pagination { display:flex; flex-wrap:wrap; gap:.25rem; }
.history-pagination button { min-width:2rem; padding:.3rem .55rem; border:1px solid #dee2e6; border-radius:.2rem; color:#007bff; background:#fff; cursor:pointer; }
.history-pagination button.is-active { color:#fff; border-color:#007bff; background:#007bff; }
.history-pagination button:disabled { color:#adb5bd; cursor:not-allowed; }
[hidden]{display:none!important}
.vpn-create { max-width:620px; }
.vpn-actions,.vpn-result-actions { display:flex; flex-wrap:wrap; gap:.5rem; }
.vpn-actions form { margin:0; }
.vpn-config { height:320px; margin-bottom:1rem; font-family:SFMono-Regular,Menlo,Monaco,Consolas,monospace; font-size:.82rem; resize:vertical; }

html[data-theme="dark"] { color:#e9ecef; background:#12161c; }
html[data-theme="dark"] body { color:#e9ecef; background:#12161c; }
html[data-theme="dark"] .card,
html[data-theme="dark"] .table,
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .device-status { color:#e9ecef; background:#20262e; border-color:#49515c; }
html[data-theme="dark"] .form-control::placeholder { color:#9da6b0; }
html[data-theme="dark"] .form-control:focus { border-color:#4da3ff; box-shadow:0 0 0 .2rem rgba(13,110,253,.3); }
html[data-theme="dark"] .card-header,
html[data-theme="dark"] .device-card-header,
html[data-theme="dark"] .table thead th { color:#f8f9fa; background:#292f38; border-color:#49515c; }
html[data-theme="dark"] .table th,
html[data-theme="dark"] .table td,
html[data-theme="dark"] .device-details div,
html[data-theme="dark"] .status-list div,
html[data-theme="dark"] .inventory-form,
html[data-theme="dark"] .archived-row { border-color:#3d444d; }
html[data-theme="dark"] .page-header p,
html[data-theme="dark"] .device-type-label,
html[data-theme="dark"] .device-details span,
html[data-theme="dark"] .metric span,
html[data-theme="dark"] .status-list span,
html[data-theme="dark"] .detail-summary span,
html[data-theme="dark"] .filter-result,
html[data-theme="dark"] .history-table-footer,
html[data-theme="dark"] .history-table-controls label,
html[data-theme="dark"] .empty-cell { color:#adb5bd; }
html[data-theme="dark"] .metric-blue,
html[data-theme="dark"] .metric-green,
html[data-theme="dark"] .metric-cyan,
html[data-theme="dark"] .metric-orange { background:#20262e; }
html[data-theme="dark"] .detail-summary div { color:#e9ecef; background:#20262e; border-color:#49515c; }
html[data-theme="dark"] .device-status.is-online { color:#8ee6a3; background:#173c25; border-color:#28653a; }
html[data-theme="dark"] .device-status.is-offline { color:#ced4da; background:#343a40; }
html[data-theme="dark"] .btn-outline-secondary { color:#ced4da; border-color:#89919a; }
html[data-theme="dark"] .btn-outline-secondary:hover { color:#12161c; background:#ced4da; }
html[data-theme="dark"] .history-pagination button { color:#69adff; background:#20262e; border-color:#49515c; }
html[data-theme="dark"] .history-pagination button.is-active { color:#fff; background:#0d6efd; border-color:#0d6efd; }
html[data-theme="dark"] .vpn-section { border-color:#3d444d; }
html[data-theme="dark"] .health-progress,
html[data-theme="dark"] .health-progress::-webkit-progress-bar { background:#343a40; }

@media (max-width: 575px) {
    .login-page { align-items: flex-start; padding-top: 2rem; }
    .page-header-row { align-items: flex-start; flex-direction: column; }
    .device-page-actions { width: 100%; align-items: stretch; }
    .device-page-actions form .btn { width: 100%; }
    .navbar { padding: .7rem 1rem; }
    .navbar-container { flex-wrap: wrap; justify-content: space-between; }
    .navbar-toggler { display: inline-block; }
    .navbar-menu { display: none; flex: 0 0 100%; margin: .65rem 0 0; padding-top: .65rem; border-top: 1px solid rgba(255,255,255,.15); }
    .navbar-menu.is-open { display: block; }
    .navbar-links { display: grid; gap: .2rem; }
    .nav-link { display: block; padding: .55rem .65rem; }
    .navbar-logout { margin-top: .4rem; }
    .theme-toggle { width:100%; margin:.4rem 0 0; padding:.5rem .65rem; text-align:left; }
    .navbar-logout .btn { width: 100%; padding: .5rem .65rem; text-align: left; }
    .device-grid { grid-template-columns: 1fr; }
    .device-card-header { align-items: center; }
    .device-card-header { display:grid; grid-template-columns:minmax(0,1fr) auto; }
    .device-card-toggle { display:block; grid-column:1/-1; justify-self:start; margin-top:.35rem; }
    .device-card-collapsible { display:none; border-top:1px solid rgba(0,0,0,.08); }
    .device-card.is-expanded .device-card-collapsible { display:block; }
    .device-details { grid-template-columns: 1fr; }
    .device-details div:nth-child(odd) { padding-right: 0; }
    .metric-grid,.health-grid,.filter-bar { grid-template-columns:1fr; }
    .detail-summary { grid-template-columns:1fr; }
    .section-heading-row { align-items:flex-start; flex-direction:column; }
    .history-table-controls { grid-template-columns:1fr; }
    .history-table-footer { align-items:flex-start; flex-direction:column; }
    .input-action .btn { min-width: 72px; }
}

@media (min-width: 576px) and (max-width: 991px) {
    .device-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric-grid { grid-template-columns:repeat(2,1fr); }.health-grid{grid-template-columns:1fr;}
}
