/* =====================================================================
   Sai Ram Engineering Workflow – styles

   All colours are plain CSS colour NAMES (no #codes):

     navy           = brand colour: logo, headings, main button, active tab
     royalblue      = screens: label, step circle, arrows   (light background: lavender)
     chocolate      = notifications: label, step circle     (light background: papayawhip)
     darkslateblue  = role box and workflow accent
     silver         = tree lines
     lightsteelblue = screenshot frames
     ghostwhite     = page background
     gainsboro      = borders
     slategray      = small grey text
   ===================================================================== */


/* ---------- sizes used in many places (change them here) ---------- */
:root {
  --card-width: 380px;       /* every card has the same width (screenshots keep their own shape) */
  --arrow-y: 90px;           /* how far down from the top of a card the arrows run */
  --row-space: 24px;         /* space above and below each workflow row */
  --arm-y: calc(var(--row-space) + var(--arrow-y));   /* where the tree line meets a workflow row */
  --arm: 56px;               /* length of a tree branch line */
  --curve: 16px;             /* how round the tree corners are */
  --line: 2px;               /* thickness of the tree lines */
  --button-height: 36px;     /* every top-bar button has this height so they line up */
}


/* ---------- page ---------- */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: ghostwhite;
  color: black;
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
}

button {
  font-family: inherit;
  cursor: pointer;
}


/* ---------- buttons ---------- */
.plain-button,
.main-button {
  height: var(--button-height);
  padding: 0 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.plain-button {
  border: 1px solid gainsboro;
  background: white;
  color: black;
}
.plain-button:hover { border-color: navy; color: navy; }

.main-button {
  border: 1px solid navy;
  background: navy;
  color: white;
}
.main-button:hover { background: darkslateblue; border-color: darkslateblue; }
.main-button:disabled { background: slategray; border-color: slategray; cursor: wait; }


/* ---------- top bar ---------- */
.top-bar {
  background: white;
  border-bottom: 1px solid gainsboro;
  box-shadow: 0 2px 10px gainsboro;
  z-index: 2;
}

.top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-logo {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: navy;
  color: white;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.04em;
}

.brand h1 { margin: 0; font-size: 18px; font-weight: 700; color: navy; }
.brand-subtitle { font-size: 13px; color: slategray; white-space: nowrap; }

/* right side of the top bar: everything on ONE line, all the same height */
.tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.legend {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-right: 6px;
  font-size: 13px;
  color: slategray;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.screen-dot { background: royalblue; }
.notification-dot { background: chocolate; }

/* the − 100% + group looks like one control */
.zoom-group {
  display: inline-flex;
  align-items: center;
  height: var(--button-height);
  border: 1px solid gainsboro;
  border-radius: 10px;
  overflow: hidden;
  background: white;
}
.zoom-group button {
  width: 36px;
  height: 100%;
  border: none;
  background: white;
  font-size: 18px;
  color: black;
}
.zoom-group button:hover { background: ghostwhite; color: navy; }
#zoomText {
  min-width: 54px;
  height: 100%;
  display: grid;
  place-items: center;
  border-left: 1px solid gainsboro;
  border-right: 1px solid gainsboro;
  font-size: 13px;
  font-weight: 600;
  color: slategray;
}

/* tabs row: workflow tabs on the left, matrix link on the right */
.tabs-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid whitesmoke;
}
.tabs {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 4px;
  padding: 0 20px;
  overflow-x: auto;
}

