/*
 * Design system for News Portal.
 * Single-file vanilla CSS (no build step) organized with cascade layers so
 * later layers always win over earlier ones, regardless of selector specificity.
 */

@layer reset, base, layout, components, utilities;

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

  html, body, h1, h2, h3, h4, p, figure, blockquote, dl, dd, ul, ol {
    margin: 0;
  }

  ul[class], ol[class] {
    list-style: none;
    padding: 0;
  }

  html {
    -webkit-text-size-adjust: 100%;
  }

  body {
    min-height: 100dvh;
  }

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

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

  button {
    cursor: pointer;
  }

  a {
    color: inherit;
    text-decoration: none;
  }
}

@layer base {
  :root {
    /* Color palette -- OKLCH: perceptually uniform, easy to tune lightness/chroma independently */
    --color-canvas: oklch(100% 0 0);
    --color-surface: oklch(97.5% 0.004 260);
    --color-surface-hover: oklch(95% 0.006 260);
    --color-border: oklch(90% 0.006 260);
    --color-border-strong: oklch(80% 0.008 260);

    --color-ink: oklch(24% 0.012 260);
    --color-ink-light: oklch(46% 0.014 260);
    --color-ink-faint: oklch(62% 0.012 260);
    --color-ink-inverted: oklch(100% 0 0);

    --color-accent: oklch(52% 0.19 25);
    --color-accent-hover: oklch(45% 0.19 25);
    --color-accent-light: oklch(93% 0.05 25);

    --color-positive: oklch(52% 0.13 152);
    --color-positive-light: oklch(94% 0.05 152);
    --color-negative: oklch(52% 0.19 25);
    --color-negative-light: oklch(94% 0.05 25);
    --color-warning: oklch(62% 0.15 75);
    --color-warning-light: oklch(94% 0.07 80);

    /* Spacing */
    --space-2xs: 0.25rem;
    --space-xs: 0.5rem;
    --space-sm: 0.75rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2.5rem;
    --space-2xl: 4rem;

    /* Type */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-serif: Georgia, "Times New Roman", serif;
    --text-small: 0.85rem;
    --text-normal: 1rem;
    --text-medium: 1.1rem;
    --text-large: 1.4rem;
    --text-xlarge: 2rem;

    /* Misc */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 999px;
    --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.06), 0 1px 1px oklch(0% 0 0 / 0.04);
    --shadow-md: 0 8px 24px oklch(0% 0 0 / 0.08);
    --content-width: 72rem;
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);

    --focus-ring-color: var(--color-accent);
    --focus-ring: 2px solid var(--focus-ring-color);
  }

  body {
    font-family: var(--font-sans);
    font-size: var(--text-normal);
    line-height: 1.5;
    color: var(--color-ink);
    background: var(--color-surface);
  }

  h1, h2, h3, h4 {
    line-height: 1.25;
    font-weight: 700;
    color: var(--color-ink);
  }

  h1 { font-size: var(--text-xlarge); }
  h2 { font-size: var(--text-large); margin-top: var(--space-xl); margin-bottom: var(--space-sm); }
  h3 { font-size: var(--text-medium); }

  p { color: var(--color-ink-light); }

  a {
    color: var(--color-accent);
  }

  a:hover {
    color: var(--color-accent-hover);
    text-decoration: underline;
  }

  *:focus-visible {
    outline: var(--focus-ring);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
  }
}

@layer layout {
  .container {
    max-width: var(--content-width);
    margin-inline: auto;
    padding-inline: clamp(var(--space-md), 4vw, var(--space-xl));
  }

  .page {
    padding-block: var(--space-xl);
  }

  .page--narrow {
    max-width: 42rem;
    margin-inline: auto;
  }

  .site-header {
    background: var(--color-canvas);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 30;
  }

  .site-header__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding-block: var(--space-sm);
    flex-wrap: wrap;
  }

  .site-logo {
    font-weight: 800;
    font-size: var(--text-medium);
    color: var(--color-ink);
    letter-spacing: -0.01em;
  }

  .site-logo:hover {
    color: var(--color-ink);
    text-decoration: none;
  }

  .site-logo span {
    color: var(--color-accent);
  }

  .site-nav {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    flex-wrap: wrap;
  }

  .site-nav__links {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex-wrap: wrap;
  }

  .site-nav a:not(.btn) {
    color: var(--color-ink-light);
    font-size: var(--text-small);
    font-weight: 600;
  }

  .site-nav a:not(.btn):hover {
    color: var(--color-ink);
    text-decoration: none;
  }

  .site-footer {
    border-top: 1px solid var(--color-border);
    margin-top: var(--space-2xl);
    padding-block: var(--space-xl);
    color: var(--color-ink-faint);
    font-size: var(--text-small);
  }

  .site-footer__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
  }

  .site-footer a {
    color: var(--color-ink-light);
  }
}

