/* === AYANA Quality Audit - Mobile-first CSS === */
/* Brand: Arsenal + Belleza fonts, AYANA Blue #0085C2, Accent Orange #FF9900 */
@import url('https://fonts.googleapis.com/css2?family=Arsenal:wght@400;700&family=Belleza&display=swap');

:root {
    --primary: #0085C2;
    --primary-dark: #006A9E;
    --primary-light: #e8f4fa;
    --accent: #FF9900;
    --success: #27ae60;
    --warning: #FF9900;
    --danger: #e74c3c;
    --muted: #95a5a6;
    --bg: #f8f8f6;
    --card-bg: #ffffff;
    --text: #3E3A39;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --radius: 8px;
    /* Safe area insets for iPhone X+ notch/home indicator */
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
    /* Prevent horizontal overflow on all mobile screens */
    overflow-x: hidden;
}

body {
    font-family: 'Arsenal', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    /* Minimum font size safety net */
    -webkit-text-size-adjust: 100%;
}

/* === Font consistency ===
 * Arsenal: ALL body text, labels, buttons, form inputs, table cells, metadata
 * Belleza: ONLY headings with .header h1, composite score, property names, page titles
 */
input, select, textarea, button {
    font-family: 'Arsenal', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* === Layout === */
.container { max-width: 900px; margin: 0 auto; padding: 16px; }

/* Header — white, logo-led, 56px, AYANA brand */
.header {
    background: #ffffff;
    height: 56px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    min-width: 0; /* Allow flex children to shrink below content size */
    flex: 1; /* Take available space but allow shrink */
}
.header-logo { height: 22px; flex-shrink: 0; }
.header-divider { width: 1px; height: 22px; background: var(--border-strong); flex-shrink: 0; }
.header h1 {
    font-family: 'Belleza', serif;
    font-size: 0.9375rem;
    font-weight: 400;
    letter-spacing: 0.3px;
    color: var(--text);
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0; /* Allow text truncation in flex */
}
.header-sub { display: none; }
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0; /* Never let right side collapse */
}
.header-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--primary-light);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.72rem; font-weight: 700; color: var(--primary);
    cursor: pointer; border: 1px solid var(--border);
    transition: border-color 0.15s;
    flex-shrink: 0;
}
.header-avatar:hover { border-color: var(--primary); }
.header-back {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8125rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px;
    transition: color 0.15s;
    flex-shrink: 0;
    /* 44px touch target for mobile */
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
}
.header-back:hover { color: var(--primary); }

/* === Cards === */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    border: 1px solid var(--border);
}
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 8px; }
.card-meta { font-size: 0.8rem; color: var(--text-light); }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #219a52; }
.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--primary); color: white; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Forms === */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text);
}
.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
    background: white;
}
.form-control:focus { outline: none; border-color: var(--primary-light); }
select.form-control { appearance: auto; }

/* === Audit Standard Item === */
.standard-item {
    background: var(--card-bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
    transition: border-color 0.2s;
}
.standard-item.responded { border-left: 4px solid var(--success); }
.standard-item.not-practiced { border-left: 4px solid var(--danger); }
.standard-item.na-item { border-left: 4px solid var(--muted); opacity: 0.7; }

.standard-code {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-light);
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
    margin-bottom: 6px;
}
.standard-classification {
    font-size: 0.7rem;
    color: var(--text-light);
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
    margin-bottom: 6px;
    margin-left: 4px;
}
.standard-question {
    font-size: 0.88rem;
    line-height: 1.5;
    margin-bottom: 10px;
}

/* Response buttons - radio-like */
.response-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
.response-btn {
    flex: 1;
    min-width: 0;
    padding: 8px 4px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    background: white;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
    color: var(--text);
    line-height: 1.2;
}
.response-btn:hover { background: #f0f0f0; }
.response-btn.active-practiced { background: #d5f5e3; border-color: var(--success); color: #1e8449; }
.response-btn.active-service { background: #fadbd8; border-color: var(--danger); color: #c0392b; }
.response-btn.active-investment { background: #fdebd0; border-color: var(--warning); color: #d68910; }
.response-btn.active-na { background: #eaecee; border-color: var(--muted); color: #5d6d7e; }

.comment-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.82rem;
    resize: vertical;
    min-height: 36px;
}
.comment-input:focus { outline: none; border-color: var(--primary-light); }

/* === Section nav === */
.section-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}
.section-pill {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    border: 1.5px solid var(--border);
    background: white;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.section-pill:hover { border-color: var(--primary-light); }
.section-pill.active { background: var(--primary); color: white; border-color: var(--primary); font-weight: 600; }
.section-pill .pill-count {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-left: 4px;
}

/* === Progress bar === */
.progress-bar-bg {
    background: #eaecee;
    border-radius: 10px;
    height: 8px;
    overflow: hidden;
    margin: 8px 0;
}
.progress-bar-fill {
    height: 100%;
    border-radius: 8px;
    background: var(--primary);
    transition: width 0.3s;
}
.progress-text { font-size: 0.8rem; color: var(--text-light); }

/* === Summary === */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
    border: 1px solid var(--border);
}
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.78rem; color: var(--text-light); margin-top: 2px; }
.stat-value.success { color: var(--success); }
.stat-value.danger { color: var(--danger); }

.bar-chart-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 0.82rem;
}
.bar-chart-label { width: 180px; flex-shrink: 0; text-align: right; }
.bar-chart-bar {
    flex: 1;
    height: 22px;
    background: #eaecee;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}
.bar-chart-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}
.bar-chart-fill.good { background: var(--success); }
.bar-chart-fill.medium { background: var(--warning); }
.bar-chart-fill.low { background: var(--danger); }
.bar-chart-pct { width: 50px; font-weight: 600; font-size: 0.82rem; }

/* === Modal === */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.active { display: flex; }
.modal {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal h2 { font-size: 1.1rem; margin-bottom: 16px; }

/* === Utilities === */
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}
.badge-draft { background: #eaecee; color: #5d6d7e; }
.badge-progress { background: #d6eaf8; color: #2471a3; }
.badge-completed { background: #d5f5e3; color: #1e8449; }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}
.empty-state p { font-size: 0.9rem; margin-top: 8px; }

/* === Toast === */
.toast {
    position: fixed;
    bottom: 20px;
    bottom: calc(20px + var(--sab));
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 0.85rem;
    z-index: 300;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    max-width: calc(100vw - 32px); /* Prevent toast overflow on narrow screens */
    text-align: center;
}
.toast.visible { opacity: 1; }

/* === Scroll hint for wide tables === */
.scroll-hint {
    position: relative;
}
.scroll-hint::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.9));
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s;
}
.scroll-hint.scrolled-end::after {
    opacity: 0;
}

/* === Fix sub-12px font sizes globally === */
.standard-classification { font-size: 0.75rem; }
.response-btn { font-size: 0.75rem; }

/* === Section nav horizontal scroll on small screens === */
.section-nav {
    -webkit-overflow-scrolling: touch;
}

/* === Responsive — Tablet (768px and below) === */
@media (max-width: 768px) {
    .container { padding: 12px; }

    /* Header: hide subtitle on tablet, keep "Quality" */
    .header h1 span { display: none; }
    .header h1::after { content: ""; }

    .bar-chart-label { width: 120px; font-size: 0.78rem; }

    /* Section pills: horizontal scroll on tablet */
    .section-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
        scrollbar-width: thin;
    }
    .section-pill { flex-shrink: 0; }
}

