/* KingIsland shared UI — professional design system on top of Bootstrap 5. */

:root {
  --ki-fg:           #1f2328;
  --ki-fg-muted:    #57606a;
  --ki-fg-subtle:   #8b949e;
  --ki-border:       #d0d7de;
  --ki-border-soft:  #e6e8eb;
  --ki-surface:      #ffffff;
  --ki-surface-alt:  #f6f8fa;
  --ki-surface-hover:#eef3ff;

  /* Cohesive blue family — each module gets a distinct shade, nothing stark. */
  --ki-brand:        #1e40af;  /* deep blue, used for buttons/links */
  --ki-brand-dark:   #1e3a8a;
  --ki-cust:         #1e3a8a;  /* navy */
  --ki-gate:         #0284c7;  /* sky */
  --ki-alp:          #0e7490;  /* teal-blue */
  --ki-user:         #3730a3;  /* indigo */
  --ki-success:      #166534;
  --ki-danger:       #991b1b;
  --ki-warning:      #854d0e;
  --ki-info:         #0369a1;

  --ki-accent:       var(--ki-brand);
  --ki-accent-soft:  #e0e7ff;

  --ki-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body[data-module="cust"] { --ki-accent: var(--ki-cust); --ki-accent-soft: #dbeafe; }
body[data-module="gate"] { --ki-accent: var(--ki-gate); --ki-accent-soft: #e0f2fe; }
body[data-module="alp"]  { --ki-accent: var(--ki-alp);  --ki-accent-soft: #cffafe; }
body[data-module="user"] { --ki-accent: var(--ki-user); --ki-accent-soft: #e0e7ff; }

/* ---------- Typography (compact) ---------- */

html, body {
  font-family: var(--ki-font);
  font-size: 13.5px;
  color: var(--ki-fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body { line-height: 1.35; }

label, .form-label { font-weight: 500; color: var(--ki-fg); font-size: .8rem; }

/* ---------- Module header band inside each iframe ---------- */

#head {
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--ki-accent) 92%, #fff) 0%,
      var(--ki-accent) 100%);
  color: #fff;
  padding: .5rem .85rem !important;
  height: auto !important;
  min-height: 56px;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.12), 0 1px 0 rgba(0,0,0,.04);
}
#head label,
#head label b { color: #fff !important; font-size: 1rem !important; font-weight: 600; letter-spacing: .01em; }
#head input[type="text"],
#head input[type="search"] {
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.15);
  color: #fff;
  border-radius: 6px;
  padding: .2rem .55rem;
  font-size: .85rem;
  margin-left: .5rem;
}
#head input[type="text"]::placeholder,
#head input[type="search"]::placeholder { color: rgba(255,255,255,.75); }
#head input[type="text"]:focus,
#head input[type="search"]:focus {
  outline: none;
  border-color: #fff;
  background: rgba(255,255,255,.25);
  box-shadow: 0 0 0 3px rgba(255,255,255,.15);
}
#head input[type="checkbox"] { accent-color: #fff; margin-right: .25rem; }
#head .btn-sm,
#head .btn.btn-sm { font-size: .8rem; padding: .25rem .7rem; }

/* ---------- Big iframe tables (.ki-table and legacy .tableFixHead) ---------- */

.ki-table,
body table.tableFixHead,
body table.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
  background: var(--ki-surface);
}
.ki-table thead th,
body table.tableFixHead thead th,
body table.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #1e293b !important;   /* slate-blue, neutral across modules */
  color: #f1f5f9 !important;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  font-size: 11px;
  padding: .35rem .55rem !important;
  border: 0;
  border-bottom: 2px solid var(--ki-accent);
  white-space: nowrap;
  text-align: left;
}
.ki-table tbody td,
body table.tableFixHead tbody td,
body table.table tbody td {
  padding: .25rem .55rem !important;
  border: 0;
  border-bottom: 1px solid var(--ki-border-soft);
  line-height: 1.3;
}
.ki-table tbody tr:nth-of-type(even),
body table.tableFixHead tbody tr:nth-of-type(even),
body table.table tbody tr:nth-of-type(even) {
  background: var(--ki-surface-alt) !important;
}
.ki-table tbody tr:nth-of-type(odd),
body table.tableFixHead tbody tr:nth-of-type(odd),
body table.table tbody tr:nth-of-type(odd) {
  background: var(--ki-surface) !important;
}
.ki-table tbody tr:hover,
body table.tableFixHead tbody tr:hover,
body table.table tbody tr:hover {
  background: var(--ki-accent-soft) !important;
  cursor: pointer;
}

