/*
Styles for admin pages.

The normal structure for an admin page is:

<html>
    <body>
        <div class="wrap">
            <div class="card">
            </div>
            <div class="card">
                <div class="header-controls">
                </div>
            </div>
            <div class="err" or "ok" or none>
            </div>
            <div class="card">
                <div class="data-cards-container">
                    <div class="data-card">
                        <div class="card-header">
                        </div>
                        <div class="card-body">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
*/

:root { 
    color-scheme: light dark; 
}

html {
    /* Always reserve space for the scrollbar to prevent "jumping" or overlapping */
    scrollbar-gutter: stable;
    overflow-y: auto;
}

body { 
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; 
    min-height:100dvh; 
    background:#0b1220; 
    color:#eef2ff; 
    margin:0; 
    display: block; 
    flex-direction:column; 
    align-items:center; 
    padding: 2rem 1rem;
    overflow-x: hidden; /* Prevents tiny sub-pixel rounding issues from causing a scrollbar */
    width: 100%;
    box-sizing: border-box;
}

header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 1rem 1.25rem; 
    background: #111a2b; 
    position: sticky; 
    top: 0;
    width: 100%;
    box-sizing: border-box; /* Prevents padding from adding to the 100% width */
    z-index: 100; /* Ensures it stays on top of cards */
}

.wrap { 
    margin: 0 auto; /* This centers the content without the flexbox math bug */
    padding: 0;     /* Remove padding here to keep math simple */
    display: grid; 
    gap: 0.5rem; 
    width: 100%;
    max-width: 1200px;
    box-sizing: border-box;
    align-items: start;
}

/* Styles for tables shown as card layouts */
.data-cards-container {
    display: grid !important;
    /* 1. data-card minimum width changed 300px to 250px */
    /* 2. Added min() to ensure it never exceeds 100% of the parent width */
    grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr));
    width: 100%;
    gap: 1.25rem;
    margin-top: 1rem;
    align-items: stretch;
    box-sizing: border-box;
}

/* Card element may contains more cards or data-cards */
.card { 
    width: 100%;            /* Try to take full width */
    max-width: 1200px;      /* Stop it from getting too wide on desktop */
    margin: 0.5rem auto;      /* Centers the card horizontally */
    box-sizing: border-box; /* Ensures padding doesn't add to width */
    flex-shrink: 1;
    background: #111a2b; 
    padding: 1rem; 
    border-radius: 16px; 
    box-shadow: 0 10px 30px rgba(0,0,0,.35);
    min-width: 0;
}


/* Compact card element may contains more cards or data-cards.
   A compact card is the same as a card but with a smaller max width.
*/
.compact-card { 
    width: 100%;                 /* Try to take full width */
    max-width: 500px;            /* Stop it from getting too wide on desktop */
    box-sizing: border-box;      /* Ensures padding doesn't add to width */
    margin: 1rem auto;           /* Centers the card horizontally */
    flex-shrink: 1;
    background: #111a2b; 
    padding: 1rem; 
    border-radius: 16px; 
    box-shadow: 0 10px 30px rgba(0,0,0,.35);
    min-width: 0;
}

/* Deal with nested cards */
.card .card {
    padding: 1rem 0; /* Vertical padding stays, horizontal removed for nested cards */
    box-shadow: none; /* Optional: clean up nested visuals */
}

.card-footer {
    display: flex;
    gap: 10px;
    margin-top: auto; /* Pushes footer to the bottom of the card */
}

.card-footer .btn {
    flex: 1; /* Makes both buttons equal width */
}

