*{box-sizing:border-box}body{margin:0;font-family:Arial,sans-serif;background:#f4f6f8;color:#1f2937}.topbar{position:fixed;top:0;left:0;right:0;height:54px;background:#111827;color:#fff;display:flex;align-items:center;justify-content:space-between;padding:0 18px;z-index:10}.brand{font-weight:700}.top-user a{color:#fff}.shell{display:flex;padding-top:54px;min-height:100vh}.sidebar{position:fixed;top:54px;bottom:0;left:0;width:210px;background:#1f2937;padding:10px;overflow:auto}.sidebar a,.sidebar .section{display:block}.sidebar a{color:#e5e7eb;text-decoration:none;padding:8px 10px;border-radius:5px}.sidebar a:hover{background:#374151}.sidebar .section{color:#9ca3af;font-size:11px;text-transform:uppercase;margin:14px 10px 5px}.content{margin-left:210px;padding:16px;width:calc(100% - 210px)}.content-full{margin-left:0;width:100%}.cards{display:grid;grid-template-columns:repeat(5,minmax(120px,1fr));gap:10px;margin-bottom:12px}.card{background:#fff;border:1px solid #e5e7eb;border-radius:8px;padding:14px}.kpi-label{font-size:12px;color:#6b7280}.kpi{font-size:28px;font-weight:700;margin-top:4px}.table-card{padding:0}.table-title{padding:12px 14px;font-weight:700;border-bottom:1px solid #e5e7eb}.table-scroll{overflow:auto;max-height:calc(100vh - 230px)}table{width:100%;border-collapse:collapse;background:#fff}th,td{padding:8px 10px;border-bottom:1px solid #e5e7eb;text-align:left;font-size:13px;white-space:nowrap}th{position:sticky;top:0;background:#f9fafb;z-index:2}.login-wrap{min-height:calc(100vh - 54px);display:flex;align-items:center;justify-content:center}.login-card{width:360px}.login-card h1{margin-bottom:2px}.muted{color:#6b7280;margin-top:0}.login-card label{display:block;margin:10px 0 5px}.login-card input{width:100%;padding:10px;border:1px solid #d1d5db;border-radius:6px}.login-card button{width:100%;padding:10px;margin-top:14px;border:0;border-radius:6px;background:#111827;color:#fff;font-weight:700}.alert{background:#fee2e2;color:#991b1b;padding:9px;border-radius:6px;margin:10px 0}@media(max-width:900px){.cards{grid-template-columns:repeat(2,1fr)}.sidebar{width:170px}.content{margin-left:170px;width:calc(100% - 170px)}}
.page-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px}.page-head h1{margin:0 0 3px;font-size:22px}.btn{border:1px solid #d1d5db;background:#fff;color:#111827;border-radius:6px;padding:8px 11px;cursor:pointer;font-weight:600}.btn.primary{background:#111827;color:#fff;border-color:#111827}.btn.danger{color:#b91c1c}.btn.small{padding:5px 8px;font-size:12px}.actions{display:flex;gap:5px;align-items:center}.inline-form{display:inline}.alert.success{background:#dcfce7;color:#166534}.badge{display:inline-block;padding:3px 7px;border-radius:999px;font-size:11px;font-weight:700}.badge.up{background:#dcfce7;color:#166534}.muted-badge{background:#e5e7eb;color:#4b5563}.table-tools{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:9px 10px;border-bottom:1px solid #e5e7eb}.table-search{width:min(360px,65vw);padding:7px 9px;border:1px solid #d1d5db;border-radius:6px}.empty{text-align:center;color:#6b7280;padding:24px}.modal{position:fixed;inset:0;background:rgba(17,24,39,.48);z-index:50;display:none;align-items:center;justify-content:center;padding:18px}.modal.show{display:flex}.modal-card{width:min(560px,100%);max-height:90vh;overflow:auto;background:#fff;border-radius:10px;box-shadow:0 20px 50px rgba(0,0,0,.25)}.modal-card.wide{width:min(760px,100%)}.modal-head{display:flex;align-items:center;justify-content:space-between;padding:12px 14px;border-bottom:1px solid #e5e7eb}.modal-close{border:0;background:transparent;font-size:25px;cursor:pointer}.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:14px 16px;padding:16px}.form-grid label{display:block;font-size:12px;font-weight:700;color:#374151;letter-spacing:.01em}.form-grid input:not([type=checkbox]):not([type=radio]),.form-grid select,.form-grid textarea,.table-search,.login-card input{width:100%;margin-top:6px;padding:10px 12px;border:1px solid #cbd5e1;border-radius:9px;background:#fff;color:#111827;font:inherit;line-height:1.35;box-shadow:0 1px 2px rgba(15,23,42,.04);transition:border-color .15s ease,box-shadow .15s ease,background .15s ease}.form-grid input:not([type=checkbox]):not([type=radio]):hover,.form-grid select:hover,.form-grid textarea:hover,.table-search:hover,.login-card input:hover{border-color:#94a3b8}.form-grid input:not([type=checkbox]):not([type=radio]):focus,.form-grid select:focus,.form-grid textarea:focus,.table-search:focus,.login-card input:focus{outline:none;border-color:#64748b;box-shadow:0 0 0 3px rgba(100,116,139,.14);background:#fff}.form-grid input::placeholder,.form-grid textarea::placeholder,.table-search::placeholder,.login-card input::placeholder{color:#9ca3af}.form-grid select{appearance:auto;cursor:pointer}.form-grid textarea{min-height:88px;resize:vertical}.form-grid .check{display:flex;gap:8px;align-items:center;min-height:40px}.form-grid .check input{width:16px;height:16px;margin:0;accent-color:#111827}.form-grid .check label{font-weight:600}.form-grid input:disabled,.form-grid select:disabled,.form-grid textarea:disabled{background:#f8fafc;color:#94a3b8;cursor:not-allowed}.modal-card{border:1px solid #e2e8f0}.modal-head{background:#f8fafc}.modal-head strong{font-size:15px}.login-card input{margin-top:0}.table-search{margin-top:0;padding:8px 11px}.span-2{grid-column:1/-1}.modal-actions{display:flex;justify-content:flex-end;gap:8px;padding-top:4px}.sidebar a.active{background:#374151;color:#fff;font-weight:700}@media(max-width:700px){.page-head{align-items:flex-start}.form-grid{grid-template-columns:1fr}.span-2{grid-column:auto}.actions{flex-wrap:wrap}}

.badge.down{background:#fee2e2;color:#991b1b}.badge.stale{background:#fef3c7;color:#92400e}.filter-card{margin-bottom:12px;padding:12px}.filter-grid{display:grid;grid-template-columns:repeat(4,minmax(140px,1fr));gap:10px;align-items:end}.history-filter{grid-template-columns:1.1fr 1.5fr 1fr 1fr .8fr auto}.filter-grid label{font-size:12px;font-weight:700;color:#374151}.filter-grid input,.filter-grid select{width:100%;margin-top:5px;padding:9px 11px;border:1px solid #cbd5e1;border-radius:9px;background:#fff;color:#111827;font:inherit;box-shadow:0 1px 2px rgba(15,23,42,.04)}.filter-grid input:focus,.filter-grid select:focus{outline:none;border-color:#64748b;box-shadow:0 0 0 3px rgba(100,116,139,.14)}.filter-actions{display:flex;gap:7px;justify-content:flex-end}.page-actions{display:flex;gap:7px}.live-cards{grid-template-columns:repeat(4,minmax(120px,1fr))}@media(max-width:1000px){.filter-grid,.history-filter{grid-template-columns:repeat(2,minmax(140px,1fr))}}@media(max-width:700px){.filter-grid,.history-filter{grid-template-columns:1fr}.live-cards{grid-template-columns:repeat(2,1fr)}.filter-actions{justify-content:flex-start}}

/* Phase 3.1 - Legacy Import */
.legacy-warning{margin-bottom:12px}.legacy-warning p{margin:8px 0}.legacy-cards{grid-template-columns:repeat(5,minmax(120px,1fr))}.legacy-actions-card{margin-bottom:12px;padding:14px}.legacy-actions-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:10px}.legacy-action-grid{display:grid;grid-template-columns:repeat(4,minmax(160px,1fr));gap:10px}.legacy-action-grid form{display:flex;gap:7px;align-items:center}.legacy-action-grid select,.legacy-filter select{width:100%;padding:8px 10px;border:1px solid #cbd5e1;border-radius:9px;background:#fff;color:#111827}.legacy-note{margin:12px 0 0}.legacy-filter{display:flex;gap:7px;align-items:center;min-width:280px}.legacy-preview{max-height:calc(100vh - 410px);min-height:220px}.legacy-runs{margin-top:12px}.legacy-runs .table-scroll{max-height:260px}code{background:#f1f5f9;padding:2px 5px;border-radius:5px;font-size:12px}@media(max-width:1100px){.legacy-cards{grid-template-columns:repeat(3,1fr)}.legacy-action-grid{grid-template-columns:repeat(2,1fr)}}@media(max-width:700px){.legacy-cards{grid-template-columns:repeat(2,1fr)}.legacy-action-grid{grid-template-columns:1fr}.legacy-filter{min-width:0;width:100%}.legacy-action-grid form{align-items:stretch;flex-direction:column}}

/* ==========================================================
   GLOBAL COMPACT ONE-SCREEN BASELINE
   Uptime V2 standard: page itself stays inside the monitor;
   tables/panels scroll internally when data is long.
   ========================================================== */
:root{
  --topbar-h:48px;
  --sidebar-w:190px;
  --page-gap:8px;
}

@media (min-width:901px){
  body.app-auth{overflow:hidden}
  .topbar{height:var(--topbar-h);padding:0 14px}
  .shell{padding-top:var(--topbar-h);height:100vh;min-height:0}
  .sidebar{top:var(--topbar-h);width:var(--sidebar-w);padding:7px;overflow-y:auto}
  .sidebar a{padding:6px 8px;font-size:13px}
  .sidebar .section{font-size:10px;margin:10px 8px 4px}
  .content{margin-left:var(--sidebar-w);width:calc(100% - var(--sidebar-w));height:calc(100vh - var(--topbar-h));padding:10px;overflow:hidden;min-height:0}
  .content-full{margin-left:0;width:100%}
}

.screen-page{
  height:100%;
  min-height:0;
  display:flex;
  flex-direction:column;
  gap:var(--page-gap);
}

.screen-page .page-head{margin:0;min-height:34px;flex:0 0 auto}
.screen-page .page-head h1{font-size:20px;line-height:1.1;margin:0 0 1px}
.screen-page .page-head .muted{font-size:12px;line-height:1.2;margin:0}
.screen-page > .alert{margin:0;flex:0 0 auto;padding:7px 10px;font-size:12px}

/* KPI cards: compact, still readable */
.screen-page .cards{gap:8px;margin:0;flex:0 0 auto}
.screen-page .card{border-radius:8px}
.screen-page .cards .card{padding:8px 10px;min-height:62px}
.screen-page .kpi-label{font-size:11px;line-height:1.1}
.screen-page .kpi{font-size:23px;line-height:1.05;margin-top:3px}
.screen-page .cards .muted{font-size:11px;margin:2px 0 0}

/* Forms / filters: one compact row on desktop */
.screen-page .filter-card{margin:0;padding:7px 9px;flex:0 0 auto}
.screen-page .filter-grid{grid-template-columns:repeat(4,minmax(120px,1fr)) auto;gap:7px;align-items:end}
.screen-page .history-filter{grid-template-columns:1fr 1.35fr .85fr .85fr .7fr auto}
.screen-page .filter-grid label{font-size:11px}
.screen-page .filter-grid input,.screen-page .filter-grid select{margin-top:3px;padding:7px 9px;border-radius:7px;min-height:34px}
.screen-page .filter-actions{gap:5px;justify-content:flex-end;align-items:end;white-space:nowrap}
.screen-page .btn{padding:7px 10px;border-radius:7px;font-size:12px;line-height:1.2}
.screen-page .btn.small{padding:5px 8px;font-size:11px}

/* Core rule: table fills remaining viewport and scrolls internally */
.screen-table,
.dashboard-page > .table-card,
.master-page > .table-card,
.monitoring-page > .table-card{
  flex:1 1 auto;
  min-height:0;
  margin:0;
  display:flex;
  flex-direction:column;
  overflow:hidden;
}
.screen-table .table-scroll,
.dashboard-page > .table-card .table-scroll,
.master-page > .table-card .table-scroll,
.monitoring-page > .table-card .table-scroll{
  flex:1 1 auto;
  min-height:0;
  max-height:none;
  overflow:auto;
}
.screen-page .table-tools,.screen-page .table-title{padding:7px 9px;min-height:34px;flex:0 0 auto;font-size:12px}
.screen-page .table-search{height:30px;padding:5px 9px;border-radius:7px;font-size:12px}
.screen-page th,.screen-page td{padding:6px 8px;font-size:12px;line-height:1.2}
.screen-page th{height:30px}
.screen-page .badge{padding:2px 6px;font-size:10px}
.screen-page .empty{padding:16px}

/* Master pages */
.master-page .page-head{flex:0 0 auto}
.master-page .table-card{margin:0}

/* Live Device: summary + filter + table all inside one viewport */
.live-page .live-cards{grid-template-columns:repeat(4,minmax(105px,1fr))}
.live-page .cards .card{min-height:58px}

/* Dashboard */
.dashboard-page .cards{grid-template-columns:repeat(5,minmax(105px,1fr))}
.dashboard-page .cards .card{min-height:58px}

/* Legacy Import is denser because it has more controls than other screens. */
.legacy-page{gap:7px}
.legacy-page .legacy-cards{grid-template-columns:repeat(5,minmax(100px,1fr))}
.legacy-page .legacy-cards .card{min-height:58px;padding:7px 9px}
.legacy-page .legacy-actions-card{margin:0;padding:8px 10px;flex:0 0 auto}
.legacy-page .legacy-actions-head{margin-bottom:5px}
.legacy-page .legacy-action-grid{display:flex;flex-wrap:wrap;gap:5px;align-items:center}
.legacy-page .legacy-action-grid form{display:flex;gap:5px;align-items:center}
.legacy-page .legacy-action-grid select,.legacy-page .legacy-filter select{padding:6px 8px;border-radius:7px;min-height:31px;font-size:12px}
.legacy-page .legacy-note{font-size:11px;line-height:1.2;margin:6px 0 0}
.legacy-page .legacy-preview-card{flex:1 1 auto;min-height:150px;display:flex;flex-direction:column;overflow:hidden;margin:0}
.legacy-page .legacy-preview-card .legacy-preview{flex:1 1 auto;min-height:0;max-height:none;overflow:auto}
.legacy-page .legacy-filter{min-width:220px}
.legacy-page .legacy-runs{flex:0 0 118px;min-height:0;margin:0;overflow:hidden;display:flex;flex-direction:column}
.legacy-page .legacy-runs .table-scroll{flex:1 1 auto;min-height:0;max-height:none;overflow:auto}
.legacy-page code{font-size:10px}

/* Compact modal while keeping comfortable inputs */
.screen-page .modal-card{max-height:88vh}
.screen-page .modal-head{padding:9px 12px}
.screen-page .form-grid{gap:9px 12px;padding:11px 12px}
.screen-page .form-grid input:not([type=checkbox]):not([type=radio]),
.screen-page .form-grid select,
.screen-page .form-grid textarea{padding:8px 10px;margin-top:4px;border-radius:8px}
.screen-page .form-grid textarea{min-height:68px}

@media(max-width:1100px){
  .screen-page .filter-grid{grid-template-columns:repeat(2,minmax(140px,1fr))}
  .screen-page .history-filter{grid-template-columns:repeat(3,minmax(120px,1fr))}
  .screen-page{height:auto;min-height:100%}
  body.app-auth{overflow:auto}
  .content{overflow:auto}
  .screen-table,.legacy-page .legacy-preview-card{min-height:360px}
  .legacy-page .legacy-action-grid{display:grid;grid-template-columns:repeat(2,1fr)}
}

@media(max-width:700px){
  .screen-page .filter-grid,.screen-page .history-filter{grid-template-columns:1fr}
  .dashboard-page .cards,.live-page .live-cards,.legacy-page .legacy-cards{grid-template-columns:repeat(2,1fr)}
  .legacy-page .legacy-action-grid{grid-template-columns:1fr}
}
