
/* ==========================================
   RAFTUR LABS — LOGIKALAB
   RESPONSIVE STYLE.CSS
   ========================================== */

/* ---------- RESET ---------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  background: #060913;
  color: #f1f5f9;
  user-select: none;
}

/* ---------- HEADER ---------- */
header {
  flex: 0 0 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  background: rgba(15, 23, 42, 0.97);
  border-bottom: 1px solid #1e293b;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  padding: 2px 6px;
  border: 1px solid #0284c7;
  border-radius: 4px;
  background: rgba(2, 132, 199, 0.2);
  color: #38bdf8;
  font-size: 0.65rem;
  font-weight: 700;
  white-space: nowrap;
}

.brand-sub {
  color: #64748b;
  font-size: 0.75rem;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

select,
header button {
  max-width: 100%;
  padding: 7px 12px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}

select:hover,
header button:hover {
  border-color: #38bdf8;
  background: #1e293b;
}

/* ---------- LAYOUT UTAMA ---------- */
.app-body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: row;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* ---------- SIDEBAR ---------- */
sidebar {
  display: flex;
  flex: 0 0 280px;
  flex-direction: column;
  gap: 18px;
  width: 280px;
  min-width: 0;
  padding: 16px;
  background: #080d1a;
  border-right: 1px solid #1e293b;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 10;
}

sidebar::-webkit-scrollbar {
  width: 4px;
}

sidebar::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: #334155;
}

sidebar > div {
  min-width: 0;
  flex-shrink: 0;
}

.sec-title {
  margin-bottom: 5px;
  color: #38bdf8;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.6px;
  line-height: 1.4;
  text-transform: uppercase;
}

.sub-text {
  margin-bottom: 10px;
  color: #64748b;
  font-size: 0.7rem;
  line-height: 1.4;
}

/* ---------- GRID KOMPONEN ---------- */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.comp-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-width: 0;
  min-height: 62px;
  padding: 8px 4px;
  border: 1px solid #1e293b;
  border-radius: 8px;
  background: #0f172a;
  color: #cbd5e1;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.comp-card:hover {
  border-color: #38bdf8;
  background: #162032;
}

.comp-card:active {
  background: #1e293b;
}

.comp-svg {
  display: block;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.comp-svg-gate {
  display: block;
  flex-shrink: 0;
  width: 44px;
  height: 22px;
}

.comp-label {
  max-width: 100%;
  color: #cbd5e1;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
  text-align: center;
}

/* ---------- CLOCK ---------- */
.clock-ctrl {
  width: 100%;
  min-width: 0;
  margin-top: auto;
  padding: 12px;
  border: 1px solid #1e293b;
  border-radius: 8px;
  background: #0f172a;
}

.clock-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 8px;
  color: #94a3b8;
  font-size: 0.73rem;
  font-weight: 600;
  line-height: 1.4;
}

#clockVal {
  color: #38bdf8;
  font-weight: 700;
}

input[type="range"] {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 20px;
  accent-color: #38bdf8;
  cursor: pointer;
  touch-action: pan-y;
}

/* ---------- CANVAS ---------- */
.canvas-container {
  position: relative;
  flex: 1 1 0;
  width: 0;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-color: #040711;
  background-image: radial-gradient(#1e293b 1px, transparent 1px);
  background-size: 24px 24px;
}

#simCanvas,
canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#simCanvas {
  touch-action: none;
}

/* ---------- TIPS ---------- */
.tips-banner {
  position: absolute;
  top: 15px;
  left: 20px;
  z-index: 5;
  max-width: calc(100% - 40px);
  padding: 8px 16px;
  border: 1px solid #1e293b;
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.9);
  color: #94a3b8;
  font-size: 0.78rem;
  line-height: 1.5;
  pointer-events: none;
  overflow-wrap: anywhere;
}

.tips-banner span {
  color: #38bdf8;
  font-weight: 600;
}

/* ---------- ZOOM ---------- */
.zoom-ctrl {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid #1e293b;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.95);
}

.zoom-ctrl button {
  min-width: 30px;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #f8fafc;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.zoom-ctrl button:hover {
  background: #1e293b;
  color: #38bdf8;
}

.zoom-val {
  padding: 0 7px;
  color: #94a3b8;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
}

.modal-overlay.active {
  display: flex;
}

.modal {
  width: 520px;
  max-width: 100%;
  max-height: 85vh;
  max-height: 85dvh;
  padding: 22px;
  overflow-x: auto;
  overflow-y: auto;
  border: 1px solid #334155;
  border-radius: 12px;
  background: #0f172a;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #1e293b;
}

.modal-title {
  color: #38bdf8;
  font-weight: 700;
}

.close-modal {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 1.2rem;
  cursor: pointer;
}

.close-modal:hover {
  color: #f8fafc;
}

table {
  width: 100%;
  margin-top: 10px;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  padding: 8px;
  border: 1px solid #334155;
  text-align: center;
}

th {
  background: #1e293b;
  color: #38bdf8;
}

ul {
  padding-left: 20px;
  color: #cbd5e1;
  font-size: 0.85rem;
  line-height: 1.6;
}

/* ==========================================
   TABLET
   ========================================== */