/* link to the requirements matrix page */
.matrix-link {
  flex: none;
  margin-right: 20px;
  padding: 7px 12px;
  border-radius: 8px;
  background: lavender;
  color: navy;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.matrix-link:hover { background: navy; color: white; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  border: none;
  border-bottom: 3px solid transparent;
  background: none;
  color: slategray;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.tab:hover { color: navy; }
.tab.active { color: navy; border-bottom-color: navy; }
.tab-code {
  padding: 2px 7px;
  border-radius: 6px;
  background: whitesmoke;
  font-size: 11px;
  color: slategray;
}
.tab.active .tab-code { background: lavender; color: navy; }


/* ---------- drawing area ---------- */
/* "margin: auto" on the tree keeps it centred when it is small,
   and lets it scroll when it is bigger than the screen.
   The background has a light dot grid, like a design board. */
.drawing-area {
  flex: 1;
  display: flex;
  overflow: auto;
  cursor: grab;
  background-color: ghostwhite;
  background-image: radial-gradient(lightgray 1px, transparent 1px);
  background-size: 22px 22px;
}
.drawing-area.dragging { cursor: grabbing; user-select: none; }

.tree {
  flex: none;
  margin: auto;
  padding: 64px;
  display: flex;
  align-items: flex-start; /* the app and role boxes line up with the FIRST workflow's line */
}

/* holds the app box / role box so that its middle sits on the first workflow's line */
.tree-holder {
  flex: none;
  height: calc(var(--arm-y) * 2);
  display: flex;
  align-items: center;
}

/* the lines between the app box, the role box and the workflows: on that same line */
.tree > .stub { margin-top: calc(var(--arm-y) - var(--line) / 2); }


/* ---------- tree boxes (nodes) ---------- */
.node {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-radius: 18px;
}
.node b { line-height: 1.25; }

.node-code {
  align-self: flex-start;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

/* level 1: the app */
.root-node {
  width: 270px;
  padding: 24px;
  background: linear-gradient(135deg, navy, royalblue);
  color: white;
  box-shadow: 0 10px 30px lightsteelblue;
}
.root-node .node-code { border: 1px solid cornflowerblue; }
.root-node b { font-size: 28px; font-weight: 800; }

.root-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.root-stats div {
  padding: 8px 4px;
  border-radius: 10px;
  border: 1px solid cornflowerblue;
  text-align: center;
}
.root-stats strong { display: block; font-size: 20px; }
.root-stats span { font-size: 11px; opacity: 0.85; }

/* level 2: the user role */
.role-node {
  width: 230px;
  padding: 20px;
  background: white;
  border: 1px solid gainsboro;
  box-shadow: 0 6px 18px gainsboro;
}
.role-node .node-code { background: lavender; color: darkslateblue; }
.role-node b { font-size: 18px; color: navy; }
.role-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
  border-radius: 50%;
  background: darkslateblue;
  color: white;
  font-weight: 700;
}

/* level 3: a workflow */
.workflow-node {
  width: 250px;
  padding: 18px 18px 18px 20px;
  background: white;
  border: 1px solid gainsboro;
  border-left: 6px solid darkslateblue;
  box-shadow: 0 6px 18px gainsboro;
}
.workflow-node .node-code { background: lavender; color: darkslateblue; }
.workflow-node b { font-size: 18px; color: navy; }
.node-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 12px;
  color: slategray;
}
.node-counts span { display: inline-flex; align-items: center; gap: 5px; }


/* ---------- tree lines ---------- */

/* straight line between two boxes on the same level */
.stub {
  flex: none;
  width: var(--arm);
  height: var(--line);
  background: silver;
}

/* the list of workflows */
.branches {
  display: flex;
  flex-direction: column;
}

/* one workflow row: [workflow box] — [cards] */
.branch {
  position: relative;
  display: flex;
  align-items: flex-start;   /* the box and all cards start at the top of the row */
  padding: var(--row-space) 0 var(--row-space) var(--arm);
}

/* holds the workflow box so that its middle sits exactly on the arrow line */
.workflow-holder {
  flex: none;
  height: calc(var(--arrow-y) * 2);
  display: flex;
  align-items: center;
}

/* blue line from the workflow box to its first card (on the arrow line) */
.start-line {
  flex: none;
  width: var(--arm);
  height: 3px;
  margin-top: calc(var(--arrow-y) - 1.5px);
  background: royalblue;
}

/* ::after = the vertical "spine" on the left that joins all workflows */
.branch::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-left: var(--line) solid silver;
}

