/* ===== Design tokens ===== */
:root {
    --bg: #edf0f6;
    --surface: #ffffff;
    --ink: #151b2c;
    --muted: #59647a;
    --line: #d9dee9;
    --field-line: #c3cad9;
    --stage: #f3f5fa;

    --accent: #2450e0;
    --accent-hover: #1b40bd;

    --good: #0f7a55;
    --good-soft: #e1f3ea;
    --good-fill: #1fa774;
    --warn: #8a5300;
    --warn-soft: #fbefd6;
    --warn-fill: #e0a100;
    --bad: #b3261e;
    --bad-soft: #fbe6e4;
    --bad-fill: #d64545;
    --neutral: #59647a;
    --neutral-soft: #e6eaf3;

    --font-ui: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-serp: Roboto, Arial, sans-serif;

    --radius: 10px;
    --radius-lg: 14px;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
[hidden] { display: none !important; }

body {
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; }

.icon {
    width: 1.15em;
    height: 1.15em;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

:focus-visible {
    outline: 3px solid rgba(36, 80, 224, 0.45);
    outline-offset: 2px;
}

/* ===== Header ===== */
.app-header {
    max-width: 1280px;
    margin: 0 auto;
    padding: 28px 24px 8px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 20px;
}

.app-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.app-header p {
    color: var(--muted);
    font-size: 0.9rem;
}

/* ===== Layout ===== */
.workspace {
    max-width: 1280px;
    margin: 0 auto;
    padding: 16px 24px 32px;
    display: grid;
    gap: 24px;
    align-items: start;
}

@media (min-width: 1180px) {
    .workspace {
        grid-template-columns: minmax(400px, 460px) minmax(0, 1fr);
    }
    .preview-pane {
        position: sticky;
        top: 20px;
    }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.panel > h2,
.preview-head h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.editor > h2 { margin-bottom: 20px; }

/* ===== Form fields ===== */
.field + .field { margin-top: 26px; }

.field-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    min-height: 28px;
}

.field label {
    font-weight: 600;
    font-size: 0.9rem;
}

.field input,
.field textarea {
    width: 100%;
    padding: 11px 14px;
    font: inherit;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--field-line);
    border-radius: var(--radius);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.field textarea {
    resize: vertical;
    min-height: 74px;
    line-height: 1.5;
}

.field input::placeholder,
.field textarea::placeholder { color: #8b94a8; }

.field input:hover,
.field textarea:hover { border-color: #9aa5bd; }

.field input:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(36, 80, 224, 0.22);
}

.field input[aria-invalid="true"] { border-color: var(--bad); }

.hint {
    margin-top: 6px;
    font-size: 0.82rem;
    color: var(--muted);
}

.hint.error { color: var(--bad); }

.field-stats {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.82rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.field-stats b { color: var(--ink); font-weight: 600; }

/* Status chip: luôn kèm icon + chữ, không chỉ dựa vào màu */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px 2px 8px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--neutral-soft);
    color: var(--neutral);
}

.chip .icon { width: 15px; height: 15px; }

[data-level="good"] .chip { background: var(--good-soft); color: var(--good); }
[data-level="warn"] .chip { background: var(--warn-soft); color: var(--warn); }
[data-level="bad"]  .chip { background: var(--bad-soft);  color: var(--bad); }

/* ===== Meter: thanh đo kèm vùng tối ưu ===== */
.meter { margin-top: 10px; }

.meter-track {
    position: relative;
    height: 10px;
    border-radius: 5px;
    background: var(--neutral-soft);
    overflow: hidden;
}

.meter-zone {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--zone-start);
    width: calc(var(--zone-end) - var(--zone-start));
    background: rgba(31, 167, 116, 0.28);
}

.meter-track::after {
    /* vạch giới hạn bị cắt */
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--zone-end);
    width: 2px;
    margin-left: -1px;
    background: var(--ink);
    opacity: 0.55;
}

.meter-fill {
    position: absolute;
    top: 2px;
    bottom: 2px;
    left: 0;
    width: 0;
    border-radius: 3px;
    background: var(--neutral);
    transition: width 0.25s ease, background-color 0.2s;
}

