/* ============================================================
   SolworxS CCTV Planner – Stylesheet
   ============================================================ */

*, *::before, *::after { margin:0; padding:0; box-sizing:border-box; }

:root {
  --bg-dark:   #0a0f1e;
  --bg-mid:    #0f172a;
  --bg-panel:  #1e293b;
  --bg-card:   #273549;
  --accent:    #f59e0b;
  --accent2:   #3b82f6;
  --text:      #e2e8f0;
  --text-muted:#94a3b8;
  --border:    #334155;
  --radius:    8px;
  --radius-lg: 12px;
  --shadow:    0 4px 24px rgba(0,0,0,.35);
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ============================================================ LOGIN */
.login-screen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #0a0f1e 0%, #1a1040 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}

.login-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 360px;
  box-shadow: var(--shadow);
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  font-size: 40px;
  margin-bottom: 8px;
}

.login-logo-img {
  display: block;
  width: 64px !important;
  height: 62px !important;
  max-width: 64px;
  max-height: 62px;
  margin: 0 auto 10px;
  object-fit: contain;
}

.login-brand h1 {
  font-size: 26px;
  color: var(--accent);
  letter-spacing: 1px;
}

.login-brand p {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.login-form label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 14px;
}

.login-form input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border .2s;
}

.login-form input:focus { border-color: var(--accent2); }

.login-error {
  background: rgba(239,68,68,.15);
  border: 1px solid #ef4444;
  color: #fca5a5;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-top: 10px;
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #0a0f1e;
  font-weight: 700;
  font-size: 15px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  margin-top: 20px;
  transition: opacity .2s;
}
.btn-primary:hover { opacity: .88; }

.login-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 12px;
}

/* ============================================================ APP SHELL */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================ TOP NAV */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 54px;
  background: var(--bg-mid);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}

.topnav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon { font-size: 22px; }

.brand-icon-img {
  display: inline-block;
  width: 28px !important;
  height: 27px !important;
  max-width: 28px;
  max-height: 27px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .5px;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  padding: 2px 8px;
  background: var(--bg-panel);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.topnav-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-btn {
  padding: 7px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .18s;
}

.nav-btn:hover { background: var(--bg-card); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #0a0f1e; border-color: var(--accent); font-weight: 700; }
.btn-download { background: var(--accent2); color: white; border-color: var(--accent2); }
.btn-download:hover { opacity: .85; color: white; }
.btn-logout { color: #ef4444; border-color: #ef4444; }
.btn-logout:hover { background: rgba(239,68,68,.12); color: #ef4444; }

/* ============================================================ VIEW PANELS */
.view-panel {
  flex: 1;
  overflow: hidden;
  display: flex;
}

/* ============================================================ SIDEBAR */
.sidebar {
  width: 300px;
  background: var(--bg-mid);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
  flex-shrink: 0;
}

.sb-section {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.sb-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 12px;
}

.sb-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 10px;
}

.sb-input {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  margin-bottom: 10px;
  outline: none;
}
.sb-input:focus { border-color: var(--accent2); }

.file-label {
  display: block;
  padding: 10px 14px;
  background: var(--bg-panel);
  border: 1px dashed var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: border .18s;
}
.file-label:hover { border-color: var(--accent2); color: var(--text); }
.file-label input { display: none; }

/* Device category tabs */
.device-cat-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}
.device-cat-tab {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-panel);
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.device-cat-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f172a;
  font-weight: 700;
}
.device-cat-tab:hover:not(.active) {
  border-color: var(--accent2);
  color: var(--text);
}

/* Camera type grid – 3 columns × 2 rows */
.cam-type-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 2px;
}

.cam-type-btn {
  padding: 8px 4px 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all .18s;
}

.cam-png {
  width: 32px;
  height: 32px;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.4));
}

.cam-png-fallback { font-size: 22px; }

.cam-type-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(245,158,11,.08);
}
.cam-type-btn:hover { border-color: var(--accent2); }

