/* =========================================================
  Shared UI Layer
   Scope:
   - Reusable shared components only
   - No global page reset overrides here
   - No sidebar/topbar structure here
   - Core tokens remain in core.css
   ========================================================= */

.ui-form {
  display: grid;
  gap: 16px;
}

/* Accessible text that remains available to assistive technology. */
.ui-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.ui-field {
  display: grid;
  gap: 8px;
  position: relative;
}

.ui-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: var(--crm-text);
  letter-spacing: .01em;
}

.ui-label::before {
  width: 3px;
  height: 12px;
  border-radius: 99px;
  content: "";
  background: linear-gradient(180deg, var(--crm-brand), var(--crm-accent));
  opacity: .72;
}

.ui-input-wrap {
  position: relative;
}

.ui-input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  color: #7c8798;
  pointer-events: none;
}

.ui-input {
  box-sizing: border-box;
  display: block;
  font-size: 16px;
  line-height: normal;
  max-width: 100%;
  width: 100%;
  min-height: var(--crm-control-height);
  padding: 0 16px;
  border-radius: var(--crm-item-radius);
  border: 1px solid var(--crm-border-strong);
  background: rgba(255,255,255,.92);
  color: var(--crm-text);
  border-color: rgba(177, 188, 205, .65);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.92), 0 5px 14px rgba(31, 42, 58, .025);
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

/* Keep native Safari/iOS form controls aligned with the shared field size. */
input.ui-input:not([type="checkbox"]):not([type="radio"]),
select.ui-input {
  height: var(--crm-control-height);
  min-width: 0;
}

select.ui-input {
  padding-right: 38px;
}

input.ui-input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}

input.ui-input[type="date"]::-webkit-date-and-time-value {
  min-height: 1.2em;
  text-align: left;
}

textarea.ui-input {
  height: auto;
  padding-block: 14px;
}

.ui-input.has-icon {
  padding-left: 42px;
}

.ui-input::placeholder {
  color: #97a0af;
}

.ui-input:hover:not(:disabled) {
  border-color: var(--crm-brand-ring);
  box-shadow: inset 0 1px 0 #fff, 0 7px 18px rgba(31, 42, 58, .045);
}

.ui-input:disabled {
  color: #8a94a5;
  background: linear-gradient(180deg, #f5f7fa, #f1f4f8);
  cursor: not-allowed;
}

.ui-input:focus {
  outline: none;
  border-color: var(--crm-brand-ring);
  box-shadow: 0 0 0 4px var(--crm-brand-ring-soft);
  background: #ffffff;
}

/* Legacy login button helpers
   Keep for backward compatibility only.
   Use .crm-btn from components/buttons.css in new UI work.
*/
.ui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--crm-control-height);
  padding: 0 18px;
  border: 0;
  border-radius: 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.ui-btn:hover {
  transform: translateY(-1px);
}

.ui-btn-primary {
  color: #ffffff;
  border-color: var(--crm-brand-dark);
  background: var(--crm-brand-gradient-deep);
  box-shadow:
    0 14px 30px var(--crm-brand-ring),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.ui-btn-primary:hover {
  box-shadow: 0 20px 38px var(--crm-focus-ring);
}

.ui-alert {
  box-sizing: border-box;
  width: 100%;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid transparent;
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.ui-alert-danger {
  background: var(--crm-danger-bg);
  border-color: var(--crm-danger-border);
  color: var(--crm-danger-text);
}

.ui-alert-success {
  background: var(--crm-success-bg);
  border-color: var(--crm-success-border);
  color: var(--crm-success);
}

.surface-card {
  position: relative;
  border-radius: var(--crm-surface-radius);
  border: 1px solid var(--crm-border);
  background: linear-gradient(150deg, var(--crm-surface), var(--crm-surface-alt));
  box-shadow: var(--crm-shadow-card),inset 0 1px 0 rgba(255,255,255,.9);
  padding: 22px;
  transition: transform var(--crm-motion-fast) var(--crm-ease),box-shadow var(--crm-motion-base) var(--crm-ease),border-color var(--crm-motion-base) ease;
}

.surface-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--crm-shadow-float),inset 0 1px 0 rgba(255,255,255,.9);
  border-color: var(--crm-brand-surface-border);
}

.surface-card--accent {
  background: var(--crm-brand-gradient-deep);
  border-color: var(--crm-brand-ring);
  color: #ffffff;
  box-shadow:
    0 26px 56px var(--crm-brand-ring),
    inset 0 1px 0 rgba(255,255,255,0.04);
}

.surface-card__label {
  display: block;
  margin-bottom: 10px;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #6e7787;
}

