/* PURZAA Base Layer: Typography, Controls, Forms, Hairlines, Modals, Toasts */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: clip;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--ink-primary);
  background: var(--surface-page);
  background-image: radial-gradient(
    ellipse 75% 32% at 50% -10%,
    var(--accent-soft),
    transparent 70%
  );
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.has-open-modal {
  position: fixed;
  top: var(--modal-page-offset, 0);
  inset-inline: 0;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

img,
video {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Text Helpers */
.muted,
.muted-small {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-muted);
  line-height: 1.45;
}

.eyebrow {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
}

.text-positive {
  color: var(--status-ok);
}

.text-negative {
  color: var(--status-danger);
}

.text-muted {
  color: var(--ink-muted);
}

/* Inputs & Selects */
input,
select,
textarea {
  outline: none;
  border: 1px solid var(--border-control);
  background: var(--surface-input);
  border-radius: var(--radius-sm);
  color: var(--ink-primary);
  transition: border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type='number'] {
  appearance: textfield;
}

input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
  border-color: var(--border-strong);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

select {
  appearance: none;
  padding-right: 1.9rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='7' viewBox='0 0 11 7'%3E%3Cpath d='m1 1 4.5 4.5L10 1' fill='none' stroke='%238b9bb4' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.38rem;
  min-height: 36px;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    transform 80ms var(--ease-out);
}

.btn svg {
  flex-shrink: 0;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn--sm {
  min-height: 32px;
  padding: 0.28rem 0.68rem;
  font-size: 0.78rem;
}

.btn--xs {
  min-height: 28px;
  padding: 0.18rem 0.5rem;
  font-size: 0.74rem;
}

.btn--primary {
  background: var(--accent-primary);
  color: var(--ink-on-accent);
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-primary-hover);
}

.btn--secondary {
  background: transparent;
  color: var(--ink-primary);
  border-color: var(--border-control);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--surface-subtle);
  border-color: var(--accent);
}

.btn--ghost {
  background: transparent;
  color: var(--ink-secondary);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-subtle);
  color: var(--ink-primary);
}

.btn--danger {
  background: var(--status-danger-solid);
  color: var(--ink-on-danger);
}

.btn--danger-ghost {
  background: transparent;
  color: var(--status-danger);
}

.btn--danger-ghost:hover:not(:disabled) {
  background: var(--status-danger-bg);
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.icon-btn:hover {
  background: var(--surface-subtle);
  color: var(--ink-primary);
}

.icon-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.icon-action-sm {
  width: 30px;
  min-width: 30px;
  padding: 0;
}

.step-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-control);
  background: transparent;
  color: var(--ink-primary);
  cursor: pointer;
}

.step-btn:hover {
  background: var(--surface-subtle);
  border-color: var(--accent);
}

/* Badges & Chips */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.12rem 0.44rem;
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.badge--ok {
  background: var(--status-ok-bg);
  color: var(--status-ok);
}

.badge--warn {
  background: var(--status-warn-bg);
  color: var(--status-warn);
}

.badge--danger {
  background: var(--status-danger-bg);
  color: var(--status-danger);
}

.badge--neutral {
  background: var(--surface-subtle);
  color: var(--ink-secondary);
}

.box-pill,
.compat-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.42rem;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-hairline);
  background: var(--surface-subtle);
  color: var(--ink-secondary);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.tax-chip,
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0.2rem 0.68rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-control);
  background: transparent;
  color: var(--ink-secondary);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out);
}

.tax-chip:hover,
.pill:hover {
  color: var(--ink-primary);
  background: var(--surface-subtle);
}

.tax-chip.is-active,
.pill.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Language Switcher */
.lang-switch {
  display: inline-flex;
  border: 1px solid var(--border-control);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.24rem 0.54rem;
  cursor: pointer;
}

.lang-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem 0.6rem;
}

.form-grid--nested {
  margin-top: 0.65rem;
}

.hierarchy-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-hairline);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  min-width: 0;
}

.form-field--span2 {
  grid-column: span 2;
}

.form-field label {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  min-height: 38px;
  padding: 0.4rem 0.68rem;
  font-size: 0.86rem;
}

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

.inline-new-value:not([hidden]) {
  margin-top: 0.28rem;
  border-color: var(--accent);
}

.field-hint {
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.field-hint:empty {
  display: none;
}

.input-affix-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-affix-wrapper input {
  padding-left: 1.65rem;
  padding-right: 3.3rem;
}

.input-affix {
  position: absolute;
  pointer-events: none;
  user-select: none;
}

.input-affix--prefix {
  left: 0.62rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink-secondary);
}

.input-affix--suffix {
  right: 0.4rem;
  padding: 0.1rem 0.36rem;
  border-radius: var(--radius-xs);
  background: var(--surface-subtle);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--status-danger);
  cursor: pointer;
}

.checkbox-inline input[type='checkbox'] {
  width: 16px;
  height: 16px;
  min-height: 16px;
  accent-color: var(--status-danger-solid);
}

/* Notices & Alerts */
.notice,
.auth-notice,
.guardrail-banner {
  padding: 0.58rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  line-height: 1.45;
  background: var(--surface-subtle);
  color: var(--ink-primary);
  border: 1px solid var(--border-hairline);
}

.notice--ok,
.guardrail-banner--ok,
.auth-notice--success,
.notice--success {
  background: var(--status-ok-bg);
  color: var(--status-ok);
  border-color: transparent;
}

.notice--warn,
.guardrail-banner--warn {
  background: var(--status-warn-bg);
  color: var(--status-warn);
  border-color: transparent;
}

.notice--error,
.auth-notice--error,
.guardrail-banner--danger {
  background: var(--status-danger-bg);
  color: var(--status-danger);
  border-color: transparent;
}

/* Modals */
.modal {
  padding: 0;
  border: 1px solid var(--border-control);
  border-radius: var(--radius-lg);
  background: var(--surface-elevated);
  color: var(--ink-primary);
  box-shadow: var(--shadow-overlay);
  width: min(560px, calc(100vw - 1.25rem));
  max-height: calc(100dvh - 1.5rem);
  overflow: hidden;
}

.modal--sm {
  width: min(420px, calc(100vw - 1.25rem));
}

.modal::backdrop {
  background: var(--surface-backdrop);
  backdrop-filter: blur(4px);
}

.modal__form {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 1.5rem);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-hairline);
}

.modal__header h2 {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal__body {
  padding: 0.85rem 1rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.65rem 1rem calc(0.65rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-hairline);
}

/* Empty State */
.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
}

.empty-state--compact {
  padding: 1.25rem 0.75rem;
}

.empty-state h2,
.empty-state h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
}

.empty-state p {
  margin: 0;
  max-width: 400px;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.empty-state__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

/* Toasts */
.toast-region {
  position: fixed;
  right: 0.9rem;
  bottom: 0.9rem;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-width: 340px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-md);
  background: var(--surface-toast);
  color: var(--ink-on-toast);
  border: 1px solid var(--border-control);
  font-size: 0.8rem;
  box-shadow: var(--shadow-overlay);
}

.toast__action {
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.74rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-xs);
  cursor: pointer;
}

@media (max-width: 640px) {
  .form-grid,
  .hierarchy-form-grid {
    grid-template-columns: 1fr;
  }

  .form-field--span2 {
    grid-column: span 1;
  }

  .form-field input,
  .form-field select,
  .form-field textarea {
    font-size: 16px;
    min-height: 40px;
  }

  .toast-region {
    left: 0.75rem;
    right: 0.75rem;
    bottom: 4.1rem;
    max-width: none;
  }
}

