/**
 * TQC Base Styles — Reset, typography, buttons, forms, cards, badges, grid, utilities.
 * Primitives only — component and page-specific styles live in components.css and portal CSS.
 */
@import url('./variables.css');

/* --- Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-y: scroll;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--color-text);
  background-color: var(--color-bg);
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  color: var(--color-primary-hover);
}

img {
  max-width: 100%;
  height: auto;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-semibold);
  line-height: 1.3;
  margin-bottom: var(--space-3);
}

h1 { font-size: var(--font-size-2xl); }
h2 { font-size: var(--font-size-xl); }
h3 { font-size: var(--font-size-lg); }
h4 { font-size: var(--font-size-md); }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: 1.5;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--color-primary);
  color: var(--color-white);
}
.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  color: var(--color-tqc-yellow);
}

.btn--secondary {
  background: var(--color-white);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn--secondary:hover:not(:disabled) {
  background: var(--color-bg);
  color: var(--color-tqc-yellow);
}

.btn--tertiary {
  background: transparent;
  color: var(--color-text-secondary);
  border-color: var(--color-border);
  font-size: 13px;
  white-space: nowrap;
}
.btn--tertiary:hover:not(:disabled) {
  background: var(--color-bg);
  color: var(--color-tqc-yellow);
}

.btn--danger {
  background: var(--color-danger);
  color: var(--color-white);
}
.btn--danger:hover:not(:disabled) {
  background: var(--color-danger-hover);
  color: var(--color-tqc-yellow);
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-secondary);
}
.btn--ghost:hover:not(:disabled) {
  background: var(--color-bg);
  color: var(--color-tqc-yellow);
}

.btn--sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-sm);
}

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

.btn--icon {
  background: transparent;
  border: none;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn--danger-icon {
}

.btn--icon-letter {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-primary);
  line-height: 1;
}

/* --- Forms --- */
.form-group {
  margin-bottom: var(--space-4);
}

.form-group--password {
  position: relative;
}

.form-group--password .form-input {
  padding-right: 3.5rem;
}

.form-toggle-password {
  position: absolute;
  right: var(--space-3);
  bottom: 10px;
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  padding: 0;
}

.form-label {
  display: block;
  margin-bottom: var(--space-1);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  color: var(--color-text);
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.form-input::placeholder,
.form-select::placeholder,
.form-textarea::placeholder {
  color: var(--color-text-secondary);
  opacity: 1;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  background-color: var(--color-white);
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-select--default {
  color: var(--color-text-secondary);
}

/* Date input — click anywhere to open picker, calendar icon on left */
input[type="date"].form-input,
input[type="date"].list-date-filter,
input[type="date"].dispatch-filters__date {
  cursor: pointer;
  position: relative;
  padding-left: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='1.5' y='3' width='13' height='11.5' rx='1.5' stroke='%23718096' stroke-width='1.3'/%3E%3Cpath d='M1.5 6.5h13' stroke='%23718096' stroke-width='1.3'/%3E%3Cpath d='M5 1.5v3M11 1.5v3' stroke='%23718096' stroke-width='1.3' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 10px center;
  background-size: 14px;
  height: var(--toolbar-height);
  font-size: var(--font-size-sm);
}

input[type="date"]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Hide native icon, stretch click target over full input */
input[type="date"]::-webkit-calendar-picker-indicator {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Date input placeholder styling — browser shadow DOM doesn't use ::placeholder */
.form-input--date-empty::-webkit-datetime-edit {
  color: var(--color-text-secondary);
  text-transform: uppercase;
}

.form-input--date-empty::-webkit-datetime-edit-fields-wrapper {
  color: var(--color-text-secondary);
  text-transform: uppercase;
}

/* Custom searchable select dropdown */
.custom-select {
  position: relative;
  width: 100%;
}

.custom-select__input {
  cursor: pointer;
  padding-right: 3rem;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23718096' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.custom-select__input--empty {
  color: var(--color-text-secondary);
}

.custom-select--open .custom-select__input {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 5L5 1L9 5' stroke='%23718096' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.custom-select__clear {
  position: absolute;
  right: 28px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--color-border);
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}

.custom-select__clear:hover {
  background: var(--color-text-secondary);
  color: var(--color-white);
}

.custom-select__clear--visible {
  display: flex;
}

.custom-select__panel {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  max-height: 250px;
  flex-direction: column;
}

.custom-select__list {
  flex: 1;
  overflow-y: auto;
}

.custom-select__option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: none;
  border-bottom: 1px solid var(--color-border-light, #eee);
  font-size: var(--font-size-base);
  cursor: pointer;
  background: transparent;
  color: var(--color-text);
  font-weight: 400;
}

.custom-select__option:hover {
  background: var(--color-primary-light, #ebf5ff);
}

.custom-select__option--selected {
  color: var(--color-primary);
  font-weight: 600;
}

.custom-select__option--selected:hover {
  background: transparent;
}

.custom-select__option--deletable {
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-select__option-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select__option-delete {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  opacity: 0.5;
  transition: opacity 0.15s, background 0.15s;
}

.custom-select__option-delete:hover {
  opacity: 1;
  background: var(--color-danger-bg, rgba(220, 53, 69, 0.1));
}

.custom-select__create {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  border-top: 1px solid var(--color-border);
  color: var(--color-primary);
  font-weight: 600;
  font-size: var(--font-size-sm);
  cursor: pointer;
  background: var(--color-white);
  position: sticky;
  bottom: 0;
}

.custom-select__create:hover {
  background: var(--color-primary-light, #ebf5ff);
}

.custom-select__empty {
  padding: 12px;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  text-align: center;
}

.form-input--error {
  border-color: var(--color-danger);
}

.form-error {
  margin-top: var(--space-1);
  font-size: var(--font-size-xs);
  color: var(--color-danger);
}

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

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

.card__header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border-light);
}

.card__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  margin: 0;
}

.card__body {
  padding: var(--space-5);
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-full);
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.badge--success { background: var(--color-success-light); color: var(--color-success); }
.badge--warning { background: var(--color-warning-light); color: var(--color-warning-dark); }
.badge--danger  { background: var(--color-danger-light);  color: var(--color-danger); }
.badge--info    { background: var(--color-info-light);    color: var(--color-info); }

/* --- Grid --- */
.grid {
  display: grid;
  gap: var(--space-4);
}

.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }

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

/* --- Utilities --- */
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-muted   { color: var(--color-text-muted); }
.text-sm      { font-size: var(--font-size-sm); }
.text-primary { color: var(--color-primary); }
.font-medium  { font-weight: var(--font-weight-medium); }

.flex     { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2    { gap: var(--space-2); }
.gap-4    { gap: var(--space-4); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.p-4  { padding: var(--space-4); }
.p-5  { padding: var(--space-5); }

.hidden { display: none !important; }

/* --- Loader --- */
.loader {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.7);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}

.loader--active {
  display: flex;
}

.loader__spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
