* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', Arial, sans-serif; background: #0f1117; color: #e0e0e0; height: 100vh; }

/* Login */
#screen-login { display: flex; align-items: center; justify-content: center; height: 100vh; background: radial-gradient(ellipse at 60% 40%, #1a0808 0%, #0a0c12 60%); }
.login-box { background: #13151f; padding: 40px; border-radius: 16px; width: 380px; box-shadow: 0 8px 50px rgba(0,0,0,0.7); border: 1px solid #252836; }
.login-logo { font-size: 2.2rem; font-weight: 800; text-align: center; margin-bottom: 2px; background: linear-gradient(135deg, #ef5350, #ff9100); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.login-sub { text-align: center; color: #555; margin-bottom: 4px; font-size: 0.82rem; letter-spacing: 1px; text-transform: uppercase; }
.login-divider { height: 1px; background: #252836; margin: 20px 0; }
.login-box input { width: 100%; padding: 13px 14px; margin-bottom: 12px; background: #0a0c12; border: 1px solid #2a2d3a; border-radius: 10px; color: #e0e0e0; font-size: 0.95rem; transition: border-color 0.15s; }
.login-box input:focus { outline: none; border-color: #e53935; }
.login-box button { width: 100%; padding: 13px; background: linear-gradient(135deg, #e53935, #c62828); border: none; border-radius: 10px; color: white; font-size: 1rem; font-weight: 700; cursor: pointer; margin-top: 4px; letter-spacing: 0.5px; }
.login-box button:hover { background: linear-gradient(135deg, #ef5350, #d32f2f); }
.error-msg { color: #ef5350; font-size: 0.85rem; margin-top: 8px; text-align: center; }

/* Screen */
.screen { display: none !important; }
.screen.active { display: flex !important; }
#screen-login.active { display: flex !important; position: fixed; inset: 0; z-index: 9999; background: #0f1117; align-items: center; justify-content: center; }
#screen-app { height: 100vh; overflow: hidden; }
/* Hide app content completely until logged in */
#screen-app:not(.active) { visibility: hidden; pointer-events: none; }

/* Sidebar */
#sidebar { width: 220px; background: #1a1d27; display: flex; flex-direction: column; padding: 20px 0; flex-shrink: 0; }
.sidebar-logo { font-size: 1.3rem; font-weight: 700; padding: 0 20px 20px; border-bottom: 1px solid #2a2d3a; }
#sidebar ul { list-style: none; padding: 16px 0; flex: 1; }
#sidebar ul li { padding: 12px 20px; cursor: pointer; border-radius: 0; transition: background 0.15s; font-size: 0.95rem; }
#sidebar ul li:hover, #sidebar ul li.active { background: #252836; color: #e53935; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid #2a2d3a; font-size: 0.85rem; }
#user-name { display: block; color: #aaa; margin-bottom: 8px; }
#btn-logout { background: none; border: 1px solid #444; color: #aaa; padding: 6px 12px; border-radius: 6px; cursor: pointer; width: 100%; }
#btn-logout:hover { border-color: #e53935; color: #e53935; }

/* Content */
#content { flex: 1; overflow-y: auto; padding: 32px; }
.page { display: none; }
.page.active { display: block; }
h1 { font-size: 1.6rem; margin-bottom: 24px; }
h2 { font-size: 1.1rem; margin-bottom: 16px; color: #bbb; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.page-header h1 { margin-bottom: 0; }

/* Cards */
.card { background: #1a1d27; border-radius: 12px; padding: 24px; margin-bottom: 20px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.stat-card { background: #1a1d27; border-radius: 12px; padding: 24px; text-align: center; }
.stat-num { font-size: 2.5rem; font-weight: 700; color: #e53935; }
.stat-label { color: #888; font-size: 0.9rem; margin-top: 4px; }

/* Quick actions */
.quick-actions { background: #1a1d27; border-radius: 12px; padding: 24px; }
.quick-btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.quick-btn-row .btn-primary, .quick-btn-row .btn-secondary { flex: 1 1 auto; min-width: 140px; text-align: center; }

/* Buttons */
.btn-primary { background: #e53935; color: white; border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.btn-primary:hover { background: #c62828; }
.btn-secondary { background: #252836; color: #e0e0e0; border: 1px solid #333; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-size: 0.9rem; }
.btn-secondary:hover { background: #2e3147; }
.btn-ghost { background: none; color: #aaa; border: 1px solid #444; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-size: 0.9rem; }
.btn-ghost:hover { color: #e0e0e0; border-color: #666; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; border-radius: 6px; cursor: pointer; border: none; }
.btn-danger { background: #b71c1c; color: white; }

/* Forms */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 0.85rem; color: #888; margin-bottom: 5px; }
.form-row input, .form-row select, .form-row textarea { width: 100%; padding: 10px; background: #0f1117; border: 1px solid #333; border-radius: 8px; color: #e0e0e0; font-size: 0.95rem; }
.form-row textarea { min-height: 80px; resize: vertical; }

/* Calc */
.calc-container { display: grid; grid-template-columns: 320px 1fr; gap: 20px; }
.calc-devices, .calc-items { grid-column: 2; }
.calc-devices { max-height: 400px; overflow-y: auto; }
.device-search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.device-search-row input, .device-search-row select { flex: 1; padding: 8px; background: #0f1117; border: 1px solid #333; border-radius: 6px; color: #e0e0e0; font-size: 0.9rem; }
.device-item { display: flex; justify-content: space-between; align-items: center; padding: 10px; border-bottom: 1px solid #252836; }
.device-item:hover { background: #252836; }
.device-item-info .name { font-weight: 600; font-size: 0.9rem; }
.device-item-info .meta { color: #888; font-size: 0.8rem; }
#calc-items-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 0.9rem; }
#calc-items-table th { text-align: left; color: #888; padding: 8px; border-bottom: 1px solid #333; }
#calc-items-table td { padding: 8px; border-bottom: 1px solid #1f2233; }
#calc-items-table input { width: 60px; padding: 4px 6px; background: #0f1117; border: 1px solid #333; border-radius: 4px; color: #e0e0e0; }
#calc-items-table select { padding: 4px 6px; background: #0f1117; border: 1px solid #333; border-radius: 4px; color: #e0e0e0; }

.calc-results { background: #0f1117; border-radius: 8px; padding: 20px; margin-bottom: 16px; }
.calc-results .result-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #1f2233; font-size: 0.9rem; }
.calc-results .result-row.total { font-weight: 700; font-size: 1.1rem; color: #e53935; border-bottom: none; padding-top: 12px; }
.calc-results .battery-rec { margin-top: 12px; padding: 12px; background: #1a1d27; border-radius: 8px; border-left: 3px solid #e53935; }
.calc-actions { display: flex; gap: 10px; }

/* Filter row */
.filter-row { display: flex; gap: 12px; margin-bottom: 20px; }
.filter-row input, .filter-row select { padding: 9px 12px; background: #1a1d27; border: 1px solid #2a2d3a; border-radius: 8px; color: #e0e0e0; font-size: 0.9rem; }
.filter-row input { flex: 1; }

/* Device library */
.device-lib-card { background: #1a1d27; border-radius: 10px; padding: 16px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: flex-start; }
.device-lib-info .name { font-weight: 700; }
.device-lib-info .meta { color: #888; font-size: 0.85rem; margin-top: 4px; }
.cd-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cd-tag { background: #252836; border-radius: 4px; padding: 3px 8px; font-size: 0.78rem; color: #ccc; }
.cd-tag span { color: #e53935; font-weight: 600; }
.csfm-badge { display:inline-block; background:#0a1520; color:#4fc3f7; border:1px solid #1565c044; padding:3px 10px; border-radius:6px; font-size:0.72rem; font-weight:700; letter-spacing:0.5px; }

/* Presence dots */
.presence-dot { display:inline-block; width:10px; height:10px; border-radius:50%; flex-shrink:0; transition:background 0.3s; }
.presence-dot.online { background:#4caf50; box-shadow:0 0 6px #4caf5088; animation: pulse-green 2s infinite; }
.presence-dot.idle { background:#ff9800; box-shadow:0 0 6px #ff980088; }
.presence-dot.offline { background:#555; }
@keyframes pulse-green { 0%,100%{box-shadow:0 0 4px #4caf5088} 50%{box-shadow:0 0 10px #4caf50cc} }

/* Panels / docs / calcs list */
.list-card { background: #1a1d27; border-radius: 10px; padding: 16px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.list-card .info .name { font-weight: 700; }
.list-card .info .meta { color: #888; font-size: 0.85rem; margin-top: 3px; }
.list-card .actions { display: flex; gap: 8px; }

/* Projects tab */
.projects-toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; }
.search-wrap { flex: 1; position: relative; }
.search-wrap .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 0.95rem; pointer-events: none; }
.search-wrap input { width: 100%; padding: 10px 12px 10px 36px; background: #1a1d27; border: 1px solid #2a2d3a; border-radius: 8px; color: #e0e0e0; font-size: 0.9rem; }
.search-wrap input:focus { outline: none; border-color: #e53935; }
.projects-toolbar select { padding: 10px 12px; background: #1a1d27; border: 1px solid #2a2d3a; border-radius: 8px; color: #e0e0e0; font-size: 0.9rem; }
.projects-stats { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.proj-stat { background: #1a1d27; border-radius: 8px; padding: 10px 16px; font-size: 0.82rem; color: #888; border: 1px solid #252836; }
.proj-stat strong { color: #e0e0e0; }

/* Project cards */
.project-card { background: #1a1d27; border-radius: 12px; padding: 0; margin-bottom: 12px; overflow: hidden; border: 1px solid #252836; transition: border-color 0.15s; }
.project-card:hover { border-color: #3a3d4a; }
.project-card-header { padding: 14px 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.project-card-title { font-weight: 700; font-size: 1rem; margin-bottom: 3px; }
.project-card-address { color: #888; font-size: 0.82rem; }
.project-card-badge { background: #252836; border-radius: 6px; padding: 4px 10px; font-size: 0.75rem; color: #aaa; white-space: nowrap; }
.project-card-stats { display: flex; gap: 0; border-top: 1px solid #252836; }
.project-stat-item { flex: 1; padding: 10px 14px; text-align: center; border-right: 1px solid #252836; }
.project-stat-item:last-child { border-right: none; }
.project-stat-item .sv { font-size: 1rem; font-weight: 700; }
.project-stat-item .sl { color: #888; font-size: 0.72rem; margin-top: 2px; }
.project-card-footer { display: flex; gap: 0; border-top: 1px solid #252836; }
.project-card-footer button, .project-card-footer a { flex: 1; padding: 10px 6px; background: none; border: none; border-right: 1px solid #252836; color: #aaa; cursor: pointer; font-size: 0.78rem; text-align: center; text-decoration: none; transition: background 0.15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.project-card-footer button:last-child { border-right: none; }
.project-card-footer button:hover { background: #252836; color: #e0e0e0; }
.project-card-footer button.load-btn { color: #4fc3f7; }
.project-card-footer button.load-btn:hover { background: #0a1520; }
.project-card-footer button.del-btn { color: #ef5350; }
.project-card-footer button.del-btn:hover { background: #1a0808; }

@media (max-width: 600px) {
  .projects-toolbar { flex-direction: column; }
  .projects-toolbar select { width: 100%; }
  .project-card-stats { flex-wrap: wrap; }
  .project-stat-item { min-width: 50%; }
}

/* Modal */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 999; }
#modal-overlay.hidden { display: none; }
#modal-box { background: #1a1d27; border-radius: 12px; padding: 28px; width: 520px; max-width: 95vw; max-height: 85vh; overflow-y: auto; }
#modal-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 20px; }
#modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* Admin only */
.admin-only { display: none; }
body.is-admin .admin-only { display: block; }
body.is-admin #sidebar li.admin-only { display: list-item; }

/* ── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .calc-container { grid-template-columns: 1fr; }
  .calc-devices { grid-column: 1; max-height: 300px; }
  .calc-items { grid-column: 1; }
  #screen-app { flex-direction: column; }
  #sidebar { width: 100%; flex-direction: row; padding: 0; height: auto; border-bottom: 1px solid #2a2d3a; overflow-x: auto; }
  .sidebar-logo { display: none; }
  #sidebar ul { display: flex; flex-direction: row; padding: 0; flex: 1; overflow-x: auto; white-space: nowrap; }
  #sidebar ul li { padding: 14px 12px; font-size: 0.75rem; flex-shrink: 0; border-radius: 0; }
  #sidebar ul li:hover, #sidebar ul li.active { background: #252836; border-bottom: 2px solid #e53935; }
  .sidebar-footer { display: none; }
  #content { padding: 16px; }
  h1 { font-size: 1.3rem; }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  #sidebar ul li { padding: 12px 8px; font-size: 0.68rem; }
  .calc-actions { flex-wrap: wrap; }
  .calc-actions button { flex: 1; min-width: 100px; }
  .filter-row { flex-direction: column; }
  .filter-row input, .filter-row select { width: 100%; }
  .page-header { flex-direction: column; gap: 10px; }
  .page-header h1 { margin-bottom: 0; }
  .list-card { flex-direction: column; gap: 10px; }
  .list-card .actions { display: flex; gap: 8px; justify-content: flex-end; }
  .device-lib-card { flex-direction: column; gap: 8px; }
}
