/*
 * base.css — Bank ABC Portal API Sandbox
 * Reset + typography defaults + button base + form base + accessibility
 * Sesi 9 V1.1 Refactor
 *
 * Depends on: tokens.css
 * RULE: Tidak ada hardcoded hex. Semua via var(--*).
 */

/* ─── 1. GOOGLE FONTS IMPORT ────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ─── 2. RESET ──────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── 3. HTML / BODY BASE ───────────────────────────────────── */
html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--font-regular);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--surface-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

/* ─── 4. TYPOGRAPHY BASE ────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  font-weight: var(--font-semibold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl);  }
h4 { font-size: var(--text-lg);  }
h5 { font-size: var(--text-base); font-weight: var(--font-semibold); }
h6 { font-size: var(--text-sm);  font-weight: var(--font-semibold); }

p {
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  max-width: 72ch;
}

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--surface-subtle);
  border: 1px solid var(--surface-muted);
  border-radius: var(--radius-sm);
  padding: 0.125em 0.375em;
  color: var(--text-primary);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--surface-muted);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  color: var(--text-primary);
  line-height: var(--leading-relaxed);
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

hr {
  border: none;
  border-top: 1px solid var(--surface-muted);
  margin: var(--space-6) 0;
}

/* ─── 5. LINK BASE ──────────────────────────────────────────── */
a {
  color: var(--text-link);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--text-link-hover);
}

a:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ─── 6. IMAGE / SVG BASE ───────────────────────────────────── */
img,
svg {
  display: block;
  max-width: 100%;
}

img {
  height: auto;
}

svg {
  overflow: visible;
}

/* ─── 7. LIST RESET ─────────────────────────────────────────── */
ul,
ol {
  list-style: none;
}

/* ─── 8. ACCESSIBILITY — FOCUS VISIBLE GLOBAL ──────────────── */
:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ─── 9. ACCESSIBILITY — .sr-only + .skip-link ──────────────── */
.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;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-4);
  background: var(--brand-primary);
  color: var(--text-on-brand);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: var(--space-4);
  outline: 2px solid var(--brand-accent);
  outline-offset: 2px;
}

/* ─── 10. PREFERS-REDUCED-MOTION OVERRIDE ───────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ─── 11. FORM BASE ─────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
  line-height: var(--leading-snug);
}

.form-label--required::after {
  content: ' *';
  color: var(--status-danger);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--font-regular);
  color: var(--text-primary);
  background: var(--surface-card);
  border: 1px solid var(--surface-muted);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
}

.form-textarea {
  height: auto;
  min-height: 96px;
  padding: var(--space-3);
  resize: vertical;
  line-height: var(--leading-normal);
}

.form-select {
  padding-right: var(--space-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  cursor: pointer;
}

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

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

.form-input--error,
.form-select--error,
.form-textarea--error {
  border-color: var(--status-danger);
}

.form-input--error:focus,
.form-select--error:focus,
.form-textarea--error:focus {
  box-shadow: 0 0 0 3px var(--status-danger-bg);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  line-height: var(--leading-normal);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--status-danger);
  line-height: var(--leading-normal);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* ─── 12. BUTTON BASE ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 40px;
  min-width: 44px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: 1;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color var(--transition-fast),
    border-color     var(--transition-fast),
    color            var(--transition-fast),
    box-shadow       var(--transition-fast);
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

.btn:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Size variants */
.btn-sm {
  height: 32px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
}

.btn-lg {
  height: 48px;
  padding: 0 var(--space-6);
  font-size: var(--text-base);
  border-radius: var(--radius-md);
}

.btn-full {
  width: 100%;
}

/* Icon-only variant */
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
}

.btn-icon.btn-sm {
  width: 32px;
  height: 32px;
}

.btn-icon.btn-lg {
  width: 48px;
  height: 48px;
}

/* Color variants */
.btn-primary {
  background: var(--brand-primary);
  color: var(--text-on-brand);
  border-color: var(--brand-primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-primary-hover);
  border-color: var(--brand-primary-hover);
}

.btn-secondary {
  background: var(--surface-card);
  color: var(--text-primary);
  border-color: var(--surface-muted);
}

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

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

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

.btn-danger {
  background: var(--status-danger);
  color: var(--text-inverse);
  border-color: var(--status-danger);
}

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

.btn-accent {
  background: var(--brand-accent);
  color: var(--text-on-accent);
  border-color: var(--brand-accent);
  font-weight: var(--font-semibold);
}

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

/* ─── 13. BUTTON LOADING STATE ──────────────────────────────── */
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

.btn--loading {
  color: transparent;
  pointer-events: none;
}

.btn--loading::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: var(--radius-full);
  animation: btn-spin 0.6s linear infinite;
  color: var(--text-inverse);
}

.btn-secondary.btn--loading::after,
.btn-ghost.btn--loading::after {
  color: var(--text-secondary);
}

/* ─── 14. UTILITY CLASSES ───────────────────────────────────── */
.text-primary   { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-tertiary  { color: var(--text-tertiary) !important; }
.text-inverse   { color: var(--text-inverse) !important; }
.text-danger    { color: var(--status-danger) !important; }
.text-success   { color: var(--status-success) !important; }
.text-warning   { color: var(--status-warning) !important; }

.text-xs   { font-size: var(--text-xs) !important; }
.text-sm   { font-size: var(--text-sm) !important; }
.text-base { font-size: var(--text-base) !important; }
.text-lg   { font-size: var(--text-lg) !important; }
.text-xl   { font-size: var(--text-xl) !important; }
.text-2xl  { font-size: var(--text-2xl) !important; }
.text-3xl  { font-size: var(--text-3xl) !important; }

.font-regular  { font-weight: var(--font-regular) !important; }
.font-medium   { font-weight: var(--font-medium) !important; }
.font-semibold { font-weight: var(--font-semibold) !important; }
.font-bold     { font-weight: var(--font-bold) !important; }

.mono { font-family: var(--font-mono) !important; }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.uppercase { text-transform: uppercase; }
.lowercase  { text-transform: lowercase; }
.capitalize { text-transform: capitalize; }

.tracking-wide   { letter-spacing: 0.05em; }
.tracking-wider  { letter-spacing: 0.075em; }

/* ─── 15. SCROLLBAR STYLING ─────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--surface-subtle);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
  background: var(--surface-muted);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-muted) var(--surface-subtle);
}