/* Import Google Font */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600&display=swap');

/* Animation Keyframes for Loader */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- Global Styles & Variables --- */
:root {
  --font-family: 'Montserrat', sans-serif;
  --primary-color: #df5039; /* IDUN Orange */
  --text-color: #333333;
  --background-color: #fdfdfd;
  --border-color: #e0e0e0;
  --border-radius: 5px;
  --container-width: 1400px;
  --selected-row-color: #b0c3d0;
  --header-background: #6f7e6b;
  --header-text: #ffffff;
}

body {
  font-family: var(--font-family);
  background-color: var(--background-color);
  color: var(--text-color);
  max-width: var(--container-width);
  margin: 2rem auto;
  padding: 0 1rem;
  line-height: 1.6;
}

/* --- Typography --- */
h1, h2, h3 {
  color: var(--header-background);
  font-weight: 600;
  margin-bottom: 1rem;
}

h1 {
  font-size: 2.5rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.5rem;
  margin-bottom: 2rem;
}

h2 {
  font-size: 1.75rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  margin-top: 2.5rem;
}

h2:has(+ div:empty) {
  display: none;
}

h2 span#project, h2 span#version {
  color: var(--primary-color);
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: opacity 0.2s ease;
}

a:hover {
  opacity: 0.8;
  text-decoration: underline;
}

a.inactive {
  pointer-events: none;
  cursor: default;
  text-decoration: none;
  color: lightgrey;
  font-style: italic;
}

a.project_delete.inactive,
a.project_duplicate.inactive {
  /* Allow hover so browser shows the title tooltip, but keep it looking disabled. */
  pointer-events: auto;
}

div.edited, tr.edited {
  border: 2px dashed var(--primary-color); 
}

/* --- Login & Messages --- */
#login, #logout {
  position: fixed;
  top: 20px;
  right: 20px;
  background-color: white;
  padding: 1.5rem;
  border-radius: var(--border-radius);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  z-index: 100;
  border: 1px solid var(--border-color);
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Logout box should sit on top of the orange header bar at the very top */
#logout {
  top: 0;
  right: 24px;
  z-index: 260; /* above #message (200) and avatar (250) */
}

/* Auto-generated user avatar shown when logged in */
#user_avatar {
  position: fixed;
  /* Sit visually on the top orange header bar (#message) */
  top: 8px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--header-background);
  color: var(--header-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  /* Above the top orange bar (#message uses z-index: 200) */
  z-index: 250;
}

/* --- Bottom button overlay (typically save button) --- */
.button-overlay {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;

  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;

  padding: 10px 12px;
  background: #ffffff;
  border-top: 1px solid var(--border-color);

  /* above main content, below login/logout (#login/#logout use z-index: 100) */
  z-index: 90;
}

#message {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 1rem;
  text-align: center;
  background-color: var(--primary-color);
  color: white;
  z-index: 200;
}

.error {
  background-color: #d9534f;
  color: white;
}

.hidden {
  display: none;
  visibility: hidden;
}

/* --- Table Styles --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1.5rem;
}

td, th {
  padding: 5px 15px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  background-color: var(--header-background);
  color: var(--header-text);
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--primary-color);
}

/* Tag-like styling for config sections */
.config_section,
.section {
  display: inline-block;
  padding: 2px 8px;
  margin: 2px 4px 2px 0;
  border-radius: 9999px;
  background-color: #e8f0f7;
  color: #2c3e50;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
}

/* Summarised name card (e.g. in delete dialog) */
.name {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 6px 10px;
  margin: 4px 0;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background-color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  font-size: 0.9rem;
  color: var(--text-color);
}

.name .section {
  margin: 0;
}

.name span {
  white-space: nowrap;
}

tr {
  transition: background-color 0.2s ease;
}

tr:hover {
  background-color: #f5f5f5;
}

tr.selected {
  background-color: var(--selected-row-color); /* A light orange for selection */
  /*font-weight: 600;*/
  color: white;
}

