/* Global */
:root {
  --accent: #6366f1;
  --muted: #64748b;
  --bg: #0b1020;
  --panel: #0f172a;
  --line: #1f2937;
  --header-h: 64px;
}

/* * {
  box-sizing: border-box;
} */

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: #e5e7eb;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #0c1226;
  position: sticky;
  top: 0;
  z-index: 110;
  min-height: var(--header-h);
}

header .left,
header .right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

input[type=text] {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: var(--panel);
  color: #e5e7eb;
  min-width: 200px;
}

button {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid #334155;
  background: #111827;
  color: #e5e7eb;
  cursor: pointer;
}

button:hover {
  border-color: #475569;
}

button.primary {
  background: linear-gradient(180deg, #6366f1, #4338ca);
  border: none;
}

button.danger {
  background: #7f1d1d;
  border-color: #7f1d1d;
}

button.icon {
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1;
}

/* Desktop grid */
body {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-columns: 280px 1fr;
  grid-template-areas: "hdr hdr" "sbar main";
}

header {
  grid-area: hdr;
}

#sidebar {
  grid-area: sbar;
  width: 280px;
  background: #0c1224;
  border-inline-end: 1px solid var(--line);
  overflow: auto;
  position: relative;
  z-index: 100;
  top:30px;
}

#main {
  grid-area: main;
  height: calc(100vh - var(--header-h));
  display: flex;
}

#canvas {
  width: 100%;
  height: 100%;
  background: radial-gradient(1000px 600px at 70% -100px, #10183a66 0%, transparent 60%);
}

/* Sidebar content */
.sb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: #0c1224;
  z-index: 1;
}

.projects {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.project {
  background: #0f172a;
  border: 1px solid #1f2937;
  border-radius: 10px;
  overflow: hidden;
}

.project>.p-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #1f2937;
  cursor: pointer;
  background-color: #0b1020;
}

.project .p-title {
  font-weight: 700;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.project .caret {
  font-size: 16px;
  color: #94a3b8;
  user-select: none;
}

.project .p-actions {
  display: flex;
  gap: 6px;
}

.diagrams {
  display: flex;
  flex-direction: column;
}

.diagram {
  padding: 10px 12px;
  border-top: 1px dashed #1f2937;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.diagram.active {
  background: #0b122b;
  border-inline-start: 3px solid var(--accent);
}

.diagram .d-name {
  flex: 1;
}

.diagram .d-actions {
  display: flex;
  gap: 6px;
}

/* Backdrop (under sidebar on mobile) */
.backdrop {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--header-h);
  bottom: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 90;
  /* أقل من السايدبار وأكبر من المحتوى */
}

/* Hide sidebar (desktop) */
body.sidebar-hidden {
  grid-template-columns: 0 1fr;
}

body.sidebar-hidden #sidebar {
  width: 0;
  border-inline-end: none;
  overflow: hidden;
}

/* ===== Mobile (<= 900px) ===== */
@media (max-width: 900px) {
  
   :root { --header-h: 72px; }

  /* كبّر الهيدر للموبايل */
  body {
    grid-template-columns: 1fr;
    grid-template-areas: "hdr" "main";
  }

  header {
    flex-wrap: wrap;
    height: 150px;
    
  }

  header .left {
    order: 1;
  }

  header .right {
    order: 2;
    width: 100%;
    justify-content: flex-start;
  }

  header .right input {
    flex: 1 1 220px;
    min-width: 0;
  }

  /* Off-canvas sidebar from the RIGHT (RTL) */
  #sidebar {
    position: fixed;
    top: 60px;
    bottom: 0;
    right: 0;
    left: auto;
    /* مثبت يمينًا */
    width: min(86vw, 340px);
    transform: translateX(100%);
    /* خارج الشاشة يمين */
    transition: transform .28s ease;
    box-shadow: -4px 0 16px rgba(0, 0, 0, .45);
    z-index: 150;
    /* أعلى من الباك دروب */
  }

  body.sidebar-open #sidebar {
    transform: translateX(0);
  }

  /* عند فتح السايدبار: امنع تمرير الخلفية وأظهر الباك دروب */
  body.sidebar-open {
    overflow: hidden;
  }

  #backdrop[hidden] {
    display: none;
  }

  body.sidebar-open #backdrop {
    display: block;
  }

  body:not(.sidebar-open) #backdrop {
    display: none;
  }

  /* لا نستخدم sidebar-hidden على الموبايل */
  body.sidebar-hidden {
    grid-template-columns: 1fr;
  }
}

/* Tree */
.link {
  fill: none;
  stroke: #334155;
  stroke-width: 1.6px;
}

.node rect {
  stroke: #0b1020;
  stroke-width: 1.6px;
  rx: 10;
  ry: 10;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .25));
  transition: filter .15s ease, stroke-width .15s ease, opacity .1s, outline-color .1s;
}

.node rect.selected {
  stroke: var(--accent);
  stroke-width: 3px;
}

.node rect.drop-target {
  outline: 2px dashed #22d3ee;
  outline-offset: 2px;
}

.node .label {
  fill: #0b1020;
  font-weight: 600;
  font-size: 13px;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.caret {
  cursor: pointer;
  font-size: 12px;
  color: #94a3b8;
  user-select: none;
}


/* buuton export */

.fab{
  position: fixed; inset-inline-end: 24px; bottom: 24px;
  width: 56px; height: 56px; border-radius: 9999px; border: none;
  background: linear-gradient(135deg, #7c3aed, #22d3ee);
  color: #fff; box-shadow: 0 16px 40px rgba(0,0,0,.35);
  display: grid; place-items: center; cursor: pointer; z-index: 1000;
}
.fab:hover{ filter: brightness(1.05); transform: translateY(-1px); }
.fab:active{ transform: translateY(0); }


/* === Context menu for nodes === */
.ctx-menu{position:fixed; inset:auto auto auto auto; min-width:200px; background:rgba(15,23,42,.98); color:#e5e7eb; border:1px solid #263043; border-radius:12px; box-shadow:0 12px 28px rgba(0,0,0,.4); padding:6px; z-index:9999; backdrop-filter: blur(6px);}
.ctx-item{display:flex; align-items:center; gap:10px; padding:10px 12px; border-radius:10px; cursor:pointer; user-select:none; white-space:nowrap;}
.ctx-item:hover{background:rgba(148,163,184,.12);}
.ctx-item.danger{color:#fecaca;}
.ctx-sep{height:1px; background:#263043; margin:4px 6px;}
.ctx-kbd{margin-inline-start:auto; font:600 11px/1 system-ui, -apple-system, "Segoe UI", Roboto; padding:.2em .5em; background:#111827; border:1px solid #374151; border-radius:6px; color:#9ca3af;}