@media (min-width: 651px) and (max-width: 900px) {
  header {
    padding: 0 12px;
  }

  .brand-title {
    font-size: 0.9rem;
  }

  .brand-sub {
    display: none;
  }

  sidebar {
    flex-basis: 220px;
    width: 220px;
    padding: 12px;
    gap: 14px;
  }

  .comp-card {
    min-height: 56px;
    padding: 7px 4px;
  }

  .comp-label {
    font-size: 0.65rem;
  }

  .comp-svg-gate {
    width: 36px;
    height: 18px;
  }

  .tips-banner {
    top: 10px;
    left: 12px;
    padding: 6px 12px;
    font-size: 0.7rem;
  }
}

/* ==========================================
   HP
   Sidebar tetap di kiri, kanvas di kanan.
   ========================================== */
@media (max-width: 650px) {
  html,
  body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  header {
    flex: 0 0 auto;
    height: auto;
    min-height: 48px;
    padding: 7px 8px;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }

  .brand {
    width: 100%;
    justify-content: center;
    gap: 6px;
  }

  .brand-title {
    font-size: 0.8rem;
    letter-spacing: 0;
  }

  .brand-badge {
    padding: 2px 5px;
    font-size: 0.58rem;
  }

  .brand-sub {
    display: none;
  }

  .top-actions {
    display: flex;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px;
  }

  .top-actions select,
  .top-actions button {
    max-width: 100%;
    padding: 5px 6px;
    font-size: 0.63rem;
  }

  .app-body {
    display: flex;
    flex: 1 1 0;
    flex-direction: row !important;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
  }

  /* Sidebar kiri dengan scroll vertikal */
  sidebar {
    display: flex;
    flex: 0 0 138px;
    flex-direction: column;
    width: 138px;
    min-width: 138px;
    max-width: 138px;
    height: 100%;
    max-height: none;
    gap: 10px;
    padding: 7px 6px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-right: 1px solid #1e293b;
    border-bottom: none;
    scroll-snap-type: none;
  }

  sidebar > div {
    display: block;
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }

  sidebar > div:first-child {
    display: block;
  }

  sidebar > div:not(:first-child) {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    width: 100%;
    min-width: 0;
  }

  .sec-title {
    margin-bottom: 5px;
    font-size: 0.57rem;
    letter-spacing: 0.2px;
    line-height: 1.4;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .sub-text {
    display: none;
  }

  .grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
  }

  .comp-card {
    width: 100%;
    min-width: 0;
    min-height: 47px;
    gap: 4px;
    padding: 5px 2px;
    border-radius: 7px;
  }

  .comp-card:hover {
    transform: none;
    box-shadow: none;
  }

  .comp-label {
    font-size: 0.52rem;
    line-height: 1.25;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .comp-svg {
    width: 17px;
    height: 17px;
  }

  .comp-svg-gate {
    width: 28px;
    height: 15px;
  }

  .clock-ctrl {
    position: static;
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: 6px;
    border: 1px solid #1e293b;
    border-radius: 7px;
    background: #0f172a;
  }

  .clock-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    margin-bottom: 5px;
    font-size: 0.55rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }

  input[type="range"] {
    width: 100%;
    min-width: 0;
    height: 22px;
    margin: 0;
  }

  /* Kanvas memenuhi ruang kanan */
  .canvas-container {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    touch-action: none;
  }

  #simCanvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
  }

  .tips-banner {
    top: 7px;
    left: 7px;
    max-width: calc(100% - 14px);
    padding: 5px 7px;
    border-radius: 9px;
    font-size: 0.55rem;
    line-height: 1.4;
    overflow-wrap: anywhere;
  }

  .tips-banner span:last-child {
    display: none;
  }

  .zoom-ctrl {
    right: 6px;
    bottom: 6px;
    gap: 1px;
    padding: 2px;
    border-radius: 7px;
  }

  .zoom-ctrl button {
    min-width: 25px;
    padding: 5px 7px;
    font-size: 0.7rem;
  }

  .zoom-val {
    padding: 0 4px;
    font-size: 0.6rem;
  }

  .modal-overlay {
    padding: 10px;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    max-height: 85dvh;
    padding: 13px;
    border-radius: 10px;
  }

  .modal-title {
    font-size: 0.85rem;
  }

  table {
    font-size: 0.7rem;
  }

  th,
  td {
    padding: 4px 3px;
  }

  ul {
    padding-left: 16px;
    font-size: 0.75rem;
  }
}

/* ==========================================
   HP KECIL
   ========================================== */
@media (max-width: 380px) {
  header {
    padding: 6px;
  }

  .brand-title {
    font-size: 0.73rem;
  }

  .top-actions select,
  .top-actions button {
    padding: 4px 5px;
    font-size: 0.58rem;
  }

  sidebar {
    flex-basis: 122px;
    width: 122px;
    min-width: 122px;
    max-width: 122px;
    padding: 6px 4px;
    gap: 9px;
  }

  .sec-title {
    font-size: 0.53rem;
  }

  .comp-card {
    min-height: 43px;
    padding: 4px 2px;
  }

  .comp-label {
    font-size: 0.48rem;
  }

  .comp-svg {
    width: 15px;
    height: 15px;
  }

  .comp-svg-gate {
    width: 24px;
    height: 13px;
  }

  .clock-ctrl {
    padding: 5px;
  }

  .clock-header {
    font-size: 0.5rem;
  }

  .tips-banner {
    font-size: 0.5rem;
  }
}

/* ---------- REDUCE MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