/* Card status Colors */
.card-disabled { color: #d32f2f; font-weight: bold; }
.card-active { color: #388e3c; font-weight: bold; }

/* How much of a user's data limit is used (the fill's width is the percentage) */
.usage-bar {
    height: 8px;
    background: #1f2a3f;
    border-radius: 4px;
    overflow: hidden;
    margin: .4rem 0 .8rem;
}

.usage-bar-fill {
    height: 100%;
    background: #3b82f6;
}

.usage-bar-fill.near-full {
    background: #dc2626;
}


/* Individual Card containing data to display */
.data-card {
    width: 100%; 
    min-width: 0; /* Critical for grid items to prevent overflow */
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    background: #1c293e; /* Slightly lighter than the main .card */
    border: 1px solid #2d3d5a;
    border-radius: 12px;
    padding: 1rem;
    color: #ffffff; /* Ensure text is readable */
    transition: transform 0.2s ease;
    word-break: break-word;
    overflow-wrap: break-word;
}

.data-card:hover {
    transform: translateY(-5px); /* Lift effect on hover */
    background: #24344d;
}

/* --- Responsive Padding Adjustments --- */
@media (max-width: 600px) {
    body {
        padding: 1rem 0.5rem; /* Reduce top/bottom and side padding */
    }

    .wrap {
        margin: 1rem auto;
        padding: 0 0.5rem; /* Shrink the wrap padding */
    }

    .card {
        padding: 0.75rem; /* Give the data-cards more room */
    }
}

/* Header styles */
h1 { 
    margin:0; 
    font-size:1.0rem; 
}

table { 
    width:100%; 
    border-collapse: collapse; 
}

th, td { 
    text-align:left; 
    padding:.6rem .5rem; 
    border-bottom:1px solid #22304d; 
    font-size:.95rem; 
}
      

label { 
    display:block; 
    font-size:.9rem; 
    margin:.75rem 0 .35rem; 
    color:#a8b3cf; 
}

input[type="text"], input[type="password"], input[type="checkbox"] { 
    width:100%; 
    padding:.75rem .9rem; 
    border-radius:10px; 
    border:1px solid #22304d; 
    background:#0e1626; 
    color:#e6edff; 
    box-sizing: border-box; 
}

/* Button styles */
.btn { 
    margin-top:1rem; 
    padding:.7rem 1rem; 
    border:0; 
    border-radius:10px; 
    background:#3b82f6; 
    color:white; 
    font-weight:600; 
    cursor:pointer; 
}

/* A link styled as a button */
a.btn {
    display:inline-block;
    text-decoration:none;
}

.btn.secondary {
    background:#5c5c5c; 
    color:white; 
}

/* Message divs */
.msg { 
    background:#1e3a8a; 
    color:#dbeafe; 
    padding:.6rem .8rem; 
    border-radius:10px;
     margin-bottom:1rem; 
     font-size:.9rem; 
}

.err { 
    background:#7f1d1d; 
    color:#fee2e2; 
    padding:.6rem .8rem; 
    border-radius:10px; 
    margin-top: 1rem; 
    margin-bottom:1rem; 
    font-size:.9rem; 
}

.ok { 
    background:#064e3b; 
    color:#d1fae5; 
    padding:.6rem .8rem; 
    border-radius:10px; 
    font-size:.9rem; 
}

.danger { 
    background:#dc2626; 
}

.hint { 
    margin-top: 1.5rem; 
    color:#9fb0d4; 
    font-size:.85rem; 
}

a { 
    color:#93c5fd; 
    text-decoration:none; 
}

a:hover { 
    text-decoration:underline; 
}

form.inline { 
    display:inline; 
}

.row { 
    display:flex; 
    justify-content:space-between; 
    align-items:center; 
    gap:0.5rem; 
}

/* Group of checkboxes in a modal dialog */
.checkbox-group {
    display: flex !important;
    flex-direction: row !important; /* Ensure they stay side-by-side */
    justify-content: flex-start !important;
    
    /* Force the element to the left of the flex container */
    margin-right: auto; 
    margin-left: 0;
    
    /* Ensure it doesn't try to fill the whole width if the parent is centering */
    width: max-content; 
    
    gap: 1.5rem;
    padding: 0.5rem 0;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    white-space: nowrap; /* Keeps "Admin Access" on one line */
}

/* Make sure the inputs are not getting squashed */
.checkbox-group input[type="checkbox"] {
    margin: 0;
    width: 16px;
    height: 16px;
    accent-color: #3b82f6; /* Colors the checkbox blue to match UI */
}

.muted { 
    color:#9fb0d4; font-size:.9rem; 
}

/* info-header is the box at the top of each page */
.info-header {
    display: flex;
    align-items: center; /* Vertically centers the button relative to the 2 lines */
    gap: 20px;           /* Space between the text and the button */
}

/* info-text is the text within the info-header*/
.info-text {
    display: flex;
    flex-direction: column;
    line-height: 1.4;    /* Adjust for better spacing between lines */
}

/* Optional: Make the button look better next to text */
.logout-btn {
    height: fit-content;
    padding: 10px 20px;
}



/* Header & Badges */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
    margin-bottom: 10px;
    padding-bottom: 10px;
}

.card-header h3 { margin: 0; font-size: 1.2rem; }

.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
}
.badge.admin { background: #e3f2fd; color: #0d47a1; }
.badge.standard { background: #f5f5f5; color: #616161; }
.badge.anonymous { background: #f5f5f5; color: #34a019; }

/* Status Colors */
.text-danger { color: #d32f2f; font-weight: bold; }
.text-success { color: #388e3c; font-weight: bold; }

/* Button to fill the bottom */
.full-width { width: 100%; margin-top: 10px; }

/* Modal dialog box styles */
.modal {
  display: none; 
  position: fixed;
  z-index: 1000;
  left: 0; 
  top: 0;
  width: 100%; 
  height: 100%;
  background-color: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: center;
  padding: 1rem;            /* Keeps the dialog off the edges of small screens */
  box-sizing: border-box;
}

/* The dialog never grows taller than the screen: it scrolls instead */
.modal-content {
  margin: 0;
  max-width: 500px;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid #2d3d5a;
}

/* A dialog with many fields (e.g. editing a scenario), spaced more tightly */
.compact-modal .modal-header {
  margin-bottom: 0.5rem;
}

.compact-modal .modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.compact-modal .close-modal {
  line-height: 1;
}

.compact-modal .err {
  margin: 0 0 0.6rem;
}

.compact-modal .form-group {
  margin-bottom: 0.6rem;
}

.compact-modal .form-group label {
  font-size: 0.85rem;
  margin-bottom: 0.2rem;
}

.compact-modal .form-group input {
  padding: 0.4rem 0.5rem;
}

.compact-modal .form-group small {
  font-size: 0.75rem;
  margin-top: 0.2rem;
}

.compact-modal .checklist-controls {
  margin-bottom: 2px;
}

.compact-modal .checklist-container {
  max-height: 140px;
}

/* On short screens, let the group checklist shrink further */
@media (max-height: 700px) {
  .compact-modal .checklist-container {
    max-height: 96px;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end; /* Aligns buttons to the right */
    gap: 0.75rem;              /* Space between buttons */
    margin-top: 0.5rem;
    padding-top: 0rem;
}

.close-modal {
  color: #aaa;
  font-size: 28px;
  cursor: pointer;
  padding-left: 28px;
}

.form-group {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: #cbd5e1;
}

.form-group input {
    padding: 0.6rem;
    background: #0b1220; /* Darker than the card for contrast */
    border: 1px solid #2d3d5a;
    border-radius: 6px;
    color: white;
}

.form-group input:focus {
    outline: none;
    border-color: #3b82f6;
}

/* 
    Admin div containing controls for the data items (shown in data-cards).

    This contains admin controls structured as follows:

      <div class="card main-admin-card">
        <div class="header-controls">
          <div class="search-wrapper">
              <input type="text" id="cardSearch">
              <span id="clearSearch" class="clear-icon"></span>
          </div> 
          <select id="cardSort">
          </select>
          <button class="btn primary">+ New Item</button>
        </div>
      </div>
*/
.main-admin-card {
    width: 100%;
    max-width: 1200px;
    align-self: start;  /* This is the magic line */
    height: auto;       /* Ensures no fixed height is inherited */
    padding: 0.75rem 1.25rem; /* Slimmer vertical padding (top/bottom) */
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Control the height of the card here instead */
    padding: 0;
}

.header-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center; /* Ensures everything is vertically centered */
    flex-wrap: wrap; /* Allows items to move to a new line instead of pushing wide */
    width: 100%;    /* Ensure container spans the whole card */
}

.header-controls .btn {
    margin-top: 0; 
    /* Ensure height matches the other inputs (approx 36-40px) */
    padding: 0.5rem 1rem; 
    line-height: 1.2;
}

.main-admin-card h2 {
    margin: 0;             /* Removes the 0.83em margins entirely */
    line-height: 1;        /* Keeps the height strictly to the font size */
    font-size: 1.25rem;    /* Makes it look more like a UI header, less like a document header */
}

.search-wrapper {
    flex: 1;
    position: relative;
    display: inline-flex;
    align-items: center;
    
    /* Move the sizing and transition logic HERE */
    min-width: 120px;
    max-width: 400px; 
    transition: max-width 0.3s ease;
}

/* If the input inside is focused, expand the wrapper */
.search-wrapper:focus-within {
    max-width: 500px;
}

.search-wrapper input {
    width: 100%; /* Now it fills the wrapper perfectly */
    padding: 0.5rem 2.2rem 0.5rem 0.8rem;
    background: #0b1220;
    border: 1px solid #2d3d5a;
    color: white;
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none; /* Handle focus state on the wrapper border instead */
}

/* Change the border color when the user clicks the input */
.search-wrapper:focus-within input {
    border-color: #3b82f6;
}

/* Ensure the other items don't shrink too much */
#cardSort, .header-controls .btn {
    flex-shrink: 0; 
}

/* The Clear Icon (X) */
.clear-icon {
    position: absolute;
    right: 8px;
    /* This centering trick is more reliable than 'line-height' */
    top: 50%;
    transform: translateY(-50%); 
    
    cursor: pointer;
    color: #64748b;
    font-size: 1.2rem;
    padding: 4px; /* Increases clickable area without moving the icon */
    display: none; /* Controlled by JS filterUsers() */
    user-select: none;
    transition: color 0.2s, transform 0.1s;
}

.clear-icon:hover {
    color: #f87171;
}

.clear-icon:active {
    transform: translateY(-50%) scale(0.9); /* Tiny click feedback */
}

/* 
    Drop down menu for sorting.
*/
#cardSort {
    appearance: none; /* Removes the default browser arrow */
    -webkit-appearance: none;
    -moz-appearance: none;
    min-width: 0;      /* Allow it to shrink below 160px if necessary */
    flex: 1;           /* Allows it to share shrinking responsibilities */
    max-width: 160px;  /* Keeps it at your preferred size on large screens */

    background-color: #0b1220;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 1em;
    
    border: 1px solid #2d3d5a;
    border-radius: 8px;
    color: white;
    padding: 0.5rem 2.5rem 0.5rem 0.8rem; /* Extra right padding for the custom arrow */
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;

}

#cardSort:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Style the options inside the dropdown */
#cardSort option {
    background: #111a2b; /* Matches your card color */
    color: white;
}

/** Delete modal */
/* Make the delete modal feel like a small dialog */
.small-modal {
    max-width: 400px;
    margin: 15vh auto; /* Sits higher up on the screen */
}

/* Ensure the delete button in the card looks good */
.btn-delete-icon {
    background: transparent;
    color: #64748b;
    border: none;
    cursor: pointer;
    transition: color 0.2s;
}

.btn-delete-icon:hover {
    color: #ef4444;
}

/* Scrolling list box with checkboxes */
.checklist-container {
    width: 100%; 
    box-sizing: border-box; 
    
    max-height: 192px; 
    overflow-y: auto;
    border-radius: 4px;
    padding: 5px;
    border: 1px solid #22304d; 
    background: #0e1626;
}

.checklist-item {
    display: flex;
    flex-direction: row !important;
    justify-content: flex-start !important;
    
    /* Changed to 100% so the hover background fills the whole width */
    width: 100%; 
    box-sizing: border-box;

    gap: 0.5rem;
    padding: 4px 8px; /* Added a little padding for a better hover look */

    /* Force the element to the left of the flex container */
    margin-right: auto;
    margin-left: 0;
    /* Ensure it doesn't try to fill the whole width if the parent is centering */
    width: max-content;

}

.checklist-item:last-child {
    border-bottom: none;
}

.checklist-item input {
    /* Keep margin minimal since we have a gap */
    margin: 0; 
    cursor: pointer;
}

.checklist-item label {
    cursor: pointer;
    flex-grow: 1;
    font-family: sans-serif;
    /* This ensures clicking anywhere on the line works */
    display: block; 
}

.checklist-item:hover {
    background-color: #283652;
    border-radius: 2px;
}

.checklist-controls {
  display: flex;
  gap: 15px;
  margin-bottom: 5px;
}

.btn-link {
  background: none;
  border: none;
  color: #4a90e2;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0;
  text-decoration: underline;
}

.btn-link:hover {
  color: #77b1f3;
}

/* Member pills container */
.member-pill-container {
  display: flex;
  flex-wrap: wrap; 
  /* Increased row-gap to 12px and column-gap to 8px */
  gap: 12px 8px; 
  align-items: center;
  margin-top: 10px;
  /* Ensures the 'shelf' each row sits on is tall enough */
  line-height: 1.6; 
}

/* Individual pill */
.member-pill {
  display: inline-flex;
  align-items: center;
  background-color: #283652;
  color: #e0e6ed;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.8rem;
  border: 1px solid #3b4b6b;
  white-space: nowrap;
  
  /* This forces an extra 2px of space at the top/bottom of every pill 
     independent of the flex gap */
  margin-block: 2px; 
}

.more-count {
  background-color: transparent;
  border: 1px dashed #4a90e2;
  color: #4a90e2;
}

.no-members {
  color: #667694;
  font-style: italic;
  font-size: 0.9rem;
}

/* OK Button for file upload */
#uploadBtn {
    position: relative;
    /* Create a sharp line between the green progress and the original button color */
    background: linear-gradient(to right, #4CAF50 0%, #4CAF50 0%, #3498db 0%);
    background-repeat: no-repeat;
    transition: background-size 0.1s ease;
    overflow: hidden;
    z-index: 1;
}

#uploadBtn.uploading {
    /* Disable hover effects during upload if you have any */
    pointer-events: none;
    border-color: #2e7d32;
}

/* Visual feedback for the inputs with the class "scenario-modal-control" */
.scenario-modal-control:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Error in a record property */
.property-error {
    background-color: red;
    color: white;
    border-radius: 2px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 4px 20px;
}

/* --- Suggestion list for a text box (suggest_list.js) ---
   Added to <body> with a fixed position, above the modal dialogs (z-index 1000). */
.suggest-list {
    position: fixed;
    z-index: 1100;
    box-sizing: border-box;
    max-height: 200px;
    overflow-y: auto;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    background: #0b1220;
    border: 1px solid #3b82f6;
    border-radius: 6px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
    font-size: 0.85rem;
}

.suggest-list[hidden] {
    display: none;
}

.suggest-item {
    padding: 0.35rem 0.6rem;
    color: #cbd5e1;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.suggest-item strong {
    color: #ffffff;
    font-weight: 700;
}

.suggest-item.active {
    background: #24344d;
    color: #ffffff;
}

/* --- Scenario folders (admin_scenarios.html) --- */

/* A folder: a collapsible section holding scenario cards and further folders */
.scenario-folder {
    margin-top: 1rem;
    border: 1px solid #2d3d5a;
    border-radius: 12px;
    background: #0f1828;
}

.scenario-folder > summary {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

/* Hide the default disclosure marker (it is drawn with ::before instead) */
.scenario-folder > summary::-webkit-details-marker {
    display: none;
}

.scenario-folder > summary::before {
    content: "\25B8";               /* right-pointing triangle */
    display: inline-block;
    width: 1rem;
    color: #8fa3c7;
    transition: transform 0.15s ease;
}

.scenario-folder[open] > summary::before {
    transform: rotate(90deg);
}

.scenario-folder > summary:hover {
    background: #16223a;
    border-radius: 12px;
}

.scenario-folder .folder-name {
    font-weight: 600;
    font-size: 1.05rem;
    overflow-wrap: anywhere;
}

.scenario-folder .folder-count {
    color: #8fa3c7;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* The rename button sits at the right of the folder's summary */
.scenario-folder .rename-folder-btn {
    margin-left: auto;
    white-space: nowrap;
}

/* A folder's contents, indented under its summary */
.scenario-folder > .folder-body {
    padding: 0 1rem 1rem 1.5rem;
}

.scenario-folder > .folder-body > .data-cards-container:first-child {
    margin-top: 0.5rem;
}

@media (max-width: 600px) {
    .scenario-folder > .folder-body {
        padding: 0 0.5rem 0.5rem 0.75rem;
    }
}