/* ── Font ────────────────────────────────────────────────────────────────── */
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-Light.ttf");         font-weight: 300; font-style: normal; }
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-LightItalic.ttf");   font-weight: 300; font-style: italic; }
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-Book.ttf");          font-weight: 400; font-style: normal; }
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-BookItalic.ttf");    font-weight: 400; font-style: italic; }
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-Medium.ttf");        font-weight: 500; font-style: normal; }
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-MediumItalic.ttf");  font-weight: 500; font-style: italic; }
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-Semibold.ttf");      font-weight: 600; font-style: normal; }
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-SemiboldItalic.ttf"); font-weight: 600; font-style: italic; }
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-Bold.ttf");          font-weight: 700; font-style: normal; }
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-BoldItalic.ttf");    font-weight: 700; font-style: italic; }
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-Black.ttf");         font-weight: 900; font-style: normal; }
@font-face { font-family: nebula; src: url("../fonts/NebulaSans-BlackItalic.ttf");   font-weight: 900; font-style: italic; }

/* ── Color palette ───────────────────────────────────────────────────────── */
:root {
  --black:   #000000;
  --grey1:   #7f7f7f;
  --grey2:   #aaaaaa;
  --grey3:   #d4d4d4;
  --white:   #ffffff;

  --blue0:   #143d82;   /* darker navy                   */
  --blue1:   #0c5aa6;   /* unchanged                      */
  --blue2:   #6e99c6;   /* muted mid-blue                 */
  --blue3:   #d4e7f7;   /* soft blue tint                 */

  --orange0: #b86000;   /* dark amber (was reddish)       */
  --orange1: #ff8c00;   /* unchanged                      */
  --orange2: #f5a93c;   /* warm peach-orange              */
  --orange3: #fde8ca;   /* creamy tint (was yellow)       */

  --green0:  #227814;   /* dark green                     */
  --green1:  #43ba10;   /* unchanged                      */
  --green2:  #7dc455;   /* muted mid-green                */
  --green3:  #d4f0be;   /* soft green tint                */

  --violet0: #6a2aa8;   /* deeper violet                  */
  --violet1: #8b3ec0;   /* unchanged                      */
  --violet2: #b882d8;   /* muted violet                   */
  --violet3: #f0e0fc;   /* soft violet tint               */

  --red0:    #a01220;   /* dark red                       */
  --red1:    #d22125;   /* unchanged                      */
  --red2:    #e87878;   /* muted red                      */
  --red3:    #fad8d8;   /* soft red tint                  */

  --teal0:   #005c55;   /* darker teal                    */
  --teal1:   #008077;   /* unchanged                      */
  --teal2:   #4aaa9e;   /* muted teal                     */
  --teal3:   #c8ecea;   /* soft teal tint                 */

  /* ── Semantic aliases ──────────────────────────────────────────────────── */
  --color-bg:           var(--white);
  --color-surface:      var(--grey3);
  --color-border:       var(--grey2);
  --color-text:         var(--black);
  --color-text-muted:   var(--grey1);
  --color-primary:      var(--blue1);
  --color-primary-dark: var(--blue0);
  --color-accent:       var(--orange1);
}

/* ── Reset / base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: nebula, system-ui, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
header {
  background: var(--blue0);
  color: var(--white);
  padding: 0.75rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

header h1 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: 0.03em;
}

.header-sub {
  opacity: 0.75;
  font-size: 0.95rem;
}

main {
  flex: 1;
  margin: 2rem 0;
}

#create-section {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 2rem;
}

#context-section {
  padding: 0 20px;
}

footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--color-border);
  margin-top: 4rem;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--color-primary);
  color: var(--white);
  border: none;
  padding: 0.5rem 1.4rem;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
}
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  padding: 0.4rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--color-surface); }

/* ── Create form ─────────────────────────────────────────────────────────── */
#create-section h2 { margin-top: 0; }

.section-divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 2rem 0;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}
.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--color-border);
}

/* ── CSV import ──────────────────────────────────────────────────────────── */
.file-pick-label {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  border: 1px dashed var(--color-border);
  border-radius: 4px;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  cursor: pointer;
  margin-bottom: 1rem;
}
.file-pick-label:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.file-pick-label input[type="file"] { display: none; }

#csv-options {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ── Examples ────────────────────────────────────────────────────────────── */
.examples-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.text-muted { color: var(--color-text-muted); font-size: 0.9rem; }

.form-row {
  display: flex;
  gap: 2rem;
  margin-bottom: 1.25rem;
}

.form-row label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.form-row input[type="number"],
.form-row select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 1rem;
  background: var(--white);
  min-width: 10rem;
}

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.toolbar-sep {
  flex: 1;
}

.btn-undo {
  background: transparent;
  color: var(--orange0);
  border: 1px solid var(--orange1);
  padding: 0.4rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}
.btn-undo:hover:not(:disabled) { background: var(--orange3); }
.btn-undo:disabled { color: var(--grey2); border-color: var(--grey3); cursor: default; }

.btn-unlock {
  background: var(--blue0);
  color: var(--white);
  border: 1px solid var(--blue0);
  padding: 0.4rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}
.btn-unlock:hover { background: var(--blue1); }