/* --- Form Elements --- */
input, select, button {
  font-family: var(--font-family);
  font-size: 1rem;
  padding: 5px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(223, 80, 57, 0.2);
}

button, input[type="button"], input[type="submit"] {
  background-color: var(--primary-color);
  color: white;
  border: none;
  cursor: pointer;
  width: auto;
  min-width: 100px;
  transition: background-color 0.2s ease;
}

button:hover {
  background-color: #c9402a;
}

button.save_configs, button.save_config {
  margin: 10px;
}

button.inactive {
  pointer-events: none;
  cursor: default;
  background-color: lightgrey;
  font-style: italic;
}

#login input {
  width: 250px;
}

/* --- Reorder Handle --- */
div[id$="_reorder"] {
  width: 20px;
  height: 20px;
  cursor: grab;
  margin: auto;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  background-image:
    linear-gradient(var(--border-color), var(--border-color)),
    linear-gradient(var(--border-color), var(--border-color)),
    linear-gradient(var(--border-color), var(--border-color));
  background-repeat: no-repeat;
  background-size: 70% 1px;
  background-position: center 30%, center 50%, center 70%;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

div[id$="_reorder"]:hover {
  background-color: #f0f0f0;
  border-color: #cccccc;
}

/* --- Options Handle (three-dot menu) --- */
div.options {
  width: 20px;
  height: 20px;
  cursor: pointer;
  margin: auto;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.options-menu {
  position: absolute;
  z-index: 300;
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 4px 0;
  min-width: 140px;
  display: none;
}

.options-menu.visible {
  display: block;
}

.options-menu button {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-color);
  text-align: left;
  padding: 6px 12px;
  font-size: 0.9rem;
  cursor: pointer;
}

.options-menu button:hover {
  background-color: #f5f5f5;
}

/* Render three horizontal dots centered in the box */
div.options::before {
  content: "";
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background-color: var(--border-color);
  box-shadow:
    -5px 0 0 var(--border-color),
     5px 0 0 var(--border-color);
}

div.options:hover {
  background-color: #f0f0f0;
  border-color: #cccccc;
}

/* --- Options Menu & Dialog --- */
.options-menu {
  position: absolute;
  z-index: 300;
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 3px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 4px 0;
  min-width: 140px;
  display: none;
}

.options-menu.visible {
  display: block;
}

.options-menu button {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-color);
  text-align: left;
  padding: 6px 12px;
  font-size: 0.9rem;
  cursor: pointer;
}

.options-menu button:hover {
  background-color: #f5f5f5;
}

.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
}

.dialog-overlay.hidden {
  display: none;
}

.dialog-overlay.loading {
  opacity: 0.4;
  pointer-events: none;
}

.dialog {
  background: #ffffff;
  border-radius: 5px;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  max-width: 640px;
  width: 95%;
  padding: 16px 18px 14px;
}

.dialog h3 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.dialog p {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.dialog-input-row {
  margin-bottom: 10px;
}

.dialog-input-row input[type="text"] {
  width: 100%;
  box-sizing: border-box;
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-buttons button {
  min-width: 80px;
}

.dialog-buttons #action_dialog_primary {
  background-color: var(--primary-color);
  color: #ffffff;
}

.dialog-buttons #action_dialog_primary:hover {
  background-color: #c9402a;
}

.dialog-buttons #action_dialog_cancel {
  background-color: #e0e0e0;
  color: #333333;
}

.dialog-buttons #action_dialog_cancel:hover {
  background-color: #d0d0d0;
}

/* Editable name card in the dialog */
.dialog-input-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 6px 10px;
  margin: 4px 0 10px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background-color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  font-size: 0.9rem;
  color: var(--text-color);
}

/* Base style for all 4 inputs inside the name editor */
.dialog-input-row input[type="text"] {
  border: none;
  padding: 2px 0;
  margin: 0;
  background: transparent;
  font: inherit;
  color: inherit;
  min-width: 0;             /* allow them to shrink */
  width: auto;              /* override the earlier width:100% dialog input rule */
  flex: 0 1 auto;
}

