/*
 * PPDO MIS UI Separation — Phase 2
 * Shared cards, tables, forms, buttons, toolbars, empty states, and modal surfaces.
 *
 * These rules are intentionally presentation-only. They do not alter form
 * actions, permissions, database operations, uploads, or module routing.
 */

/* Shared content surfaces */
.main .card:not(.stat),
.main .ppdo-panel,
.main .panel,
.main .module-panel {
  border-color: var(--mis-color-line);
  border-radius: var(--mis-radius-lg);
}

.main .section-title,
.main .card-head,
.main .panel-head,
.main .module-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--mis-space-3);
  flex-wrap: wrap;
}

.main .section-title > div,
.main .card-head > div,
.main .panel-head > div,
.main .module-header > div {
  min-width: 0;
}

.main .section-title h2,
.main .section-title h3,
.main .card-head h2,
.main .card-head h3,
.main .panel-head h2,
.main .panel-head h3,
.main .module-header h2,
.main .module-header h3 {
  color: var(--mis-color-text);
  line-height: 1.2;
}

.main .section-title p,
.main .card-head p,
.main .panel-head p,
.main .module-header p {
  color: var(--mis-color-muted);
  line-height: 1.45;
}

/* Toolbars and action groups */
.main :where(.toolbar,.actions,.btn-row,.quick-actions,.ppdo-quick-actions,.modal-actions) {
  display: flex;
  align-items: center;
  gap: var(--mis-space-2);
  flex-wrap: wrap;
}

.main :where(.toolbar,.actions,.btn-row,.quick-actions,.ppdo-quick-actions,.modal-actions) > :where(.btn,button,a) {
  max-width: 100%;
}

/* Buttons — shared shape only; semantic colors remain with existing classes. */
.main .btn,
body .modal-overlay .btn,
body .modal-card .btn {
  min-height: 40px;
  border-radius: var(--mis-radius-md);
  padding: 9px 14px;
  gap: 7px;
  font-weight: 800;
  line-height: 1.15;
  text-decoration: none;
  transition: transform .14s ease, box-shadow .14s ease, filter .14s ease;
}

.main .btn:hover,
body .modal-overlay .btn:hover,
body .modal-card .btn:hover {
  transform: translateY(-1px);
}

.main .btn:focus-visible,
body .modal-overlay .btn:focus-visible,
body .modal-card .btn:focus-visible {
  outline: 3px solid rgba(8,125,184,.24);
  outline-offset: 2px;
}

/* Forms */
.main .form-grid,
body .modal-overlay .form-grid,
body .modal-card .form-grid {
  align-items: start;
}

.main .field,
body .modal-overlay .field,
body .modal-card .field {
  min-width: 0;
}

.main .field > label,
body .modal-overlay .field > label,
body .modal-card .field > label {
  display: block;
  margin-bottom: 6px;
  color: #3d5369;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .025em;
}

.main .field :where(input:not([type="checkbox"]):not([type="radio"]),select,textarea),
body .modal-overlay .field :where(input:not([type="checkbox"]):not([type="radio"]),select,textarea),
body .modal-card .field :where(input:not([type="checkbox"]):not([type="radio"]),select,textarea) {
  width: 100%;
  max-width: 100%;
  border: 1px solid #cbd9e6;
  border-radius: var(--mis-radius-md);
  background: #fff;
  color: var(--mis-color-text);
  padding: 10px 12px;
  line-height: 1.4;
  transition: border-color .14s ease, box-shadow .14s ease;
}

.main .field :where(input:not([type="checkbox"]):not([type="radio"]),select,textarea):focus,
body .modal-overlay .field :where(input:not([type="checkbox"]):not([type="radio"]),select,textarea):focus,
body .modal-card .field :where(input:not([type="checkbox"]):not([type="radio"]),select,textarea):focus {
  border-color: var(--mis-color-primary);
  box-shadow: 0 0 0 3px rgba(8,125,184,.13);
  outline: none;
}

.main .field small,
.main .field .help,
body .modal-overlay .field small,
body .modal-card .field small {
  display: block;
  margin-top: 5px;
  color: var(--mis-color-muted);
  line-height: 1.4;
}

/* Tables */
.main .table-wrap,
.main .responsive-table,
.main .table-responsive,
.main .data-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--mis-color-line);
  border-radius: var(--mis-radius-lg);
  background: var(--mis-color-surface);
  box-shadow: var(--mis-shadow-sm);
}

.main .table-wrap > table,
.main .responsive-table > table,
.main .table-responsive > table,
.main .data-table-wrap > table,
.main table.mis-ui-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.main table.mis-ui-table th,
.main table.mis-ui-table td,
.main .table-wrap th,
.main .table-wrap td {
  padding: 11px 12px;
  border-bottom: 1px solid #e7eef5;
  vertical-align: top;
}

.main table.mis-ui-table thead th,
.main .table-wrap thead th {
  background: #f4f8fb;
  color: #40566b;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .045em;
  text-transform: uppercase;
  white-space: nowrap;
}

.main table.mis-ui-table tbody tr,
.main .table-wrap tbody tr {
  transition: background-color .14s ease;
}

.main table.mis-ui-table tbody tr:hover,
.main .table-wrap tbody tr:hover {
  background: #f8fbfd;
}

.main table.mis-ui-table tbody tr:last-child td,
.main .table-wrap tbody tr:last-child td {
  border-bottom: 0;
}

/* Empty, status, and message surfaces */
.main .empty,
.main .empty-state,
.main .no-records {
  border: 1px dashed #c8d6e3;
  border-radius: var(--mis-radius-md);
  background: #f8fbfd;
  color: var(--mis-color-muted);
  padding: 16px;
  line-height: 1.5;
}

.main :where(.alert,.flash,.message,.notice) {
  border-radius: var(--mis-radius-md);
}

/* Modal surface styling only. Existing modal positioning and open/close logic
   remain controlled by the legacy modal functions and safety layers. */
body .modal-overlay > .modal-card,
body .modal-overlay > .modal-content,
body .modal-card.mis-ui-modal {
  border: 1px solid var(--mis-color-line);
  border-radius: var(--mis-radius-lg);
  box-shadow: var(--mis-shadow-lg);
}

body .modal-card :where(h2,h3),
body .modal-content :where(h2,h3) {
  color: var(--mis-color-text);
  line-height: 1.2;
}

body .modal-card .toolbar,
body .modal-content .toolbar,
body .modal-card .modal-actions,
body .modal-content .modal-actions {
  display: flex;
  align-items: center;
  gap: var(--mis-space-2);
  flex-wrap: wrap;
}

@media (max-width: 760px) {
  .main .section-title,
  .main .card-head,
  .main .panel-head,
  .main .module-header {
    align-items: stretch;
  }

  .main :where(.toolbar,.actions,.btn-row,.quick-actions,.ppdo-quick-actions,.modal-actions) > :where(.btn,button,a) {
    flex: 1 1 150px;
    justify-content: center;
  }

  .main .form-grid,
  body .modal-overlay .form-grid,
  body .modal-card .form-grid {
    grid-template-columns: 1fr !important;
  }

  .main .field.full,
  body .modal-overlay .field.full,
  body .modal-card .field.full {
    grid-column: 1 !important;
  }
}

@media print {
  .main .table-wrap,
  .main .responsive-table,
  .main .table-responsive,
  .main .data-table-wrap {
    overflow: visible;
    border: 0;
    box-shadow: none;
  }

  .main table.mis-ui-table thead {
    display: table-header-group;
  }
}
