/* =========================
   Root & Global
========================= */
:root {
  --bg: #f5f5f7;
  --card-bg: #ffffff;
  --primary: #A77B1E;
  --primary-hover: #5A3E16;
  --border: #e5e7eb;
  --text-main: #111827;
  --text-muted: #6b7280;
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  margin: 0;
  padding: 24px;
  display: flex;
  justify-content: center;
}

/* =========================
   Layout / Card
========================= */
.wrapper {
  width: 100%;
  max-width: 780px;
}

.card {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  padding: 24px 28px 28px;
}

.card-header { margin-bottom: 20px; }

.title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-main);
  margin: 0;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--text-muted);
}

.section-title {
  margin: 20px 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* =========================
   Form Fields
========================= */
.field-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 14px;
}

.field-label {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-main);
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}


input[type="text"],
input[type="email"],
input[type="date"],
input[type="month"],
select {
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, .2);
}

.two-column {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* =========================
   Buttons
========================= */
.actions {
  margin-top: 22px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-secondary {
  background: #e5e7eb;
  color: #374151;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.footer-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
}

/* =========================
   Responsive
========================= */
@media (max-width: 640px) {
  .card { padding: 18px 16px 20px; }
  .two-column { grid-template-columns: 1fr; }
}

/* =========================
   Site Drawing
========================= */
.site-palette{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-bottom:10px;
}

.palette-item{
  border-radius:999px;
  border:1px solid var(--border);
  background:#f9fafb;
  padding:6px 12px;
  font-size:13px;
  cursor:pointer;
  transition:background .15s ease, border-color .15s ease;
}
.palette-item:hover{
  background:#e5f0ff;
  border-color:var(--primary);
}

.site-canvas{
  border:1px solid var(--border);
  border-radius:12px;

  width: 100%;          /* ✅ responsive */
  max-width: 672px;     /* ✅ desktop limit */
  height: 420px;

  position:relative;
  overflow:hidden;
  box-sizing:border-box;
  background: none;     /* ✅ move grid to inner */
}

@media (max-width: 480px){
  .site-canvas{ height: 200px; }
}

/* Prevent scroll/zoom gestures interfering with drag */
.site-canvas,
.site-canvas-inner{
  touch-action: manipulation;
  touch-action: pan-x pan-y pinch-zoom;
}

.site-node {
  touch-action: none;
}

/* Optional: nicer on phone */
.site-node {
  user-select: none;
  -webkit-user-select: none;
}

.site-canvas-inner{
  position:absolute;    /* ✅ doesn't push layout wider */
  left:0;
  top:0;

  width:672px;          /* 🔒 logical */
  height:420px;         /* 🔒 logical */
  box-sizing:border-box;

  transform-origin: top left;

  /* ✅ grid scales together with nodes/room */
  background:
    repeating-linear-gradient(to right,#f3f4f6 0,#f3f4f6 1px,transparent 1px,transparent 16px),
    repeating-linear-gradient(to bottom,#f3f4f6 0,#f3f4f6 1px,transparent 1px,transparent 16px);
}

/* ✅ ROOM = LOGICAL (NOT visual-only) */
.site-room{
  position:absolute;
  left:64px;
  top:48px;
  width:544px;   /* 672 - 64 - 64 */
  height:328px;  /* 420 - 48 - 48 */
  z-index:1;
}

.site-room::before{
  content:"";
  position:absolute;
  inset:0;
  border:2px dashed #9ca3af;
  background:rgba(255,255,255,.4);
  pointer-events:none;
}

/* nodes */
.site-node{
  position:absolute;
  min-width:60px;
  min-height:26px;
  padding:4px 6px 6px;
  background:#fff;
  border:1px solid #d1d5db;
  font-size:11px;
  cursor:move;
  text-align:center;
  box-shadow:0 1px 3px rgba(15,23,42,.15);
  user-select:none;
  transform-origin:center center;
  transition:box-shadow .15s ease, border-color .15s ease, transform .15s ease;
  overflow:visible;
  z-index:2;
}
.site-node:hover{
  border-color:var(--primary);

}

.site-node-inner{
  position:relative;
  width:100%;
  height:100%;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  text-align:center;
  padding:0 6px;
  
}

.site-node-label-big{
  font-size:14px;
  font-weight:700;
  color:#111;
  text-align:center;
}

.site-node-toolbar{
  position:absolute;
  top:-22px;
  left:50%;
  transform:translateX(-50%);
  display:flex;
  gap:4px;
  pointer-events:auto;
  z-index:10;
}

.site-node-btn{
  border:none;
  background:rgba(17,24,39,.9);
  color:#fff;
  border-radius:50%;
  width:20px;
  height:20px;
  padding:0;
  font-size:12px;
  line-height:20px;
  text-align:center;
  cursor:pointer;
  box-shadow:0 1px 3px rgba(0,0,0,.4);
}

/* per-type min sizes */
.site-node{min-width:40px;min-height:24px;}
.site-node[data-type="EFI"]{min-width:32px;min-height:16px;}
.site-node[data-type="RCB"]{min-width:64px;min-height:16px;}
.site-node[data-type="FEEDER"]{min-width:70px;min-height:40px;}
.site-node[data-type="BC"],.site-node[data-type="RTU"],.site-node[data-type="FTU"]{min-width:40px;min-height:40px;}
.site-node[data-type="DB"]{min-width:32px;min-height:32px;}
.site-node[data-type="DOOR"]{min-width:80px;min-height:32px;padding:2px 4px;}


/* =========================
   Photo Upload
========================= */
    .photo-block, .existing-photo {
      margin: 20px 0;
    }

    .photo-title {
      display: block;
      font-size: 13px;
      font-weight: 600;
      margin-bottom: 6px;
      color: var(--text-main);
    }

    .photo-preview,
    .existing-photo  {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      margin-top: 10px;
    }

    .photo-preview img, 
    .existing-photo img{
      width: 110px;
      height: 110px;
      object-fit: cover;
      border-radius: 6px;
      border: 1px solid #d1d5db;
    }

    /* wrapper around each thumb */
    .photo-thumb {
      position: relative;
      width: 110px;
      height: 110px;
    }

    .photo-thumb img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      border-radius: 6px;
      border: 1px solid #d1d5db;
    }

    /* delete button on each thumb */
    .photo-thumb-remove {
      position: absolute;
      top: -6px;
      right: -6px;
      width: 18px;
      height: 18px;
      border-radius: 999px;
      border: none;
      background: rgba(17, 24, 39, 0.9);
      color: #fff;
      font-size: 12px;
      line-height: 18px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .file-input-hidden {
      display: none;
    }

    .upload-actions {
      display: flex;
      gap: 10px;
      margin-top: 6px;
    }

    .upload-btn {
      display: inline-flex;
      align-items: center;
      gap: 6px;

      padding: 10px 14px;
      font-size: 14px;
      font-weight: 600;

      border-radius: 8px;
      cursor: pointer;
      user-select: none;

      transition: background 0.2s ease, transform 0.1s ease;
    }

    /* File */
    .upload-btn {
      background: #f3f4f6;
      color: #111827;
      border: 1px solid #d1d5db;
    }

    .upload-btn:hover {
      background: #e5e7eb;
    }

    .upload-btn:active {
      transform: scale(0.97);
    }


/* =========================
   Points / Matrix Grid
========================= */
.points-card {
  margin-top: 18px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.points-title {
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .08em;
  margin-bottom: 10px;
}

.matrix-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  max-height: 520px;
  background: #fff;
}

.matrix { min-width: 980px; }

.row {           
  display: grid;
  grid-template-columns: 180px repeat(var(--cols), 78px);
  align-items: center;
}

.row.header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.cell {
  padding: 8px 6px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
}

.cell.vertical {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.point-col {
  text-align: left;
  font-weight: 700;
}

.sticky {
  position: sticky;
  left: 0;
  z-index: 6;
  background: #fff;
  border-right: 1px solid var(--border);
}

.row.header .sticky { z-index: 10; }

.matrix input[type="checkbox"] {  /* This change the box size*/
  transform: scale(1.4);
  cursor: pointer;
}

/* =========================
   Feeder Grid
========================= */
.feeder-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 768px) {
  .feeder-grid { grid-template-columns: 1fr; }
}

.feeder-block {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}
