/* =========================================================
   Alarm Receiver UI — Industrial / Utilitarian Theme
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap');

/* ---- Variables ---- */
:root {
    --bg:           #0f1117;
    --sidebar-bg:   #161b24;
    --surface:      #1c2333;
    --surface-2:    #242d3d;
    --border:       #2a3448;
    --text:         #c8d0e0;
    --text-dim:     #6b7a96;
    --text-bright:  #e8edf5;
    --accent:       #2563eb;
    --accent-dim:   #1e4db7;
    --green:        #16a34a;
    --green-dim:    #14532d;
    --green-bg:     #0d2e1a;
    --red:          #dc2626;
    --red-dim:      #991b1b;
    --red-bg:       #2d1010;
    --amber:        #d97706;
    --amber-bg:     #2d1f0a;
    --mono:         'IBM Plex Mono', monospace;
    --sans:         'IBM Plex Sans', sans-serif;
    --sidebar-w:    220px;
    --radius:       4px;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
    font-family: var(--sans);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #60a5fa; }

/* ---- Layout ---- */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}

.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.content {
    padding: 28px 28px;
    flex: 1;
}

/* ---- Sidebar ---- */
.sidebar-brand {
    padding: 20px 18px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-name {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-bright);
    display: block;
}

.sidebar-brand .brand-sub {
    font-size: 10px;
    color: var(--text-dim);
    letter-spacing: 0.05em;
    margin-top: 2px;
    display: block;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
}

.nav-label {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-dim);
    padding: 12px 18px 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 400;
    transition: color 0.15s, background 0.15s;
    border-left: 2px solid transparent;
}

.nav-link:hover {
    color: var(--text);
    background: var(--surface);
}

.nav-link.active {
    color: var(--text-bright);
    background: var(--surface);
    border-left-color: var(--accent);
}

.nav-link svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-link.active svg { opacity: 1; }

.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-dim);
}

.sidebar-footer .user-name {
    color: var(--text);
    font-weight: 500;
}

/* ---- Topbar ---- */
.page-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-bright);
    letter-spacing: 0.03em;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 12px;
    color: var(--text-dim);
}

.logout-link {
    color: var(--text-dim);
    font-size: 12px;
    font-family: var(--mono);
}

.logout-link:hover { color: var(--red); }

/* ---- Cards ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
}

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

.card-title {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dim);
    font-weight: 500;
}

.card-body { padding: 18px; }

/* ---- Status Grid (Dashboard) ---- */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.status-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    position: relative;
    overflow: hidden;
}

.status-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
}

.status-card.armed::before    { background: var(--green); }
.status-card.disarmed::before { background: var(--accent); }
.status-card.unknown::before  { background: var(--border); }
.status-card.fault::before    { background: var(--red); }
.status-card.stale::before    { background: var(--amber); }

.status-card .site-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-bright);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-card .area-name {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 10px;
}

.status-card .state-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 3px 7px;
    border-radius: 2px;
}

.state-badge.armed    { background: var(--green-bg);  color: var(--green); }
.state-badge.disarmed { background: var(--surface);   color: var(--accent); }
.state-badge.unknown  { background: var(--surface);   color: var(--text-dim); }
.state-badge.fault    { background: var(--red-bg);    color: var(--red); }
.state-badge.stale    { background: var(--amber-bg);  color: var(--amber); }

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

.armed    .state-dot { background: var(--green); }
.disarmed .state-dot { background: var(--accent); }
.unknown  .state-dot { background: var(--text-dim); }
.fault    .state-dot { background: var(--red); }
.stale    .state-dot { background: var(--amber); }

.status-card .last-seen {
    margin-top: 8px;
    font-size: 10px;
    color: var(--text-dim);
    font-family: var(--mono);
}

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dim);
    font-weight: 500;
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

td {
    padding: 10px 14px;
    color: var(--text);
    vertical-align: middle;
}

td.mono {
    font-family: var(--mono);
    font-size: 12px;
}

td.dim { color: var(--text-dim); }

/* ---- Event badges ---- */
.event-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: var(--mono);
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 2px;
    white-space: nowrap;
}

.badge-alarm    { background: var(--red-bg);   color: var(--red);   }
.badge-restore  { background: var(--green-bg); color: var(--green); }
.badge-arm      { background: var(--green-bg); color: var(--green); }
.badge-disarm   { background: var(--surface);  color: var(--accent);}
.badge-tamper   { background: var(--amber-bg); color: var(--amber); }
.badge-fault    { background: var(--amber-bg); color: var(--amber); }
.badge-test     { background: var(--surface);  color: var(--text-dim);}
.badge-default  { background: var(--surface);  color: var(--text-dim);}

/* ---- Forms ---- */
.form-group {
    margin-bottom: 16px;
}

label {
    display: block;
    font-size: 11px;
    font-family: var(--mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-bright);
    font-family: var(--sans);
    font-size: 13px;
    padding: 8px 12px;
    outline: none;
    transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
}

select {
    cursor: pointer;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 7px 14px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

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

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

.btn-secondary {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--surface);
    border-color: #3a4458;
    color: var(--text-bright);
}

.btn-danger {
    background: var(--red-bg);
    border-color: var(--red-dim);
    color: var(--red);
}

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

.btn-sm {
    font-size: 10px;
    padding: 4px 10px;
}

/* ---- Filters bar ---- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 18px;
}

.filter-bar .form-group {
    margin-bottom: 0;
    min-width: 140px;
}

.filter-bar select,
.filter-bar input {
    min-width: 0;
}

/* ---- Pagination ---- */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-dim);
}

.page-link {
    padding: 4px 9px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 11px;
    transition: background 0.1s;
}

.page-link:hover { background: var(--surface-2); color: var(--text); }

.page-link.current {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ---- Alerts ---- */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid;
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-error   { background: var(--red-bg);   border-color: var(--red-dim);   color: var(--red);   }
.alert-success { background: var(--green-bg); border-color: var(--green-dim); color: var(--green); }
.alert-info    { background: var(--surface);  border-color: var(--border);    color: var(--text);  }

/* ---- Login page ---- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-box {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px 32px;
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo .brand {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-dim);
    display: block;
    margin-top: 10px;
}

.login-logo .brand-main {
    font-family: var(--mono);
    font-size: 18px;
    font-weight: 500;
    color: var(--text-bright);
    letter-spacing: 0.1em;
}

/* ---- Stats row ---- */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}

.stat-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.stat-box .stat-value {
    font-family: var(--mono);
    font-size: 26px;
    font-weight: 500;
    color: var(--text-bright);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-box .stat-label {
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-dim);
}

/* ---- Misc ---- */
.empty-state {
    padding: 48px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}

.text-mono { font-family: var(--mono); }
.text-dim  { color: var(--text-dim);   }
.text-sm   { font-size: 12px;          }
.mt-0 { margin-top: 0; }

/* Auto-refresh indicator */
.refresh-indicator {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 5px;
}

.refresh-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main    { margin-left: 0; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .status-grid { grid-template-columns: repeat(2, 1fr); }
}