[data-level="good"] .meter-fill { background: var(--good-fill); }
[data-level="warn"] .meter-fill { background: var(--warn-fill); }
[data-level="bad"]  .meter-fill { background: var(--bad-fill); }

.meter-labels {
    position: relative;
    height: 18px;
    margin-top: 4px;
    font-size: 0.72rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.meter-labels span {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    white-space: nowrap;
}

.feedback {
    margin-top: 8px;
    min-height: 3.1em;
    font-size: 0.86rem;
    color: var(--ink);
}

/* ===== Buttons ===== */
.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px solid var(--line);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 16px;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--field-line);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
}

.btn:hover { background: #f3f5fa; border-color: #9aa5bd; }
.btn:active { background: #e9edf5; }

.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ===== Preview ===== */
.preview-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.segmented {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    border-radius: var(--radius);
    background: var(--neutral-soft);
}

.seg-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 36px;
    padding: 0 14px;
    font: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

.seg-btn:hover { color: var(--ink); }

.seg-btn[aria-selected="true"] {
    background: #fff;
    color: var(--ink);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(21, 27, 44, 0.16);
}

.serp-stage {
    padding: 28px 24px;
    background: var(--stage);
    border-radius: var(--radius);
    overflow-x: auto;
}

/* Khung kết quả tìm kiếm mô phỏng Google */
.serp {
    box-sizing: content-box;
    margin: 0 auto;
    padding: 18px 20px;
    background: #fff;
    border-radius: 12px;
    font-family: var(--font-serp);
    color: #202124;
}

.serp--desktop { width: 612px; }  /* vùng chữ 612px > giới hạn tiêu đề 600px */
.serp--mobile  { width: 360px; }

.serp-site {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.serp-favicon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #eef1f6;
    border: 1px solid #dadce0;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 500;
    color: #5f6368;
    text-transform: uppercase;
}

.serp-site-text { min-width: 0; line-height: 1.3; }

.serp-site-name {
    font-size: 14px;
    color: #202124;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.serp-site-url {
    font-size: 12px;
    color: #4d5156;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.serp-title {
    margin: 0 0 4px;
    font-family: var(--font-serp);
    font-size: 20px;
    line-height: 1.3;
    font-weight: 400;
    color: #1a0dab;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.serp-title:hover { text-decoration: underline; }

.serp-description {
    font-size: 14px;
    line-height: 1.58;
    color: #4d5156;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.serp--mobile .serp-title {
    font-size: 18px;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.serp--mobile .serp-description {
    font-size: 13px;
    line-height: 1.5;
    -webkit-line-clamp: 2;
}

.is-placeholder { opacity: 0.45; }

/* Trạng thái hiển thị của thiết bị đang xem */
.flags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    margin-top: 16px;
    font-size: 0.85rem;
    color: var(--muted);
}

.flag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.flag .icon { width: 16px; height: 16px; }
.flag[data-state="ok"]  { color: var(--good); }
.flag[data-state="cut"] { color: var(--warn); }

/* ===== Guide + footer ===== */
.guide {
    max-width: 1280px;
    margin: 0 auto;
    padding: 8px 24px 24px;
}

.guide > h2 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 14px;
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
}

.guide-grid > div {
    padding-top: 14px;
    border-top: 2px solid var(--line);
}

.guide-grid h3 {
    font-size: 0.92rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.guide-grid p {
    font-size: 0.88rem;
    color: var(--muted);
    max-width: 52ch;
}

.app-footer {
    max-width: 1280px;
    margin: 0 auto;
    padding: 8px 24px 40px;
    font-size: 0.82rem;
    color: var(--muted);
}

/* ===== Responsive ===== */
@media (max-width: 760px) {
    .guide-grid { grid-template-columns: 1fr; gap: 18px; }
}

@media (max-width: 560px) {
    .app-header, .workspace, .guide, .app-footer { padding-left: 14px; padding-right: 14px; }
    .panel { padding: 18px 16px; }
    .serp-stage { padding: 16px 10px; }
    .actions .btn { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
