@layer reset, base, components, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; margin: 0; }
  html, body { height: 100%; }
  body { margin: 0; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
  img, svg { display: block; max-width: 100%; }
  input, button, textarea, select { font: inherit; }
  h1, h2, h3, h4, h5, h6 { margin: 0; }
  p { margin: 0; }
  a { color: inherit; text-decoration: none; }
}

@layer base {
  :root {
    --background: #f8fafc;
    --foreground: #171717;
    --card: #ffffff;
    --card-foreground: #171717;
    --popover: #ffffff;
    --popover-foreground: #171717;
    --primary: #2563eb;
    --primary-foreground: #ffffff;
    --secondary: rgba(0, 0, 0, 0.04);
    --secondary-foreground: #171717;
    --muted: rgba(0, 0, 0, 0.04);
    --muted-foreground: #737373;
    --accent: rgba(0, 0, 0, 0.04);
    --accent-foreground: #171717;
    --destructive: #ef4444;
    --destructive-foreground: #dc2626;
    --success: #10b981;
    --success-foreground: #059669;
    --warning: #f59e0b;
    --warning-foreground: #d97706;
    --info: #3b82f6;
    --info-foreground: #2563eb;
    --border: rgba(0, 0, 0, 0.08);
    --input: rgba(0, 0, 0, 0.10);
    --ring: #a3a3a3;
    --radius: 0.625rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-heading: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  }

  body {
    font-family: var(--font-sans);
    background: var(--background);
    color: var(--foreground);
    line-height: 1.5;
    font-size: 0.9375rem;
    letter-spacing: -0.01em;
  }

  .container {
    width: min(1120px, 100% - 32px);
    margin-inline: auto;
  }

  .content {
    padding-block: 24px 64px;
  }

  h1 {
    font-family: var(--font-heading);
    font-size: 1.875rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.025em;
    color: var(--foreground);
  }

  h2 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.02em;
    color: var(--foreground);
  }

  p {
    color: var(--muted-foreground);
  }
}