/* ::before = the arm going right from the spine to the workflow box */
.branch::before {
  content: "";
  position: absolute;
  left: 0;
  top: calc(var(--arm-y) - var(--line) / 2);
  width: var(--arm);
  border-top: var(--line) solid silver;
}

/* first workflow: the line comes straight on from the role box, and the spine starts here going down */
.branch:first-child::after { top: calc(var(--arm-y) - var(--line) / 2); }

/* last workflow: the line curves  ╰  (spine ends here) */
.branch:last-child::before {
  top: calc(var(--arm-y) - var(--curve) + var(--line) / 2);
  height: var(--curve);
  border-top: none;
  border-bottom: var(--line) solid silver;
  border-left: var(--line) solid silver;
  border-bottom-left-radius: var(--curve);
}
.branch:last-child::after { bottom: auto; height: calc(var(--arm-y) - var(--curve) + var(--line)); }

/* only one workflow: no spine needed */
.branch:only-child::after { display: none; }
.branch:only-child::before {
  top: calc(var(--arm-y) - var(--line) / 2);
  height: 0;
  border-left: none;
  border-bottom: none;
  border-top: var(--line) solid silver;
}


/* ---------- cards (one screen or one notification) ----------
   Each card is:   [screenshot in a frame, step number on its corner]
                   [coloured label: "SCREEN 2" + title]
                   description text
*/
.card-row {
  display: flex;
  align-items: flex-start;   /* every card starts at the same top line */
}

.card {
  flex: none;
  width: var(--card-width);
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: zoom-in;
}
.card:focus { outline: none; }

/* The screenshot frame. The screenshot is shown COMPLETE, in its own shape:
   full frame width, and the height follows the picture (nothing is cut). */
.card-picture {
  position: relative;
  padding: 6px;
  background: white;
  border: 1px solid lightsteelblue;
  border-radius: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.card-picture img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4px;
}
.card:hover .card-picture,
.card:focus .card-picture {
  border-color: royalblue;
  box-shadow: 0 0 0 2px royalblue, 0 8px 22px lightsteelblue;
}
.card.notification:hover .card-picture,
.card.notification:focus .card-picture {
  border-color: chocolate;
  box-shadow: 0 0 0 2px chocolate, 0 8px 22px bisque;
}

/* the round step number sitting on the top-left corner of the screenshot */
.step-circle {
  position: absolute;
  left: -14px;
  top: -14px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 3px solid ghostwhite;   /* same colour as the page, so it looks cut out */
  border-radius: 50%;
  color: white;
  font-size: 15px;
  font-weight: 700;
}

/* the coloured label under the screenshot */
.card-label {
  min-height: 64px;
  padding: 9px 12px;
  border-radius: 10px;
  color: white;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}
.card-label span {
  display: block;
  margin-bottom: 3px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* colours: blue for screens, orange-brown for notifications */
.screen .step-circle,
.screen .card-label { background: royalblue; }
.notification .step-circle,
.notification .card-label { background: chocolate; }

/* the description under the label */
.card-text {
  padding: 0 2px;
  font-size: 13px;
  line-height: 1.5;
  color: slategray;
}

.no-picture {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: slategray;
  font-weight: 600;
}

/* small pill used in the popup ("SCREEN 2") */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.badge.screen { background: lavender; color: royalblue; }
.badge.notification { background: papayawhip; color: sienna; }

/* arrow between two cards: a thick blue line with a head.
   It runs at the same height (--arrow-y) on every card, through the screenshots. */
.arrow {
  flex: none;
  width: 56px;
  display: flex;
  align-items: center;
  margin-top: calc(var(--arrow-y) - 7px);   /* 7px = half the arrow head */
  padding: 0 6px;
}
.arrow-line {
  flex: 1;
  height: 3px;
  background: royalblue;
}
.arrow-head {
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 10px solid royalblue;
}


/* ---------- popup (big screenshot + details panel) ---------- */
.popup {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr 380px;
  background: color-mix(in srgb, black 85%, transparent);
}

.popup-image {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  overflow: auto;
}
.popup-image img {
  max-width: 100%;
  max-height: calc(100vh - 56px);
  border-radius: 10px;
  background: white;
  box-shadow: 0 10px 40px black;
}
.popup-image .no-picture { color: white; }

.popup-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 32px 28px 24px;
  background: white;
  overflow-y: auto;
}

