*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f1f5f9; --surface: #ffffff; --border: #e2e8f0; --text: #1e293b;
  --text-secondary: #64748b; --primary: #6366f1; --primary-hover: #4f46e5;
  --success: #22c55e; --warning: #f59e0b; --danger: #ef4444; --info: #3b82f6;
  --radius: 10px; --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }
.screen { display: none; } .screen.active { display: flex; }
.hidden { display: none !important; }

/* LOGIN */
#login-screen { align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 50%, #c7d2fe 100%); }
.login-card { background: var(--surface); border-radius: 16px; padding: 40px; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.1); }
.login-header { text-align: center; margin-bottom: 28px; }
.login-header h1 { font-size: 1.5rem; margin: 12px 0 4px; }
.login-header p { color: var(--text-secondary); font-size: .9rem; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 6px; color: var(--text-secondary); }
.field input { width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: 8px; font-size: .95rem; transition: border-color .2s; }
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
.hint { font-size: .78rem; color: var(--text-secondary); margin-top: 4px; display: block; }
#login-form button[type=submit] { width: 100%; padding: 12px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: background .2s; margin-top: 8px; }
#login-form button[type=submit]:hover { background: var(--primary-hover); }
.error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; border-radius: 8px; padding: 10px 14px; margin-top: 12px; font-size: .85rem; }

/* HEADER */
header { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.header-left { display: flex; align-items: center; gap: 10px; }
.header-left h2 { font-size: 1.15rem; }
.header-right { display: flex; align-items: center; gap: 8px; }
.badge { background: #eef2ff; color: var(--primary); padding: 4px 12px; border-radius: 20px; font-size: .8rem; font-weight: 600; }
header button { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 1rem; transition: background .15s; }
header button:hover { background: var(--bg); }

/* LAYOUT */
#dashboard-screen { flex-direction: column; height: 100vh; }
.main-content { display: flex; flex: 1; overflow: hidden; }
#device-list-panel { width: 360px; min-width: 300px; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; }
.panel-header { padding: 12px; border-bottom: 1px solid var(--border); }
#device-search { width: 100%; padding: 9px 14px; border: 1.5px solid var(--border); border-radius: 8px; font-size: .9rem; }
#device-search:focus { outline: none; border-color: var(--primary); }
.scrollable { flex: 1; overflow-y: auto; }
#device-detail-panel { flex: 1; overflow-y: auto; padding: 24px; background: var(--bg); }
.placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-secondary); gap: 16px; }

/* DEVICE LIST ITEMS */
.device-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .15s; }
.device-item:hover { background: #f8fafc; }
.device-item.active { background: #eef2ff; border-left: 3px solid var(--primary); }
.device-status { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.device-status.connected { background: var(--success); box-shadow: 0 0 6px rgba(34,197,94,.4); }
.device-status.disconnected { background: var(--danger); }
.device-status.unknown { background: var(--text-secondary); }
.device-info { flex: 1; min-width: 0; }
.device-name { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-type { font-size: .78rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-alarms { display: flex; gap: 4px; }
.alarm-badge { font-size: .7rem; padding: 2px 6px; border-radius: 10px; font-weight: 700; color: #fff; }
.alarm-badge.critical { background: var(--danger); }
.alarm-badge.major { background: #f97316; }
.alarm-badge.minor { background: var(--warning); }
.alarm-badge.warning { background: var(--info); }
.loading { text-align: center; padding: 24px; color: var(--text-secondary); }

/* DETAIL VIEW */
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.detail-title { font-size: 1.4rem; font-weight: 700; }
.detail-id { font-size: .8rem; color: var(--text-secondary); margin-top: 2px; }
.status-pill { padding: 5px 14px; border-radius: 20px; font-size: .8rem; font-weight: 600; }
.status-pill.connected { background: #dcfce7; color: #166534; }
.status-pill.disconnected { background: #fef2f2; color: #991b1b; }
.status-pill.unknown { background: #f1f5f9; color: #475569; }

.tab-bar { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn { padding: 10px 18px; background: none; border: none; font-size: .88rem; font-weight: 600; cursor: pointer; color: var(--text-secondary); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; } .tab-content.active { display: block; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.info-card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.info-card h3 { font-size: .85rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }
.info-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #f1f5f9; font-size: .88rem; }
.info-row:last-child { border-bottom: none; }
.info-label { color: var(--text-secondary); }
.info-value { font-weight: 500; text-align: right; max-width: 60%; word-break: break-all; }

/* ALARMS & EVENTS TABLE */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.data-table th { background: #f8fafc; text-align: left; padding: 10px 14px; font-size: .8rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.data-table td { padding: 10px 14px; border-top: 1px solid var(--border); font-size: .88rem; }
.severity { padding: 2px 8px; border-radius: 6px; font-size: .78rem; font-weight: 600; }
.severity.CRITICAL { background: #fef2f2; color: var(--danger); }
.severity.MAJOR { background: #fff7ed; color: #c2410c; }
.severity.MINOR { background: #fefce8; color: #a16207; }
.severity.WARNING { background: #eff6ff; color: #1d4ed8; }
.empty-state { text-align: center; padding: 40px; color: var(--text-secondary); font-size: .9rem; }

/* MEASUREMENTS */
.measurement-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.measurement-card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); text-align: center; }
.measurement-card .value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.measurement-card .unit { font-size: .85rem; color: var(--text-secondary); }
.measurement-card .label { font-size: .8rem; color: var(--text-secondary); margin-top: 6px; }
.measurement-card .time { font-size: .72rem; color: #94a3b8; margin-top: 4px; }

@media (max-width: 768px) {
  .main-content { flex-direction: column; }
  #device-list-panel { width: 100%; min-width: unset; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  .info-grid { grid-template-columns: 1fr; }
}