@layer components {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border-bottom: 1px solid var(--border);
  }

  .topbar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-block: 12px;
    height: 56px;
  }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -0.02em;
    color: var(--foreground);
  }

  .brand__logo {
    height: 22px;
    width: auto;
    display: inline-block;
  }

  .brand__muted {
    color: var(--muted-foreground);
    font-weight: 400;
  }

  .nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .nav__link {
    padding: 6px 12px;
    border-radius: var(--radius);
    color: var(--muted-foreground);
    font-size: 0.875rem;
    font-weight: 500;
    transition: color 0.15s ease, background-color 0.15s ease;
  }

  .nav__link:hover {
    color: var(--foreground);
    background: var(--secondary);
  }

  .nav__link--danger:hover {
    color: var(--destructive);
    background: rgba(239, 68, 68, 0.08);
  }

  .nav__user {
    padding: 4px 12px;
    border-radius: 9999px;
    background: var(--secondary);
    color: var(--foreground);
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1px solid var(--border);
  }

  .hero {
    display: grid;
    gap: 16px;
    padding: 24px;
    border-radius: var(--radius-xl);
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
  }

  .hero__kicker {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    width: fit-content;
    padding: 4px 12px;
    border-radius: 9999px;
    background: color-mix(in srgb, var(--primary) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 16%, transparent);
    color: var(--primary);
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0.01em;
  }

  .hero__grid {
    display: grid;
    gap: 16px;
  }

  .hero__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--background);
    color: var(--foreground);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25rem;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    user-select: none;
    box-shadow: var(--shadow-xs);
  }

  .btn:hover {
    background: var(--secondary);
    border-color: rgba(0, 0, 0, 0.12);
  }

  .btn:active {
    transform: translateY(1px);
  }

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

  .btn:disabled {
    opacity: 0.5;
    pointer-events: none;
  }

  .btn--primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-foreground);
    box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  }

  .btn--primary:hover {
    background: color-mix(in srgb, var(--primary) 90%, #000);
    border-color: color-mix(in srgb, var(--primary) 90%, #000);
  }

  .btn--danger {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--destructive);
    box-shadow: none;
  }

  .btn--danger:hover {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.3);
  }

  .btn--block {
    width: 100%;
  }

  .btn--disabled,
  .btn[aria-disabled="true"] {
    pointer-events: none;
    opacity: 0.5;
  }

  .grid {
    display: grid;
    gap: 16px;
  }

  .card {
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    background: var(--card);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
    transition: box-shadow 0.2s ease;
  }

  .card:hover {
    box-shadow: var(--shadow-sm);
  }

  .card__body {
    padding: 20px;
  }

  .card__title {
    font-weight: 600;
    font-size: 0.9375rem;
    letter-spacing: -0.01em;
    margin: 0 0 8px;
    color: var(--foreground);
  }

  .card__title a {
    color: inherit;
    text-decoration: none;
    transition: color 0.15s ease;
  }

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

  .card__meta {
    color: var(--muted-foreground);
    font-size: 0.875rem;
    line-height: 1.5;
  }

  .card__thumb-wrap {
    position: relative;
    overflow: hidden;
    border-radius: calc(var(--radius-xl) - 4px);
  }

  .card__thumb {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: calc(var(--radius-xl) - 4px);
    border: 1px solid var(--border);
    transition: transform 0.3s ease;
  }

  .card:hover .card__thumb {
    transform: scale(1.02);
  }

  .card__thumb-pill {
    position: absolute;
    top: 12px;
    right: 12px;
  }

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

  .field {
    display: grid;
    gap: 6px;
  }

  .label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--foreground);
    line-height: 1.25rem;
  }

  .input,
  .select,
  .textarea {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--input);
    background: var(--background);
    color: var(--foreground);
    font-size: 0.875rem;
    line-height: 1.25rem;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
  }

  .input:focus,
  .select:focus,
  .textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent);
  }

  .input::placeholder,
  .textarea::placeholder {
    color: var(--muted-foreground);
  }

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

  .row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
  }

  .switch {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
  }

  .switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
  }

  .switch__track {
    width: 40px;
    height: 22px;
    border-radius: 9999px;
    background: rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(0, 0, 0, 0.08);
    position: relative;
    flex: 0 0 auto;
    transition: background 0.2s ease, border-color 0.2s ease;
  }

  .switch__track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 9999px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: var(--shadow-xs);
    transition: transform 0.2s ease;
  }

  .switch input:checked + .switch__track {
    background: var(--primary);
    border-color: var(--primary);
  }

  .switch input:checked + .switch__track::after {
    transform: translateX(18px);
    border-color: transparent;
  }

  .switch input:focus-visible + .switch__track {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent);
  }

  .hp {
    position: absolute;
    left: -10000px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
  }

  .muted {
    color: var(--muted-foreground);
    font-size: 0.875rem;
  }

  .msg {
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--secondary);
    color: var(--foreground);
    font-size: 0.875rem;
    line-height: 1.5;
  }

  .msg--error {
    border-color: rgba(239, 68, 68, 0.2);
    background: rgba(239, 68, 68, 0.05);
    color: var(--destructive);
  }

  .msg--ok {
    border-color: rgba(16, 185, 129, 0.2);
    background: rgba(16, 185, 129, 0.05);
    color: var(--success-foreground);
  }

  .table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
  }

  .table th,
  .table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    text-align: left;
  }

  .table th {
    color: var(--muted-foreground);
    font-weight: 500;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--secondary);
  }

  .table td {
    color: var(--foreground);
  }

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

  .table tr:hover td {
    background: var(--secondary);
  }

  .pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 9999px;
    border: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.5;
    letter-spacing: 0.01em;
  }

  .pill--ok {
    background: rgba(16, 185, 129, 0.08);
    border-color: rgba(16, 185, 129, 0.2);
    color: var(--success-foreground);
  }

  .pill--warn {
    background: rgba(239, 68, 68, 0.06);
    border-color: rgba(239, 68, 68, 0.15);
    color: var(--destructive);
  }

  .images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
  }

  .images-grid__item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--background);
  }

  .images-grid__img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    display: block;
  }

  .images-grid__actions {
    display: flex;
    gap: 8px;
    padding: 8px;
    justify-content: space-between;
    flex-wrap: wrap;
    align-items: center;
  }

  .tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    padding: 4px;
    background: var(--secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
  }

  .tab {
    border: none;
    background: transparent;
    padding: 6px 14px;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--muted-foreground);
    transition: all 0.15s ease;
  }

  .tab:hover {
    color: var(--foreground);
    background: rgba(0, 0, 0, 0.02);
  }

  .tab--active {
    color: var(--foreground);
    background: var(--background);
    box-shadow: var(--shadow-xs);
  }

  .tab-panel {
    display: none;
  }

  .tab-panel--active {
    display: block;
  }

  .modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 50;
    padding: 16px;
  }

  .modal--open {
    display: flex;
  }

  .modal__dialog {
    width: min(920px, 100%);
    max-height: min(86vh, 900px);
    overflow: auto;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    background: var(--background);
    box-shadow: var(--shadow-lg);
  }

  .modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--background);
    z-index: 1;
  }

  .modal__title {
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -0.01em;
  }

  .modal__body {
    padding: 20px;
  }

  body.modal-open {
    overflow: hidden;
  }

  .wysiwyg {
    display: grid;
    gap: 12px;
  }

  .wysiwyg__toolbar {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    padding: 4px;
    background: var(--secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
  }

  .wysiwyg__editor {
    min-height: 260px;
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--input);
    background: var(--background);
    outline: none;
    font-size: 0.9375rem;
    line-height: 1.6;
  }

  .wysiwyg__editor:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent);
  }

  .ref-table-wrap .col-competitor {
    display: none;
  }

  .ref-table-wrap.show-competitor .col-competitor {
    display: table-cell;
  }

  .carousel {
    display: grid;
    gap: 12px;
  }

  .carousel__track {
    display: flex;
    gap: 12px;
    overflow: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    padding-bottom: 8px;
  }

  .carousel__img {
    flex: 0 0 100%;
    max-height: 400px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    scroll-snap-align: start;
    background: var(--secondary);
  }

  .carousel__controls {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .carousel__dots {
    display: flex;
    gap: 6px;
    justify-content: center;
    padding: 8px 0;
  }

  .carousel__dot {
    width: 6px;
    height: 6px;
    border-radius: 9999px;
    border: none;
    background: rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
    cursor: pointer;
  }

  .carousel__dot[aria-current="true"] {
    background: var(--primary);
    width: 20px;
  }

  .cart-item {
    display: grid;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card);
  }

  .cart-item__main {
    display: grid;
    gap: 4px;
  }

  .cart-item__title {
    font-weight: 600;
    font-size: 0.9375rem;
  }

  .cart-item__meta {
    color: var(--muted-foreground);
    font-size: 0.875rem;
  }

  .cart-item__actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }

  .cart-qty {
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }

  .cart-qty__value {
    min-width: 36px;
    text-align: center;
    padding: 6px 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--secondary);
    font-size: 0.875rem;
    font-weight: 500;
  }

  .cart-fab {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 45;
    width: 56px;
    height: 56px;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-foreground);
    background: var(--primary);
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.3), 0 2px 8px rgba(0, 0, 0, 0.1);
    border: none;
    transition: all 0.2s ease;
    animation: cart-fab-sway 5.5s ease-in-out infinite;
  }

  @keyframes cart-fab-sway {
    0%, 72%, 100% { transform: translateX(0) rotate(0deg); }
    76% { transform: translateX(-3px) rotate(-9deg); }
    80% { transform: translateX(4px) rotate(9deg); }
    84% { transform: translateX(-3px) rotate(-7deg); }
    88% { transform: translateX(2px) rotate(5deg); }
    92% { transform: translateX(0) rotate(0deg); }
  }

  .cart-fab:hover {
    color: var(--primary-foreground);
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(37, 99, 235, 0.35), 0 4px 12px rgba(0, 0, 0, 0.15);
    background: color-mix(in srgb, var(--primary) 90%, #000);
  }

  .cart-fab__icon {
    width: 26px;
    height: 26px;
  }

  .cart-fab__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
    color: #ffffff;
    background: var(--destructive);
    border: 2px solid var(--background);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
  }

  .footer {
    border-top: 1px solid var(--border);
    background: var(--background);
    margin-top: 48px;
  }

  .footer__inner {
    padding-block: 24px;
    display: grid;
    gap: 8px;
  }

  .footer__brand {
    font-weight: 600;
    font-size: 0.9375rem;
    letter-spacing: -0.01em;
  }

  .footer__muted {
    color: var(--muted-foreground);
    font-size: 0.875rem;
  }

  .footer__admin {
    color: var(--muted-foreground);
    font-size: 0.8125rem;
    opacity: 0.7;
    width: fit-content;
    transition: opacity 0.15s ease;
  }

  .footer__admin:hover {
    opacity: 1;
    text-decoration: underline;
  }

  @media (min-width: 768px) {
    h1 {
      font-size: 2.25rem;
    }

    .hero {
      padding: 32px;
    }

    .hero__grid {
      grid-template-columns: 1.2fr 0.8fr;
      align-items: start;
    }

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

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

  @media (min-width: 1024px) {
    .grid--3 {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
  }

  @supports not (background: color-mix(in srgb, #000 50%, #fff)) {
    .btn--primary:hover {
      filter: brightness(0.92);
    }
    .cart-fab:hover {
      filter: brightness(0.92);
    }
    .input:focus,
    .select:focus,
    .textarea:focus {
      box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
    }
    .wysiwyg__editor:focus {
      box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
    }
    .switch input:focus-visible + .switch__track {
      box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
    }
  }
}

@layer utilities {
  .spacer {
    height: 16px;
  }

  .right {
    margin-left: auto;
  }
}