/* Soft state chip backgrounds used in some cells */
td.state-active   { color: var(--ki-success); font-weight: 600; }
td.state-inactive { color: var(--ki-fg-muted); }
td.state-danger   { color: var(--ki-danger);  font-weight: 600; }

/* ---------- Buttons ---------- */

.btn {
  font-family: var(--ki-font);
  font-weight: 500;
  border-radius: 6px;
  padding: .3rem .8rem;
  font-size: .82rem;
  transition: background .12s, box-shadow .12s, border-color .12s;
}
.btn-sm { font-size: .76rem; padding: .2rem .65rem; }
.btn-primary   { background: var(--ki-brand);   border-color: var(--ki-brand); }
.btn-primary:hover   { background: var(--ki-brand-dark); border-color: var(--ki-brand-dark); }
.btn-success   { background: var(--ki-success); border-color: var(--ki-success); }
.btn-danger    { background: var(--ki-danger);  border-color: var(--ki-danger); }
.btn-secondary { background: #ffffff; border-color: var(--ki-border); color: var(--ki-fg); }
.btn-secondary:hover { background: var(--ki-surface-alt); }

/* ---------- Modals (shared dialog chrome) ---------- */

.modal-content {
  border: 1px solid var(--ki-border);
  border-radius: 10px;
  box-shadow: 0 1.5rem 3rem rgba(0, 0, 0, .2);
  overflow: hidden;
}
/* modal-xs is a legacy class used throughout this app — give it a comfortable width. */
.modal-dialog.modal-xs { max-width: 720px; }
.modal-content::before {
  content: "";
  display: block;
  height: 4px;
  background: linear-gradient(90deg, var(--ki-accent) 0%, color-mix(in srgb, var(--ki-accent) 60%, #fff) 100%);
}
.modal-header {
  background: #fff;
  border-bottom: 1px solid var(--ki-border);
  padding: .6rem 1rem;
  align-items: center;
  gap: .4rem;
}
.modal-header .modal-title,
.modal-header h4.modal-title,
.modal-header h5.modal-title {
  margin: 0;
  font-size: .95rem;
  line-height: 1.3;
  font-weight: 600;
  color: var(--ki-fg);
}
.modal-header .modal-title ~ .modal-title {
  margin-top: .1rem;
  font-size: .82rem;
  font-weight: 500;
  color: var(--ki-fg-muted);
}
/* A modal-header is a flex row by default in BS5 — make stacked titles stack vertically
   with inline action buttons alongside. */
.modal-header {
  display: flex;
  flex-wrap: wrap;
  row-gap: .15rem;
  column-gap: .6rem;
}
.modal-header .modal-title { flex: 1 1 100%; }
.modal-header input[type="button"] {
  flex: 0 0 auto;
  align-self: center;
}
.modal-header .btn-close { flex: 0 0 auto; margin-left: auto; }
.modal-body {
  padding: .85rem 1rem;
  background: #fff !important;
  border: 0 !important;
}
/* Strip the wheat/blue-gray/yellow decorative wrappers used in legacy dialogs.
   Status colors on <td>/<tr> cells are preserved (we only target divs). */
.modal-content div[style*="background-color"],
.modal-content .table-container[style*="background-color"] {
  background: transparent !important;
  border: 0 !important;
  border-top: 0 !important;
  border-bottom: 0 !important;
  border-left: 0 !important;
  border-right: 0 !important;
}
/* The dialog `<form>` element is also sometimes a visual container. */
.modal-content form { padding: 0; margin: 0; }
.modal-body > .form-label,
.modal-body label.dia1 {
  font-weight: 500;
  color: var(--ki-fg-muted);
  font-size: .8rem;
}

/* ---- Cleaner form-row layout: label | input grid ---- */
/* Target any direct child of .modal-body that contains a .dia1 label.       */
.modal-body > div:has(> label.dia1) {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: .5rem;
  align-items: center;
  margin-bottom: .4rem;
}
.modal-body > div:has(> label.dia1) > label.dia1 {
  width: auto !important;
  text-align: right;
  margin: 0;
  padding-right: .15rem;
}
.modal-body > div:has(> label.dia1) input,
.modal-body > div:has(> label.dia1) select,
.modal-body > div:has(> label.dia1) textarea {
  width: 100%;
  max-width: 380px;
  float: none !important;
  margin: 0;
}
/* A textarea can stretch beyond the single-row cap. */
.modal-body > div:has(> label.dia1) textarea { max-width: 100%; }
/* A few rows wrap the <select> in a stray <td> — flatten it into the grid. */
.modal-body > div:has(> label.dia1) > td { display: contents; }
/* Inline extras (units, currency prefix, helper text) can still sit beside the input. */
.modal-body > div:has(> label.dia1) > .form-extra { margin-left: .35rem; color: var(--ki-fg-muted); }

/* Rhythm between logical groups in a dialog (Details / Tags / Access / Footer). */
.modal-body + div,
.modal-body + form > div { margin-top: .25rem; }

.modal-body input[type=text],
.modal-body input[type=tel],
.modal-body input[type=email],
.modal-body input[type=number],
.modal-body input[type=password],
.modal-body input[type=date],
.modal-body input[type=time],
.modal-body input[type=search],
.modal-body select,
.modal-body textarea {
  border: 1px solid var(--ki-border);
  border-radius: 5px;
  padding: .22rem .5rem;
  background: #fff;
  font-size: .8rem;
  transition: border-color .12s, box-shadow .12s;
  max-width: 100%;
}
.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
  border-color: var(--ki-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ki-accent) 22%, transparent);
  outline: 0;
}
.modal-body input[readonly],
.modal-body textarea[readonly] {
  background: var(--ki-surface-alt);
  color: var(--ki-fg-muted);
  cursor: default;
}

/* Tables inside dialogs (anywhere within .modal-content) */
.modal-content table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  margin-bottom: .4rem;
}
.modal-content table thead th,
.modal-content table th {
  background: #1e293b !important;
  color: #f1f5f9 !important;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: .03em;
  padding: .3rem .5rem !important;
  border: 0;
  border-bottom: 2px solid var(--ki-accent);
  text-align: left;
}
.modal-content table tbody td,
.modal-content table td {
  padding: .22rem .5rem !important;
  border: 0;
  border-bottom: 1px solid var(--ki-border-soft);
  font-size: 12px;
}
.modal-content table tbody tr:nth-of-type(even) { background: var(--ki-surface-alt); }
.modal-content table tbody tr:hover { background: var(--ki-accent-soft); }