/* Remove the usual focus ring/box-shadow: they sit inside the card */
.dialog-input-row input[type="text"]:focus {
  outline: none;
  box-shadow: none;
}

/* Real-time validation feedback */
input:invalid {
  box-shadow: 0 1px 0 0 #d9534f; /* underline */
  color: #d9534f;
}

.dialog-buttons #action_dialog_primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Section part: mimic the .section pill */
#action_dialog_input_sec {
  padding: 2px 8px;
  border-radius: 9999px;
  background-color: #e8f0f7;
  color: #2c3e50;
  font-weight: 500;
}

/* Name part: give it a bit more room */
#action_dialog_input_nam {
  min-width: 8rem;
}

/* Source spec: slightly narrower, often looks like a code-ish token */
#action_dialog_input_src {
  min-width: 6rem;
  font-family: monospace;
  font-size: 0.85rem;
}

/* Version: compact; lines up with the v.X in the summary */
#action_dialog_input_ver {
  width: 3.5rem;
  text-align: right;
}

tr.dragging {
  opacity: 0.5;
  background: #fafafa;
}

tr.over {
  background-color: #e0e0e0;
}

/* "build_status === building" animation */
@keyframes build-underline {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.build_status[data-build_status="building"] {
  position: relative;
  overflow: hidden;
}

.build_status[data-build_status="building"]::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0.1rem;
  height: 3px;
  width: 40%;
  background: linear-gradient(
    to right,
    transparent,
    var(--primary-color),
    transparent
  );
  animation: build-underline 1.2s ease-in-out infinite;
  opacity: 0.9;
}

/* Highlight failed builds */
.build_status[data-build_status="error"] {
  background-color: rgba(223, 80, 57, 0.12); /* light version of IDUN orange */
  color: #a12f1c;                            /* darker text for contrast */
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 600;
}

/* --- Utility & Loader --- */
#loader.loading {
  visibility: visible;
  position: fixed;
  left: 50%;
  top: 50%;
  margin-left: -20px; /* Half of width */
  margin-top: -20px;  /* Half of height */
  z-index: 500;

  /* Hide the "Loading..." text from the div */
  color: transparent;

  /* Spinner animation styles */
  width: 40px;
  height: 40px;
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

#loader.notloading {
  visibility: hidden;
}

#body.loading {
  opacity: 0.4;
  pointer-events: none;
}

#body.notloading {
  opacity: 1.0;
  pointer-events: auto;
}

/* User page: ensure content can scroll above fixed footer */
#user_editor {
  padding-bottom: 80px; /* leave room for the fixed Save footer */
}

#projects_container {
  margin-top: 1rem;
}

.note {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: #666666;
}

.user-project {
  border: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 12px 14px;
  margin-top: 1rem;
  background-color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  position: relative;
}

.user-project h3 {
  margin: 0 0 0.5rem 0;
  display: flex;
  align-items: center; /* vertically center minus relative to name */
  gap: 0.5rem;
}

.allowed-path-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.allowed-path-input {
  flex: 1 1 auto;
  min-width: 0;
}

/* Users page: create user control */
#create_user_container {
  margin-top: 1.5rem;
  display: flex;
  justify-content: flex-start;
}

/* User page: bottom add-project control */
#add_project_container {
  margin-top: 1.5rem;
  display: flex;
  justify-content: flex-start;
}

/* User page: make all action buttons (inside and outside cards) look the same */
#add_project_link,
.path-remove,
.project-remove,
.add-path-link {
  min-width: auto;        /* override global 100px so they can size to label */
  padding: 4px 12px;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* Project config page: keep container + makefile inputs visually aligned */
#project_config_container_select,
#project_config_makefile_input {
  width: 100%;
  max-width: 320px;
  box-sizing: border-box;
}
