/**
 * Unified Forms, Tables, and Fieldsets CSS
 * ========================================
 * Provides consistent styling across all pages for:
 * - Tables (standard, data, summary)
 * - Forms and form controls (inputs, textareas, selects)
 * - Fieldsets and legends
 * - Labels and validation states
 */

/* ========== BASE FORM ELEMENTS ========== */

fieldset {
  margin: 1rem 0;
  padding: 1.2rem 1.15rem 0.8rem;
  border: 1px solid #d8e2f0;
  border-radius: 10px;
  ;
  background: linear-gradient(180deg, #ffffff 0%, #f9fbfd 100%);
  box-shadow: 0 4px 12px rgba(15, 44, 82, 0.05);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

fieldset:hover {
  box-shadow: 0 8px 16px rgba(15, 44, 82, 0.08);
  border-color: #cdd7e8;
}

legend {
  font-weight: 700;
  font-size: 0.95rem;
  color: #0f2642;
  padding: 0.18rem 0.62rem;
  border: 1px solid #c5d4e8;
  border-radius: 10px;
  background: linear-gradient(180deg, #f5f9fd 0%, #eef4fa 100%);
  width: auto;
  margin-left: -0.62rem;
}

/* ========== INPUT CONTROLS ========== */

input:not([type='checkbox']):not([type='radio']):not([type='submit']):not([type='button']):not([type='date']):not([type='time']):not([type='datetime-local']):not([type='month']):not([type='week']),
textarea,
select {
  width: 100%;
  min-height: 2.35rem;
  padding: 0.62rem 0.8rem;
  border: 1.5px solid #c8d5e6;
  border-radius: 10px;
  background-color: #ffffff;
  color: #1a3554;
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
  box-sizing: border-box;
}

input::placeholder,
textarea::placeholder {
  color: #9ab0c9;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #2f73bd;
  box-shadow: 0 0 0 3.5px rgba(47, 115, 189, 0.14), inset 0 1px 2px rgba(0, 0, 0, 0.02);
  background-color: #ffffff;
}

/* Restore native iOS appearance for date/time inputs */
input[type='date'],
input[type='time'],
input[type='datetime-local'],
input[type='month'],
input[type='week'] {
  -webkit-appearance: auto;
  appearance: auto;
  font-size: 1rem;
  /* Prevent iOS auto-zoom */
  font-family: inherit;
  box-sizing: border-box;
}

/* Select dropdown custom styling */
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%232f73bd' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.2rem;
  cursor: pointer;
}

select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Textarea specific */
textarea {
  min-height: 9rem;
  resize: vertical;
  padding: 0.75rem 0.8rem;
}

/* Checkbox and Radio styling */
input[type='checkbox'],
input[type='radio'] {
  width: 1.1rem;
  height: 1.1rem;
  margin-right: 0.5rem;
  cursor: pointer;
  accent-color: #2f73bd;
  vertical-align: middle;
}

input[type='checkbox']:focus,
input[type='radio']:focus {
  outline: 2px solid #2f73bd;
  outline-offset: 2px;
}

/* ========== LABELS ========== */

label {
  display: block;
  margin-bottom: 0.1rem;
  font-weight: 600;
  color: #1a3554;
  font-size: 0.95rem;
  cursor: pointer;
}

label.required::after,
label[required]::after {
  content: ' *';
  color: #e74c3c;
  font-weight: 700;
}

input[type='checkbox']~label,
input[type='radio']~label {
  display: inline;
  margin-bottom: 0;
  font-weight: 500;
  color: #2a4a6f;
  cursor: pointer;
}

/* ========== BUTTONS ========== */

button:not(.collapsible):not(.too-account-copy-btn):not(.tab-button):not(.nav-dropbtn):not(.topbar-session-account-btn):not(.topbar-hamburger),
input[type='submit'],
input[type='button'],
input[type='reset'],
.formbutton {
  min-height: 2.4rem;
  padding: 0.56rem 1.3rem;
  border: none;
  border-radius: 10px;
  ;
  background: linear-gradient(135deg, #1c4f8f 0%, #2f73bd 100%);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.3px;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(27, 78, 140, 0.18);
  transition: all 0.2s ease;
  margin-right: 0.6rem;
  margin-bottom: 0.45rem;
}

button:not(.collapsible):hover,
input[type='submit']:hover,
input[type='button']:hover,
input[type='reset']:hover,
.formbutton:hover {
  box-shadow: 0 16px 36px rgba(27, 78, 140, 0.25);
  background: linear-gradient(135deg, #1a4580 0%, #2d6aad 100%);
}

button:not(.collapsible):active,
input[type='submit']:active,
input[type='button']:active,
input[type='reset']:active,
.formbutton:active {
  box-shadow: 0 8px 16px rgba(27, 78, 140, 0.15);
}

button:disabled,
input:disabled,
input[type='submit']:disabled,
input[type='button']:disabled,
input[type='reset']:disabled,
.formbutton:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Success button variant */
input[type='submit'].success,
button.success {
  background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
  box-shadow: 0 12px 28px rgba(40, 167, 69, 0.18);
}

input[type='submit'].success:hover,
button.success:hover {
  background: linear-gradient(135deg, #218838 0%, #1aa179 100%);
  box-shadow: 0 16px 36px rgba(40, 167, 69, 0.25);
}

/* Cancel/Reset button variant */
button.cancel,
input[type='reset'] {
  background: linear-gradient(135deg, #6c757d 0%, #848e99 100%);
  box-shadow: 0 12px 28px rgba(108, 117, 125, 0.18);
}

button.cancel:hover,
input[type='reset']:hover {
  background: linear-gradient(135deg, #5a6268 0%, #6a7278 100%);
  box-shadow: 0 16px 36px rgba(108, 117, 125, 0.25);
}

/* ========== TABS ========== */

.tabs-nav {
  display: flex;
  border-bottom: 2px solid #d7e2ee;
  margin: 0 0 2rem;
  gap: 0;
}

.tabs-nav .tab-button {
  margin: 0;
  padding: 1rem 1.5rem;
  min-height: auto;
  border: none;
  border-radius: 0;
  background: transparent;
  color: #607489;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: normal;
  box-shadow: none;
  position: relative;
  transition: color 0.15s ease;
}

.tabs-nav .tab-button:hover {
  transform: none;
  box-shadow: none;
  background: transparent;
  color: #35506c;
}

.tabs-nav .tab-button.active {
  color: #1d4f8f;
  background-color: transparent !important;
  font-weight: 800;
}

/* Override newswift.css global .active:after injected minus sign on active tabs. */
.tabs-nav .tab-button.active:after {
  content: '' !important;
  font-size: inherit !important;
  position: absolute !important;
  bottom: -2px !important;
  left: 0 !important;
  right: 0 !important;
  height: 3px !important;
  background: #1d4f8f !important;
  display: block !important;
  float: none !important;
  margin: 0 !important;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  background-color: transparent !important;
}

/* Override newswift.css global .active:after on active pane wrappers. */
.tab-panel.active:after {
  content: '' !important;
  display: none !important;
}

/* ========== TABLES ========== */

table {
  width: 100%;
  border-collapse: collapse;
  background-color: #ffffff;
  border: 1px solid #dce4f0;
  border-radius: 10px;
  ;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(15, 44, 82, 0.06);
  font-family: inherit;
  font-size: 0.95rem;
  margin: 1rem 0;
}

table thead {
  background: linear-gradient(180deg, #f0f6fd 0%, #e8f0f8 100%);
  border-bottom: 2px solid #c5d4e8;
}

table thead th {
  padding: 0.85rem 1rem;
  text-align: left;
  font-weight: 700;
  color: #0f2642;
  white-space: nowrap;
  vertical-align: middle;
  letter-spacing: 0.3px;
}

table thead th:not(:last-child) {
  border-right: 1px solid #d8e2f0;
}

table tbody tr {
  border-bottom: 1px solid #dce4f0;
  transition: background-color 0.15s ease;
}

table tbody tr:hover {
  background-color: #f8fafd;
}

table tbody tr:last-child {
  border-bottom: 1px solid #dce4f0;
}

table tbody td {
  padding: 0.85rem 1rem;
  color: #2a4a6f;
  vertical-align: top;
  word-break: break-word;
}

table tfoot {
  background-color: #f8fafd;
  border-top: 2px solid #c5d4e8;
}

table tfoot td,
table tfoot th {
  padding: 0.85rem 1rem;
  font-weight: 600;
  color: #0f2642;
}

/* Striped table rows */
table tbody tr:nth-child(odd) {
  background-color: #ffffff;
}

table tbody tr:nth-child(even) {
  background-color: #f8fafd;
}

table tbody tr:nth-child(odd):hover,
table tbody tr:nth-child(even):hover {
  background-color: #eef5fb;
}

/* Compact table variant */
table.compact tbody td,
table.compact thead th {
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
}

/* Data table variant */
table.dataTable tbody tr.selected {
  background-color: #e3f2fd;
}

table.dataTable tbody tr.selected:hover {
  background-color: #bbdefb;
}

/* Summary table - legacy support */
table.summary,
table.summary td,
table.summary th {
  padding: 0.6rem 0.8rem;
}

table.summary tr.header,
table.summary tr.header td {
  background-color: #555555;
  color: #ffffff;
  font-weight: bold;
}

table.summary tr.norm0 td {
  background-color: #eeeeee;
}

table.summary tr.norm1 td {
  background-color: #dddddd;
}

/* Active state row styling */
table tbody tr.active {
  background-color: #ffeaa7;
}

table tbody tr.active:hover {
  background-color: #ffeb3b;
}

/* Status indicators */
table td.status-ok,
table td.ok {
  color: #28a745;
  font-weight: 600;
}

table td.status-bad,
table td.bad {
  color: #e74c3c;
  font-weight: 600;
}

table td.status-pending,
table td.pending {
  color: #f39c12;
  font-weight: 600;
}

table td.status-warning,
table td.warning {
  color: #fd7e14;
  font-weight: 600;
}

/* ========== FORM WRAPPER CLASSES ========== */

.form-group {
  margin-bottom: 1rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

/* Legacy PHP/JS form output wrappers (.forminput, .unitinput, .resolve) */
.forminput,
.unitinput,
.resolve {
  margin-bottom: 0.85rem;
}

.forminput label,
.unitinput label {
  display: block;
  float: none;
  width: 100%;
  text-align: left;
  margin: 0 0 0.1rem;
  font-weight: 650;
  color: #1a3554;
  font-size: 0.95rem;
}

/* The JS form builder puts <br> after labels — suppress them */
.forminput br,
.unitinput br {
  display: none;
}

.unitinput {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.unitinput input,
.unitinput select {
  display: block;
  width: 100%;
  min-width: 0;
}

/* Inner form container generated by tooForm() and similar JS builders */
form .container,
.panel-body .container {
  border: 1px solid #dce4f0;
  border-radius: 10px;
  padding: clamp(1rem, 1.5vw, 1.5rem);
  background: linear-gradient(180deg, #fbfdff 0%, #f5f8fc 100%);
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  margin: 0;
}

.form-inline input,
.form-inline textarea,
.form-inline select {
  display: inline-block;
  width: auto;
  margin-right: 0.5rem;
}

/* Form validation states */
input.error,
select.error,
textarea.error {
  border-color: #e74c3c;
  background-color: #fff5f5;
}

input.error:focus,
select.error:focus,
textarea.error:focus {
  border-color: #e74c3c;
  box-shadow: 0 0 0 3.5px rgba(231, 76, 60, 0.14);
}

input.success,
select.success,
textarea.success {
  border-color: #28a745;
  background-color: #f1f9f1;
}

input.success:focus,
select.success:focus,
textarea.success:focus {
  border-color: #28a745;
  box-shadow: 0 0 0 3.5px rgba(40, 167, 69, 0.14);
}

.form-error,
.field-error {
  color: #e74c3c;
  font-size: 0.85rem;
  margin-top: 0.25rem;
  display: block;
}

.form-help,
.field-help {
  color: #6c757d;
  font-size: 0.85rem;
  margin-top: 0.25rem;
  display: block;
  font-style: italic;
}

/* ========== LAYOUT UTILITIES ========== */

.page-shell {
  max-width: 100%;
  margin: 0.5rem auto 1rem;
  padding: 0 10px;
}

.page-content {
  color: #10243e;
}

.card-section {
  background: linear-gradient(180deg, #ffffff 0%, #f4f8fe 100%);
  border: 1px solid #d6e0ec;
  border-radius: 10px;
  ;
  box-shadow: 0 18px 45px rgba(20, 51, 92, 0.08);
  padding: 10px;
  margin-bottom: 10px;
}

.card-section h2 {
  margin: 0 0 0.7rem;
  font-size: 1.2rem;
  color: #14335c;
}

.stack-form {
  display: grid;
  gap: 0.6rem;
}

.field-stack {
  display: grid;
  gap: 0.25rem;
}

.section-intro {
  margin-bottom: 1rem;
}

.page-title {
  margin: 0 0 0.75rem;
  color: #14335c;
  font-size: clamp(1.55rem, 2.8vw, 2.25rem);
  line-height: 1.15;
}

.notes-panel {
  margin: 0 0 1rem;
  padding: 0.95rem 1rem;
  border: 1px solid #d8e2f0;
  border-radius: 10px;
  ;
  background: linear-gradient(180deg, #f8fbff 0%, #f1f6fc 100%);
  box-shadow: 0 8px 18px rgba(15, 44, 82, 0.05);
}

.notes-title {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #35506c;
}

.notes-list {
  margin: 0;
  padding-left: 1.15rem;
  color: #4b647d;
  line-height: 1.65;
}

.notes-list li+li {
  margin-top: 0.28rem;
}

.note-accent {
  color: #c62828;
  font-weight: 700;
}

.note-symbol {
  font-weight: 700;
  color: #14335c;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.72fr) minmax(0, 1.28fr);
  gap: 1.5rem;
  align-items: stretch;
}

.panel-card {
  background: linear-gradient(180deg, #ffffff 0%, #f4f8fe 100%);
  border: 1px solid #d6e0ec;
  border-radius: 10px;
  ;
  box-shadow: 0 18px 45px rgba(20, 51, 92, 0.08);
  overflow: hidden;
}

.panel-hero {
  padding: 2rem;
  background:
    radial-gradient(circle at top right, rgba(54, 112, 191, 0.16), transparent 30%),
    linear-gradient(145deg, #12345d 0%, #1f5a9b 100%);
  color: #f7fbff;
}

.panel-kicker {
  display: inline-block;
  margin-bottom: 0.9rem;
  padding: 0.3rem 0.65rem;
  border-radius: 10px;
  ;
  background: rgba(255, 255, 255, 0.14);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-hero h1 {
  margin: 0;
  font-size: clamp(2rem, 3.5vw, 2.9rem);
  line-height: 1.05;
  color: #ffffff;
}

.panel-hero p {
  margin: 1rem 0 0;
  font-size: 1.02rem;
  line-height: 1.7;
  color: rgba(247, 251, 255, 0.92);
}

.hero-note {
  margin-top: 1.2rem;
  font-size: 0.88rem;
  line-height: 1.6;
}

.card-intro {
  margin: 0.35rem 0 0.9rem;
  color: #4f6277;
  font-size: 0.85rem;
  line-height: 1.4;
}

.feature-list {
  margin: 1.4rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.75rem;
}

.feature-list li {
  padding: 0.85rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  line-height: 1.5;
}

.panel-body {
  padding: 1.2rem;
}

.panel-stack {
  display: grid;
  gap: 1.1rem;
}

.resolve-layout {
  display: grid;
  gap: 0.5rem;
}

.resolve-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: flex-end;
}

.resolve-input-row .field-stack {
  margin: 0;
}

.secondary-button {
  min-height: 2.4rem;
  padding: 0.56rem 1rem;
  border: 1px solid #bfd0e1;
  background: #ffffff;
  color: #26486b;
  border-radius: 10px;
  ;
  font-weight: 700;
  cursor: pointer;
  box-shadow: none;
  align-self: end;
}

.secondary-button:hover {
  background: #f5f9fd;
  border-color: #9eb8d4;
  transform: translateY(-1px);
}

.button-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.2rem;
  margin-bottom: 0.6rem;
}

.inline-fieldset {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.radio-stack {
  display: grid;
  gap: 0.35rem;
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.radio-row input {
  width: auto;
  min-height: auto;
  padding: 0;
  margin: 0;
}

.radio-row label {
  margin: 0;
  cursor: pointer;
}

.toolbar-card {
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}

.toolbar-form {
  display: grid;
  grid-template-columns: minmax(170px, 220px) minmax(260px, 1fr);
  gap: 0.75rem 1rem;
  align-items: end;
}

.toolbar-radio {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 1rem;
  padding: 0.45rem 0.6rem;
  min-height: 2.1rem;
  border: 1px solid #bfd0e1;
  border-radius: 10px;
  background: #ffffff;
}

.toolbar-radio .radio-row {
  margin: 0;
}

.table-wrap {
  margin: 1rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrap .dataTables_wrapper {
  min-width: 0;
}

.table-wrap table.dataTable {
  width: auto !important;
  min-width: 100%;
}

/* Shared table presentation used by results views and generated summary tables */
.table-wrap table,
.results-block table,
#output table,
.swift-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid #c7d6e6;
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
  margin: 1rem 0;
}

.table-wrap table thead th,
.results-block table thead th,
#output table thead th,
.swift-table thead th {
  padding: 0.55rem 0.65rem;
  background: #eaf1f8;
  color: #14335c;
  font-size: 0.86rem;
  font-weight: 700;
  border-bottom: 1px solid #c7d6e6;
  text-align: left;
}

.table-wrap table tbody td,
.results-block table tbody td,
#output table tbody td,
.swift-table tbody td {
  padding: 0.45rem 0.65rem;
  font-size: 0.88rem;
  color: #234568;
  border-bottom: 1px solid #dbe6f2;
}

.table-wrap table tbody tr:last-child td,
.results-block table tbody tr:last-child td,
#output table tbody tr:last-child td,
.swift-table tbody tr:last-child td {
  border-bottom: 0;
}

.table-wrap table tbody tr:hover,
.results-block table tbody tr:hover,
#output table tbody tr:hover,
.swift-table tbody tr:hover {
  background: #f7fbff;
}

.table-wrap table a,
.results-block table a,
#output table a,
.swift-table a {
  color: #1d4f8f;
  text-decoration: none;
}

.table-wrap table a:hover,
.results-block table a:hover,
#output table a:hover,
.swift-table a:hover {
  color: #123f72;
  text-decoration: underline;
}

.loading-state {
  padding: 2rem;
  text-align: center;
  color: #7a8fa5;
  border: 1px dashed #c8d5e6;
  border-radius: 10px;
  ;
  background: linear-gradient(180deg, #fbfdff 0%, #f3f8fd 100%);
}

.inline-error {
  margin: 0.75rem 0;
}

.status-table td:first-child {
  font-weight: 600;
  color: #14335c;
  background: #f4f8fe;
  width: 50%;
}

.results-block {
  margin-top: 1rem;
}

.status-message {
  min-height: 1.25rem;
  margin-top: 0;
}

/* ========== RESPONSIVE ADJUSTMENTS ========== */

@media (max-width: 768px) {
  fieldset {
    padding: 1rem 0.9rem 0.6rem;
    margin: 0.8rem 0;
  }

  table thead th,
  table tbody td {
    padding: 0.6rem 0.75rem;
  }

  input:not([type='checkbox']):not([type='radio']):not([type='submit']):not([type='button']):not([type='date']):not([type='time']):not([type='datetime-local']):not([type='month']):not([type='week']),
  textarea,
  select {
    min-height: 2.25rem;
    padding: 0.55rem 0.7rem;
    font-size: 1rem;
    /* ≥16px prevents iOS auto-zoom on focus */
  }

  button:not(.collapsible):not(.nav-dropbtn):not(.topbar-hamburger):not(.topbar-session-account-btn):not(.tab-button):not(.too-account-copy-btn),
  input[type='submit'],
  input[type='button'],
  input[type='reset'],
  .formbutton {
    width: 100%;
    margin-right: 0;
    margin-bottom: 0.6rem;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .panel-grid,
  .resolve-input-row,
  .toolbar-form {
    grid-template-columns: 1fr;
  }

  .panel-hero {
    padding: 1.35rem;
  }

  .panel-body {
    padding: 0.95rem;
  }

  .secondary-button {
    width: 100%;
  }

  label {
    font-size: 0.9rem;
  }
}

@media (max-width: 480px) {
  fieldset {
    padding: 0.9rem 0.8rem 0.5rem;
    margin: 0.6rem 0;
  }

  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    font-size: 0.8rem;
  }

  table thead th,
  table tbody td,
  table tfoot td,
  table tfoot th {
    padding: 0.5rem 0.6rem;
  }

  input:not([type='checkbox']):not([type='radio']):not([type='submit']):not([type='button']):not([type='date']):not([type='time']):not([type='datetime-local']):not([type='month']):not([type='week']),
  textarea,
  select {
    min-height: 2.15rem;
    padding: 0.5rem 0.6rem;
    font-size: 1rem;
    /* ≥16px prevents iOS auto-zoom on focus */
  }

  textarea {
    min-height: 6rem;
  }

  button:not(.collapsible):not(.topbar-hamburger),
  input[type='submit'],
  input[type='button'],
  input[type='reset'],
  .formbutton {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
  }

  legend {
    font-size: 0.9rem;
    padding: 0.15rem 0.5rem;
  }
}