.surface-card--accent .surface-card__label {
  color: rgba(255,255,255,0.78);
}

.surface-card__value {
  display: block;
  font-size: clamp(27px, 3vw, 38px);
  line-height: 1.02;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--crm-text);
}

.surface-card--accent .surface-card__value {
  color: #ffffff;
}

.surface-card__meta {
  display: block;
  margin-top: 10px;
  color: #748094;
  font-size: 13px;
  line-height: 1.55;
}

.surface-card--accent .surface-card__meta {
  color: rgba(255,255,255,0.88);
}

.section-title {
  margin: 0 0 8px;
  font-size: clamp(17px,1.6vw,21px);
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--crm-text);
  text-wrap: balance;
}

.section-text {
  margin: 0;
  color: var(--crm-text-muted);
  line-height: 1.72;
  font-size: 14px;
  max-width: 74ch;
  text-wrap: pretty;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 15px;
  border-radius: 999px;
  background: var(--crm-brand-gradient-soft);
  border: 1px solid var(--crm-brand-surface-border);
  color: var(--crm-brand-text-soft);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.55);
}

.status-chip::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--crm-brand) 0%, var(--crm-brand-dark) 100%);
  box-shadow: 0 0 0 4px var(--crm-brand-ring-soft);
  flex: 0 0 auto;
}

.metric-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.metric-list__item {
  display: grid;
  gap: 5px;
  padding: 15px 16px;
  border: 1px solid rgba(229, 233, 242, 0.96);
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.86);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.metric-list__item:hover {
  transform: translateY(-1px);
  border-color: var(--crm-brand-surface-border);
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.055);
}

.metric-list__item strong {
  font-size: 14px;
  color: var(--crm-text);
}

.metric-list__item span {
  font-size: 13px;
  color: #758195;
  line-height: 1.52;
}

.progress-stack {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.progress-stack__row {
  display: grid;
  gap: 8px;
}

.progress-stack__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--crm-text);
}

.progress-stack__track {
  height: 11px;
  background: linear-gradient(180deg, #edf1f7 0%, #e8edf4 100%);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.75);
}

.progress-stack__fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--crm-brand-dark) 0%, var(--crm-brand) 72%, var(--crm-accent) 100%);
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.08);
}

.data-table-wrap {
  overflow: auto;
  margin-top: 18px;
  border-radius: var(--crm-content-radius);
  border: 1px solid var(--crm-experience-line);
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(25, 31, 44, .055);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid #eef2f7;
  font-size: 13px;
  vertical-align: middle;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: #4c5668;
  font-size: 11.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  box-shadow: inset 0 -1px rgba(255,255,255,.14);
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover td {
  background: var(--crm-brand-ring-soft);
}

.data-table tbody tr { transition: transform .16s ease, background .16s ease; }
.data-table tbody tr:hover { transform: translateY(-1px); }
.data-table tbody td:first-child { position: relative; }
.data-table tbody tr:hover td:first-child::before {
  position: absolute;
  inset: 7px auto 7px 0;
  width: 3px;
  border-radius: 0 99px 99px 0;
  content: "";
  background: var(--crm-brand);
}

@media (max-width: 700px) {
  .data-table tbody tr:hover { transform: none; }
}

.pill-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 10.8px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pill-badge--brand-soft {
  background: var(--crm-brand-soft);
  color: var(--crm-brand-text-soft);
  border: 1px solid var(--crm-brand-ring-soft);
}

.pill-badge--neutral {
  background: #eef2f7;
  color: #475569;
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.mini-stat-card {
  display: grid;
  gap: 8px;
  padding: 18px;
  border-radius: 24px;
  border: 1px solid rgba(229, 233, 242, 0.96);
  background: linear-gradient(180deg, rgba(255,255,255,0.985) 0%, rgba(251,252,255,0.985) 100%);
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.045), inset 0 1px 0 rgba(255,255,255,0.88);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.mini-stat-card:hover {
  transform: translateY(-1px);
  border-color: var(--crm-brand-surface-border);
  box-shadow: 0 22px 42px rgba(15, 23, 42, 0.06), inset 0 1px 0 rgba(255,255,255,0.88);
}

.mini-stat-card strong {
  font-size: 24px;
  font-weight: 800;
  color: var(--crm-text);
  letter-spacing: -0.03em;
}

.mini-stat-card span {
  color: #758195;
  font-size: 13px;
  line-height: 1.58;
}

@media (max-width: 700px) {
  .surface-card {
    padding: 18px;
    border-radius: 22px;
  }

  .data-table th,
  .data-table td {
    padding: 12px 13px;
  }
}