/* === Responsive — Phone (480px and below) === */
@media (max-width: 480px) {
    /* Header compact */
    .header { height: 48px; padding: 0 12px; }
    .header-logo { height: 18px; }
    .header-divider { height: 18px; }
    .header h1 { font-size: 0.8rem; }
    .header-avatar { width: 44px; height: 44px; font-size: 0.75rem; }
    .header-brand { gap: 8px; }

    /* Touch targets: min 44px for all interactive elements */
    .response-group { flex-wrap: wrap; }
    .response-btn { min-width: 45%; flex: unset; padding: 14px 8px; font-size: 0.82rem; min-height: 44px; }
    .section-pill { padding: 12px 14px; font-size: 0.82rem; min-height: 44px; display: inline-flex; align-items: center; }
    .btn-sm { padding: 10px 14px; font-size: 0.85rem; min-height: 44px; }
    .badge { padding: 4px 10px; font-size: 0.78rem; }

    /* Cards, forms */
    .container { padding: 10px; }
    .card { padding: 12px; }
    .modal { padding: 16px; border-radius: 12px 12px 0 0; max-height: 95vh; }
    .modal-overlay { align-items: flex-end; padding: 0; }
    .form-control { padding: 12px; font-size: 1rem; min-height: 44px; }
    .comment-input { min-height: 60px; font-size: 0.88rem; padding: 10px 12px; }

    /* Bar charts: stack label above bar on phone */
    .bar-chart-row { flex-wrap: wrap; }
    .bar-chart-label { width: 100%; text-align: left; font-size: 0.78rem; margin-bottom: 2px; }
    .bar-chart-pct { width: 40px; font-size: 0.78rem; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-value { font-size: 1.4rem; }

    /* Save bar with safe-area for iPhones with home indicator */
    .btn-block, .btn { font-size: 1rem; padding: 12px 20px; min-height: 44px; }

    /* Score table — ensure scroll on narrow screens */
    .score-table th, .score-table td { padding: 6px 4px; font-size: 0.75rem; white-space: nowrap; }

    /* Flex-between: allow wrapping on phone when content overflows */
    .flex-between { flex-wrap: wrap; gap: 8px; }

    /* Card title + meta text sizing */
    .card-title { font-size: 0.95rem; }
    .card-meta { font-size: 0.78rem; }

    /* Progress bar section */
    .progress-text { font-size: 0.78rem; }

    /* Standard items: tighter padding */
    .standard-item { padding: 12px; }
    .standard-question { font-size: 0.85rem; }

    /* Toast safe area */
    .toast {
        bottom: calc(20px + var(--sab));
        max-width: calc(100vw - 32px);
    }

    /* Modal safe area padding at bottom */
    .modal {
        padding-bottom: calc(16px + var(--sab));
    }
}

/* === Responsive — Small phone (375px and below) === */
@media (max-width: 375px) {
    .header { padding: 0 8px; }
    .header h1 { font-size: 0.75rem; }
    .header-logo { height: 16px; }
    .header-brand { gap: 6px; }
    .header-back { margin-right: 4px; min-width: 40px; }

    .container { padding: 8px; }

    .stat-grid { grid-template-columns: 1fr 1fr; }
    .stat-value { font-size: 1.2rem; }
    .stat-label { font-size: 0.75rem; }

    .response-btn { min-width: 100%; }

    .card { padding: 10px; margin-bottom: 8px; }
    .card-title { font-size: 0.9rem; }

    .standard-item { padding: 10px; margin-bottom: 8px; }
    .standard-question { font-size: 0.82rem; }
    .standard-code { font-size: 0.72rem; padding: 2px 6px; }

    /* Buttons: full width stacking */
    .btn { padding: 12px 16px; font-size: 0.95rem; }
    .btn-sm { padding: 10px 12px; font-size: 0.82rem; }

    /* Score table: smaller on tiny screens */
    .score-table th, .score-table td { padding: 4px 3px; font-size: 0.72rem; }
}