.popup-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 1px solid gainsboro;
  border-radius: 50%;
  background: white;
  font-size: 14px;
  color: slategray;
}
.popup-close:hover { color: navy; border-color: navy; }

.popup-path {
  padding-right: 40px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: darkslateblue;
}
.popup-panel h2 { margin: 0; font-size: 22px; line-height: 1.3; color: navy; }
.popup-panel p { margin: 0; font-size: 15px; line-height: 1.6; color: slategray; }

.popup-buttons {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid gainsboro;
}
#popupCounter { font-size: 13px; font-weight: 600; color: slategray; }
.popup-hint { font-size: 12px; color: silver; text-align: center; }


/* ---------- smaller screens ---------- */
@media (max-width: 1100px) {
  .legend, .brand-subtitle { display: none; }
}

/* ---------- phones (760px and below): top bar and popup ---------- */
@media (max-width: 760px) {
  .top-row { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .tools { flex-wrap: wrap; gap: 8px; }
  #actualSizeButton { display: none; }
  .tabs { padding: 0 16px; }
  .matrix-link { margin-right: 12px; }
  .matrix-link-long { display: none; }

  /* popup: screenshot on top, details below */
  .popup { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .popup-image { padding: 16px; }
  .popup-image img { max-height: 50vh; }
  .popup-panel { max-height: 50vh; padding: 24px 18px 18px; }
  .popup-panel h2 { font-size: 19px; }
  .popup-hint { display: none; }
}


/* ---------- phones: the tree ----------
   js/start-app.js puts the class "phone-layout" on <body> when the screen is
   760px or narrower. (A class is used instead of @media so that "Download PDF"
   can switch it off for a moment and always save the full desktop tree.)

   The tree turns from left-to-right into top-to-bottom:

     [Sai Ram Engineering]
          |
     [Admin]
          |
          ├── [WF 01]
          |      card
          |       ↓
          |      card
          └── [WF 02] ...
*/
.phone-layout .tree {
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  margin: 0;
  padding: 20px 16px 40px;
}
.phone-layout .drawing-area { cursor: auto; }

.phone-layout .root-node,
.phone-layout .role-node,
.phone-layout .workflow-node { width: 100%; }

/* the straight lines between levels now go down */
.phone-layout .stub {
  width: var(--line);
  height: 28px;
  margin-left: 28px;
}
.phone-layout .tree > .stub { margin-top: 0; }
.phone-layout .tree-holder { height: auto; }

/* workflows hang from a spine on the left */
.phone-layout .branches { margin-left: 28px; }

.phone-layout .branch {
  flex-direction: column;
  align-items: stretch;
  padding: 16px 0 16px 22px;
}
.phone-layout .workflow-holder { height: auto; }
.phone-layout .start-line { width: 3px; height: 26px; margin: 0 0 0 24px; }

/* the arm from the spine to the workflow box (always straight on phones) */
.phone-layout .branch::before {
  top: 56px;
  width: 22px;
  height: 0;
  border-top: var(--line) solid silver;
  border-left: none;
  border-bottom: none;
  border-radius: 0;
}
.phone-layout .branch:first-child::after { top: 0; }
.phone-layout .branch:last-child::after { top: 0; bottom: auto; height: 57px; }
.phone-layout .branch:only-child::after { display: block; }

/* cards stack one under the other */
.phone-layout .card-row { flex-direction: column; align-items: stretch; }
.phone-layout .card { width: 100%; }

/* arrows point down */
.phone-layout .arrow {
  align-self: center;
  width: auto;
  height: 46px;
  margin-top: 0;
  flex-direction: column;
  padding: 6px 0;
}
.phone-layout .arrow-line { width: 3px; height: auto; }
.phone-layout .arrow-head {
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 10px solid royalblue;
  border-bottom: none;
}