.btn-arrows {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  padding: 0.4rem 1rem;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}
.btn-arrows:hover { background: var(--color-surface); }
.btn-arrows.active {
  background: var(--blue1);
  color: var(--white);
  border-color: var(--blue1);
}
.btn-arrows.active:hover { background: var(--blue0); }

/* ── Notice ──────────────────────────────────────────────────────────────── */
.notice {
  background: var(--blue3);
  color: var(--blue0);
  border: 2px solid var(--blue1);
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}
.notice.notice-warning {
  color: var(--orange0);
  border-color: var(--orange1);
  background: var(--orange3);
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 1.5rem;
}

.tab-btn {
  padding: 0.5rem 1.4rem;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  background: none;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--color-text-muted);
  font-family: inherit;
}
.tab-btn:hover  { color: var(--color-text); }
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }

/* ── Diagram pane ────────────────────────────────────────────────────────── */
.diagram-pane {
}

#CSCanvas {
  display: block;
  width: 1300px;
  height: 1100px;
  outline: 1px solid black;
  margin: 0 auto;
}

/* ── Context table ───────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 220px);
  margin-bottom: 2.5rem;
}

.table-center {
  min-width: 100%;
  display: flex;
  justify-content: center;
}

.context-table {
  border-collapse: collapse;
  white-space: nowrap;
}

.context-table th,
.context-table td {
  border: 1px solid var(--color-border);
  padding: 0.25rem 0.5rem;
  min-width: 2.5rem;
  text-align: center;
}

/* corner (top-left) */
.context-table th.corner {
  background: var(--grey3);
  border-color: var(--grey3);
  min-width: 1.5rem;
  position: sticky;
  top: 0;
  left: 0;
  z-index: 4;
}

/* ── Delete button (inside header cells) ─────────────────────────────────── */
.delete-btn {
  position: absolute;
  right: 3px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: transparent;
  cursor: pointer;
  font-size: 0.7rem;
  padding: 1px 3px;
  line-height: 1;
  font-family: inherit;
  border-radius: 2px;
}
.context-table th:hover .delete-btn       { color: rgba(255,255,255,0.5); }
.context-table th .delete-btn:hover       { color: var(--white); background: rgba(0,0,0,0.2); }

.header-label {
  padding-right: 1rem;
}

/* attribute headers (top row) */
.context-table th.attr-header {
  background: var(--violet1);
  color: var(--white);
  cursor: pointer;
  font-weight: 600;
  min-width: 5rem;
  position: sticky;
  top: 0;
  z-index: 3;
}
.context-table th.attr-header:hover { background: var(--violet0); }

/* object headers (left column) */
.context-table th.obj-header {
  background: var(--teal1);
  color: var(--white);
  cursor: pointer;
  font-weight: 600;
  text-align: left;
  min-width: 7rem;
  position: sticky;
  left: 0;
  z-index: 1;
}
.context-table th.obj-header:hover { background: var(--teal0); }

/* incidence cells */
.context-table td.incidence-cell {
  cursor: pointer;
  user-select: none;
  font-size: 1.4rem;
  height: 2.2rem;
  background: var(--white);
}
.context-table.locked td.incidence-cell {
  cursor: default;
}
.context-table.locked th.attr-header,
.context-table.locked th.obj-header {
  cursor: default;
}
.context-table td.incidence-cell:hover        { background: var(--grey3); }
.context-table td.incidence-cell.marked       { background: var(--orange3); color: var(--orange0); }
.context-table td.incidence-cell.marked:hover { background: var(--orange2); }
.context-table td.incidence-cell.has-arrow    { color: var(--blue1); font-size: 1rem; }

/* add-row / add-col buttons */
.context-table th.add-btn-cell {
  background: var(--grey3);
  border: 1px dashed var(--grey2);
  cursor: pointer;
}
.context-table th.add-btn-cell:hover { background: var(--grey2); }
.context-table th.add-btn-cell button {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--grey1);
  padding: 0 0.25rem;
  line-height: 1;
  pointer-events: none;
}

/* add-attribute cell sticks to the top with the rest of the header row */
.context-table thead th.add-btn-cell {
  position: sticky;
  top: 0;
  z-index: 3;
}

/* add-object cell sticks left with the rest of the object column */
.context-table .add-obj-row th.add-btn-cell {
  position: sticky;
  left: 0;
  z-index: 1;
}

/* filler cells in add rows/cols */
.context-table td.add-col-spacer,
.context-table td.add-row-spacer {
  background: var(--grey3);
  border: 1px dashed var(--grey2);
}

/* inline header input */
.header-input {
  background: var(--white);
  border: 1px solid var(--blue2);
  border-radius: 3px;
  padding: 0.15rem 0.35rem;
  font-size: 0.9rem;
  color: var(--black);
  width: 100%;
  min-width: 4rem;
  outline: none;
}

/* ── CSV export ──────────────────────────────────────────────────────────── */
.export-section {
  border-top: 1px solid var(--color-border);
  padding-top: 1.5rem;
}

.export-section h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.export-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.option-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.option-group span {
  color: var(--color-text-muted);
}

.option-group label {
  cursor: pointer;
}
