/* =============================================================================
   Theater TD — components.css
   Reusable UI components
   ============================================================================= */

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.5;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border: 1px solid transparent;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); text-decoration: none; }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-interactive); color: var(--text-primary); text-decoration: none; }

.btn-danger {
  background: var(--error);
  color: #fff;
  border: 1px solid transparent;
}
.btn-danger:hover:not(:disabled) { background: #dc2626; text-decoration: none; }

.btn-success {
  background: var(--success);
  color: #fff;
  border: 1px solid transparent;
}
.btn-success:hover:not(:disabled) { background: #16a34a; text-decoration: none; }

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
}
.btn-sm svg { width: 14px; height: 14px; }

.btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
}

/* Icon-only button */
.btn-icon {
  padding: var(--space-2);
  border-radius: var(--radius-sm);
}

/* --- Cards --- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.card-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
}

.card-body {
  padding: var(--space-6);
}

.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

.card-clickable {
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.card-clickable:hover {
  border-color: var(--border-focus);
  box-shadow: var(--shadow);
  text-decoration: none;
}

/* --- Stat Cards (dashboard) --- */
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.stat-value {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.stat-sub {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* Tier badges */
.badge-observer { background: rgba(107,114,128,0.2); color: var(--tier-observer); }
.badge-operator { background: rgba(59,130,246,0.2); color: var(--tier-operator); }
.badge-lead     { background: rgba(139,92,246,0.2); color: var(--tier-lead); }
.badge-td       { background: rgba(245,158,11,0.2); color: var(--tier-td); }
.badge-auditor  { background: rgba(56,189,248,0.2); color: var(--info); }

/* System badges */
.badge-eos { background: var(--eos-muted); color: var(--eos-color); }
.badge-dm7 { background: var(--dm7-muted); color: var(--dm7-color); }

/* Status badges */
.badge-success { background: var(--success-muted); color: var(--success); }
.badge-warning { background: var(--warning-muted); color: var(--warning); }
.badge-error   { background: var(--error-muted); color: var(--error); }
.badge-info    { background: var(--info-muted); color: var(--info); }
.badge-neutral { background: var(--bg-elevated); color: var(--text-secondary); }

/* Show readiness badges */
.badge-not-cleared { background: rgba(107,114,128,0.2); color: var(--readiness-not-cleared); }
.badge-assisted    { background: rgba(245,158,11,0.15); color: var(--readiness-assisted); }
.badge-solo        { background: rgba(34,197,94,0.15); color: var(--readiness-solo); }

/* --- Tables --- */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}

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

.table tbody tr {
  transition: background var(--transition);
}
.table tbody tr:hover { background: var(--bg-interactive); }

.table-muted td { color: var(--text-secondary); }

/* --- Forms --- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.form-label-optional {
  font-weight: 400;
  color: var(--text-muted);
  font-size: var(--text-xs);
  margin-left: var(--space-2);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  background: var(--bg-interactive);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  color: var(--text-primary);
  font-size: var(--text-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-input::placeholder { color: var(--text-muted); }
.form-textarea::placeholder { color: var(--text-muted); }

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(74, 111, 165, 0.25);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%238a9ab5' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.form-select option {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.form-textarea { min-height: 100px; resize: vertical; }

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--error);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
  margin-top: var(--space-6);
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: var(--space-4);
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: 600;
}

.modal-close {
  color: var(--text-muted);
  padding: var(--space-1);
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

/* --- Toasts --- */
#toast-container {
  position: fixed;
  top: var(--space-5);
  right: var(--space-5);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-width: 360px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: toastIn 0.25s ease;
  border-left: 4px solid var(--border-default);
}

.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--error); }
.toast-warning { border-left-color: var(--warning); }
.toast-info    { border-left-color: var(--info); }

.toast-icon { flex-shrink: 0; margin-top: 2px; }
.toast-success .toast-icon { color: var(--success); }
.toast-error   .toast-icon { color: var(--error); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info    .toast-icon { color: var(--info); }

.toast-content { flex: 1; min-width: 0; }
.toast-title { font-size: var(--text-sm); font-weight: 600; }
.toast-message { font-size: var(--text-xs); color: var(--text-secondary); margin-top: 2px; }

.toast-dismiss { flex-shrink: 0; color: var(--text-muted); cursor: pointer; }
.toast-dismiss:hover { color: var(--text-primary); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(20px); }
}

/* --- Progress Bar --- */
.progress-bar-container {
  width: 100%;
  height: 6px;
  background: var(--bg-interactive);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

.progress-bar-fill.eos { background: var(--eos-color); }
.progress-bar-fill.dm7 { background: var(--dm7-color); }
.progress-bar-fill.success { background: var(--success); }

/* Progress with label */
.progress-with-label {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.progress-label-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* --- Callout / Alert Boxes --- */
.callout {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  line-height: 1.6;
}
.callout svg { flex-shrink: 0; margin-top: 2px; width: 18px; height: 18px; }

.callout-info    { background: var(--info-muted);    color: var(--text-primary); border-left: 3px solid var(--info); }
.callout-warning { background: var(--warning-muted); color: var(--text-primary); border-left: 3px solid var(--warning); }
.callout-error   { background: var(--error-muted);   color: var(--text-primary); border-left: 3px solid var(--error); }
.callout-success { background: var(--success-muted); color: var(--text-primary); border-left: 3px solid var(--success); }

.callout-info    svg { color: var(--info); }
.callout-warning svg { color: var(--warning); }
.callout-error   svg { color: var(--error); }
.callout-success svg { color: var(--success); }

/* --- Chip / Tag --- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-2);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}

/* --- Tabs --- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-6);
  overflow-x: auto;
}

.tab-btn {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* --- Section Header --- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.section-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}

/* --- Grid Layouts --- */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }

@media (max-width: 900px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* --- Divider --- */
.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-6) 0;
}

/* --- Inline Icon+Text --- */
.icon-text {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.icon-text svg { flex-shrink: 0; }

/* --- Search Input --- */
.search-input-wrapper {
  position: relative;
  width: 100%;
  max-width: 320px;
}
.search-input-wrapper svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}
.search-input {
  width: 100%;
  padding-left: 34px;
  background: var(--bg-interactive);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  padding-top: var(--space-2);
  padding-bottom: var(--space-2);
  padding-right: var(--space-3);
  color: var(--text-primary);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--transition);
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--border-focus); }

/* --- Checkbox --- */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-primary);
}
.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* --- Radio Group --- */
.radio-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.radio-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-primary);
}
.radio-label input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* --- Copy to clipboard --- */
.copyable {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-interactive);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
.copyable span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.copy-btn {
  flex-shrink: 0;
  color: var(--text-muted);
  padding: 2px;
}
.copy-btn:hover { color: var(--accent); }