@layer components {
  /* Buttons */
  .btn {
    --btn-bg: var(--color-canvas);
    --btn-color: var(--color-ink);
    --btn-border: var(--color-border-strong);

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: 0.6em 1.2em;
    font-size: var(--text-small);
    font-weight: 600;
    border-radius: var(--radius-md);
    border: 1px solid var(--btn-border);
    background: var(--btn-bg);
    color: var(--btn-color);
    transition: filter 0.15s var(--ease-out-expo), background-color 0.15s var(--ease-out-expo), transform 0.1s;
    white-space: nowrap;
  }

  .btn:hover {
    text-decoration: none;
    filter: brightness(0.97);
  }

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

  .btn--primary {
    --btn-bg: var(--color-accent);
    --btn-color: var(--color-ink-inverted);
    --btn-border: var(--color-accent);
  }

  .btn--primary:hover {
    filter: brightness(1.08);
  }

  .btn--danger {
    --btn-bg: var(--color-canvas);
    --btn-color: var(--color-negative);
    --btn-border: var(--color-negative-light);
  }

  .btn--danger:hover {
    --btn-bg: var(--color-negative-light);
  }

  .btn--small {
    padding: 0.4em 0.9em;
    font-size: var(--text-small);
  }

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

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

  .auth-card {
    max-width: 26rem;
    margin-inline: auto;
  }

  .auth-card h1 {
    margin-bottom: var(--space-lg);
  }

  /* Forms */
  .field {
    margin-bottom: var(--space-md);
  }

  .field label {
    display: block;
    margin-bottom: var(--space-2xs);
    font-size: var(--text-small);
    font-weight: 600;
    color: var(--color-ink);
  }

  .field input[type="text"],
  .field input[type="email"],
  .field input[type="password"],
  .field input[type="datetime-local"],
  .field textarea,
  .field select {
    width: 100%;
    padding: 0.65em 0.85em;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    background: var(--color-canvas);
    font-size: var(--text-normal);
  }

  .field input:focus,
  .field textarea:focus,
  .field select:focus {
    outline: var(--focus-ring);
    outline-offset: 1px;
    border-color: var(--color-accent);
  }

  .field textarea {
    min-height: 10rem;
    resize: vertical;
  }

  .field--file input {
    padding: 0.4em 0;
  }

  .search-form {
    display: flex;
    gap: var(--space-xs);
  }

  .search-form input[type="search"] {
    flex: 1;
    padding: 0.6em 0.9em;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
  }

  .error-messages {
    background: var(--color-negative-light);
    border: 1px solid oklch(85% 0.1 25);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    color: var(--color-negative);
  }

  .error-messages h2 {
    font-size: var(--text-small);
    margin-bottom: var(--space-xs);
    margin-top: 0;
  }

  .error-messages ul {
    padding-left: var(--space-md);
    list-style: disc;
  }

  .error-messages li {
    font-size: var(--text-small);
  }

  /* Flash */
  .flash {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--text-small);
    font-weight: 600;
    margin-bottom: var(--space-md);
  }

  .flash--notice {
    background: var(--color-positive-light);
    color: var(--color-positive);
  }

  .flash--alert {
    background: var(--color-negative-light);
    color: var(--color-negative);
  }

  /* Badges & status pills */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
    padding: 0.25em 0.7em;
    border-radius: var(--radius-full);
    font-size: var(--text-small);
    font-weight: 600;
    background: var(--color-surface);
    color: var(--color-ink-light);
  }

  .badge--accent {
    background: var(--color-accent-light);
    color: var(--color-accent);
  }

  .badge--tag {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-ink-light);
  }

  .badge--tag:hover {
    text-decoration: none;
    border-color: var(--color-accent);
    color: var(--color-accent);
  }

  .badge--ai {
    background: var(--color-accent);
    color: var(--color-ink-inverted);
  }

  .status-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.2em 0.7em;
    border-radius: var(--radius-full);
    font-size: var(--text-small);
    font-weight: 700;
    text-transform: capitalize;
  }

  .status-pill--draft {
    background: var(--color-surface);
    color: var(--color-ink-faint);
  }

  .status-pill--scheduled {
    background: var(--color-warning-light);
    color: var(--color-warning);
  }

  .status-pill--published {
    background: var(--color-positive-light);
    color: var(--color-positive);
  }

  .status-pill--compliance-good {
    background: var(--color-positive-light);
    color: var(--color-positive);
  }

  .status-pill--compliance-warning {
    background: var(--color-warning-light);
    color: var(--color-warning);
  }

  .status-pill--compliance-bad {
    background: var(--color-negative-light);
    color: var(--color-negative);
  }

  .status-pill--compliance-pending {
    background: var(--color-surface);
    color: var(--color-ink-faint);
  }

  /* Panel note (AI review details) */
  .panel-note {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--text-small);
  }

  /* Filter chips */
  .filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-bottom: var(--space-lg);
  }

  .filter-bar a {
    padding: 0.4em 1em;
    border-radius: var(--radius-full);
    background: var(--color-canvas);
    border: 1px solid var(--color-border);
    font-size: var(--text-small);
    font-weight: 600;
    color: var(--color-ink-light);
  }

  .filter-bar a:hover {
    text-decoration: none;
    border-color: var(--color-accent);
  }

  .filter-bar a.is-active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--color-ink-inverted);
  }

  /* Article grid / cards */
  .article-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
    gap: var(--space-lg);
  }

  .article-card {
    display: flex;
    flex-direction: column;
    background: var(--color-canvas);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s var(--ease-out-expo), box-shadow 0.15s var(--ease-out-expo);
  }

  .article-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }

  .article-card__cover {
    aspect-ratio: 16 / 9;
    background: var(--color-surface);
    overflow: hidden;
  }

  .article-card__cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .article-card__cover--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-ink-faint);
    font-size: 2rem;
  }

  .article-card__body {
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    flex: 1;
  }

  .article-card__title {
    font-size: var(--text-medium);
    font-weight: 700;
    color: var(--color-ink);
  }

  .article-card__title:hover {
    text-decoration: none;
    color: var(--color-accent);
  }

  .article-card__meta {
    font-size: var(--text-small);
    color: var(--color-ink-faint);
    margin-top: auto;
    padding-top: var(--space-xs);
  }

  /* Article detail */
  .article-hero__cover {
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--color-border);
    margin-bottom: var(--space-lg);
    max-height: 28rem;
  }

  .article-hero__cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .article-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    align-items: center;
    font-size: var(--text-small);
    color: var(--color-ink-faint);
    margin-bottom: var(--space-lg);
  }

  .article-body {
    font-size: var(--text-medium);
    line-height: 1.7;
    color: var(--color-ink);
  }

  /* Comments */
  .comment-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
  }

  .comment {
    padding: var(--space-md);
    background: var(--color-canvas);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
  }

  .comment__meta {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: var(--text-small);
    color: var(--color-ink-faint);
    margin-bottom: var(--space-2xs);
  }

  .comment__author {
    font-weight: 700;
    color: var(--color-ink);
  }

  .comment-form-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
  }

  @media (max-width: 40rem) {
    .comment-form-fields {
      grid-template-columns: 1fr;
    }
  }

  .empty-state {
    padding: var(--space-xl);
    text-align: center;
    color: var(--color-ink-faint);
    background: var(--color-canvas);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-lg);
  }

  /* Ad slot placeholder — replace inner span with real AdSense unit once approved */
  .ad-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 5rem;
    margin-block: var(--space-lg);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface);
  }

  .ad-slot__label {
    font-size: var(--text-small);
    color: var(--color-ink-faint);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .admin-subnav {
    margin-bottom: var(--space-lg);
  }

  /* Generic content rows (categories list, etc.) */
  .list-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-canvas);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
  }

  .list-row + .list-row {
    margin-top: var(--space-xs);
  }

  .list-row__main {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-weight: 600;
  }

  .list-row__actions {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
  }

  /* Panel header (page title + primary action) */
  .panel-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
  }

  .panel-header h1 {
    margin-bottom: 0;
  }

  .back-link {
    display: inline-block;
    font-size: var(--text-small);
    font-weight: 600;
    margin-bottom: var(--space-md);
  }

  /* Stat cards (admin dashboard) */
  .stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
  }

  .stat-card {
    background: var(--color-canvas);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-md) var(--space-lg);
    box-shadow: var(--shadow-sm);
  }

  .stat-card__label {
    font-size: var(--text-small);
    color: var(--color-ink-faint);
    font-weight: 600;
    text-transform: capitalize;
  }

  .stat-card__value {
    font-size: var(--text-large);
    font-weight: 800;
    color: var(--color-ink);
  }

  /* Data tables */
  .table-wrap {
    overflow-x: auto;
    background: var(--color-canvas);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
  }

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

  .table th, .table td {
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--color-border);
  }

  .table th {
    color: var(--color-ink-faint);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.03em;
  }

  .table tbody tr:hover {
    background: var(--color-surface-hover);
  }

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

  .table td.is-actions {
    display: flex;
    gap: var(--space-xs);
    align-items: center;
    white-space: nowrap;
  }
}

@layer utilities {
  .stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
  }

  .cluster {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
  }

  .txt-center { text-align: center; }
  .txt-small { font-size: var(--text-small); }
  .txt-muted { color: var(--color-ink-faint); }
  .mt-lg { margin-top: var(--space-lg); }
  .mt-xl { margin-top: var(--space-xl); }
}