/* Color row */
.color-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.color-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform .15s, border .15s;
}
.color-btn.active { border-color: white; transform: scale(1.2); }
.color-btn:hover { transform: scale(1.15); }

/* Action buttons in sidebar */
.btn-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.btn-row button { flex: 1; }

.btn-green {
  padding: 10px;
  background: #059669;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: opacity .2s;
}
.btn-green:hover { opacity: .85; }
.btn-green.off { background: #374151; }

.btn-blue {
  padding: 10px;
  background: var(--bg-panel);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all .18s;
}
.btn-blue.active-wiring { background: var(--accent2); color: white; border-color: var(--accent2); }

.btn-red {
  width: 100%;
  padding: 9px;
  background: rgba(220,38,38,.15);
  color: #ef4444;
  border: 1px solid #ef4444;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all .18s;
}
.btn-red:hover { background: #ef4444; color: white; }

.btn-sm {
  padding: 6px 12px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
}
.btn-sm:hover { border-color: var(--accent2); }
.btn-sm:disabled { opacity: .4; cursor: default; }

/* PDF nav */
.pdf-thumbs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
  margin-bottom: 10px;
}

.pdf-thumb {
  background: var(--bg-panel);
  border: 2px solid transparent;
  border-radius: 5px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: border .15s;
}
.pdf-thumb:hover { border-color: var(--border); }
.pdf-thumb.active-thumb { border-color: var(--accent2); color: var(--text); }

.pdf-nav-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.page-info-label {
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

/* Camera list */
.camera-list-wrap {
  font-size: 13px;
  color: var(--text-muted);
  max-height: 300px;
  overflow-y: auto;
}

.cam-item {
  background: var(--bg-card);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
  border-left: 4px solid #ef4444;
}

.cam-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.cam-item-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cam-item-name {
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
  flex: 1;
}

.cam-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.cam-item button {
  padding: 4px 10px;
  background: rgba(220,38,38,.15);
  color: #ef4444;
  border: 1px solid #ef4444;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}
.cam-item button:hover { background: #ef4444; color: white; }

/* ============================================================ WORKSPACE */
.workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.canvas-wrapper {
  width: 100%;
  height: 100%;
  padding: 16px;
}

#planCanvas {
  width: 100%;
  height: 100%;
  background: #f8fafc;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  touch-action: none;
  display: block;
}

.canvas-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(15,23,42,.9);
  color: var(--text-muted);
  padding: 16px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  border: 1px solid var(--border);
}

.zoom-controls {
  position: absolute;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.zoom-controls button {
  width: 36px;
  height: 36px;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.zoom-controls button:hover { border-color: var(--accent2); }

/* ============================================================ REPORT VIEW */
.report-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding: 24px;
  width: 100%;
  overflow-y: auto;
  max-height: calc(100vh - 54px);
}

.report-form-col,
.report-preview-col {
  min-width: 0;
  max-width: 100%;
  max-height: calc(100vh - 102px);
  overflow-y: auto;
  overflow-x: hidden;
}

.section-heading {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }

.form-group label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.form-group input,
.form-group textarea {
  padding: 10px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: vertical;
}
.form-group input:focus,
.form-group textarea:focus { border-color: var(--accent2); }

.readonly-input {
  background: var(--bg-card) !important;
  cursor: default;
  color: var(--text-muted) !important;
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.img-preview {
  margin-top: 10px;
}
.img-preview img {
  max-height: 80px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* Signature */
.sig-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.file-label-sm {
  padding: 5px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
}
.file-label-sm:hover { border-color: var(--accent2); color: var(--text); }

.sig-canvas {
  width: 100%;
  max-width: 540px;
  height: 120px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: crosshair;
  touch-action: none;
}

/* Report Preview */
.report-preview-col { overflow-y: auto; }

.report-preview-card {
  background: white;
  color: #1e293b;
  border-radius: var(--radius);
  padding: 20px;
  font-size: 13px;
  box-shadow: var(--shadow);
  min-height: 200px;
}

.report-preview-card h3 {
  color: #0f172a;
  margin-bottom: 4px;
}

.rp-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 14px;
}

.rp-logo img { max-height: 52px; }
.rp-logo-placeholder {
  font-size: 22px;
  font-weight: 700;
  color: #f59e0b;
}

.rp-meta { text-align: right; font-size: 11px; color: #64748b; }
.rp-meta strong { font-size: 13px; color: #0f172a; display: block; margin-bottom: 2px; }

.rp-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin-bottom: 14px;
  font-size: 12px;
}
.rp-info-grid .rp-label { color: #94a3b8; font-size: 10px; text-transform: uppercase; }
.rp-info-grid .rp-val { color: #1e293b; font-weight: 600; }

.rp-cam-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.rp-cam-table th {
  background: #f1f5f9;
  padding: 6px 8px;
  text-align: left;
  color: #64748b;
  font-size: 11px;
  text-transform: uppercase;
}
.rp-cam-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #e2e8f0;
  color: #334155;
}
.rp-cam-table tr:hover td { background: #f8fafc; }

/* ============================================================ MATERIALS VIEW */
.materials-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  padding: 24px;
  width: 100%;
  overflow-y: auto;
  max-height: calc(100vh - 54px);
}

.mat-form-col,
.mat-list-col {
  min-width: 0;     /* prevents grid children from overflowing their track */
  max-width: 100%;
  max-height: calc(100vh - 102px);
  overflow-y: auto;
  overflow-x: hidden;
}

.mat-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.btn-red-sm {
  padding: 5px 12px;
  background: rgba(220,38,38,.15);
  color: #ef4444;
  border: 1px solid #ef4444;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
}
.btn-red-sm:hover { background: #ef4444; color: white; }

.mat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.mat-table th {
  background: var(--bg-panel);
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.mat-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.mat-table tr:hover td { background: var(--bg-card); }

.cat-badge {
  display:inline-block;
  padding:2px 7px;
  margin:2px;
  border-radius:12px;
  background:rgba(245,158,11,.15);
  border:1px solid rgba(245,158,11,.35);
  color:#f59e0b;
  font-size:10px;
  white-space:nowrap;
}
.cat-badges-cell { max-width:200px; }

.mat-del-btn {
  padding: 4px 10px;
  background: transparent;
  color: #ef4444;
  border: 1px solid #ef4444;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}
.mat-del-btn:hover { background: #ef4444; color: white; }

/* Totals summary */
.mat-totals-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 16px;
  overflow: hidden;
}

.mat-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.mat-total-row:last-child { border-bottom: none; }
.mat-total-row span:last-child { font-weight: 700; }

.gst-row { background: rgba(59,130,246,.07); }
.gst-row span:last-child { color: var(--accent2); }

.grand-row { background: rgba(245,158,11,.1); }
.grand-row span { font-size: 15px !important; font-weight: 800 !important; color: var(--accent) !important; }

.btn-excel {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  background: #16a34a;
  color: white;
  border: none;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .2s;
  letter-spacing: .3px;
}
.btn-excel:hover { opacity: .88; }

.mat-table-wrap { overflow-x: auto; }

/* ============================================================ UTILITIES */
.hidden { display: none !important; }

/* ============================================================ SCROLLBARS */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent2); }

/* ============================================================ MOBILE */
@media (max-width: 768px) {
  body { overflow: auto; }

  .app { height: auto; overflow: visible; }

  .topnav {
    flex-direction: column;
    height: auto;
    padding: 10px;
    gap: 8px;
  }

  .topnav-actions {
    flex-wrap: wrap;
    justify-content: center;
  }

  #viewPlan {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .workspace {
    height: 60vh;
  }

  .report-layout,
  .materials-layout {
    grid-template-columns: 1fr;
    max-height: none;
  }
}