/* Section wrapper panels inside dialogs (Tags/Access blocks) */
#TagsTable, #UAccessTable, #CustAccessPanel {
  background: var(--ki-surface-alt);
  border: 1px solid var(--ki-border);
  border-radius: 8px;
  padding: .4rem .6rem;
  margin: .4rem 1rem;
}
#TagsTable > div:first-child,
#UAccessTable > div:first-child,
#CustAccessPanel > h5 {
  font-size: .82rem;
  font-weight: 600;
  color: var(--ki-fg);
  margin-bottom: .3rem;
}

.modal-footer {
  padding: .55rem 1rem;
  background: var(--ki-surface-alt);
  border-top: 1px solid var(--ki-border);
  gap: .4rem;
}

.modal-header input[type=button],
.modal-body input[type=button] {
  border: 1px solid var(--ki-border);
  border-radius: 5px;
  padding: .18rem .6rem;
  background: #fff;
  font-weight: 500;
  font-size: .78rem;
  cursor: pointer;
  transition: background .12s;
}
.modal-header input[type=button]:hover,
.modal-body input[type=button]:hover { background: var(--ki-surface-alt); }

/* ---------- Scrollbars ---------- */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: #c4c9d0; border-radius: 10px;
  border: 2px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: #a8aeb6; background-clip: content-box; }

/* ---------- Mobile: full-screen dialogs ---------- */
@media (max-width: 575.98px) {
  .modal-dialog {
    margin: 0;
    max-width: none;
    min-height: 100%;
  }
  .modal-content {
    min-height: 100vh;
    border-radius: 0;
    border: 0;
  }
  .modal-body { padding: .7rem; }
  .modal-header, .modal-footer { padding: .55rem .75rem; }
  .modal-body label.dia1 {
    display: block; width: auto; text-align: left; margin-bottom: .15rem;
  }
  .modal-body input[type=text],
  .modal-body input[type=tel],
  .modal-body input[type=email],
  .modal-body input[type=number],
  .modal-body select,
  .modal-body textarea { width: 100%; }

  #head { min-height: auto; padding: .5rem .7rem !important; }
  #head label { font-size: .95rem !important; display: block; }
}
