/* ==========================================================================
   Meal Log — Frontend Styles
   ========================================================================== */

:root {
    --ml-blue:        #2563eb;
    --ml-blue-dark:   #1d4ed8;
    --ml-blue-light:  rgba(37, 99, 235, 0.08);
    --ml-green:       #16a34a;
    --ml-red:         #dc2626;
    --ml-border:      #e5e7eb;
    --ml-bg:          #f9fafb;
    --ml-white:       #ffffff;
    --ml-text:        #111827;
    --ml-muted:       #6b7280;
    --ml-radius:      6px;
    --ml-shadow-sm:   0 1px 3px rgba(0,0,0,.08);
    --ml-focus-ring:  0 0 0 3px rgba(37, 99, 235, 0.2);
}

/* --------------------------------------------------------------------------
   Shared utilities
   -------------------------------------------------------------------------- */

.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;
}

.ezmeal-notice {
    padding: 12px 16px;
    border-radius: var(--ml-radius);
    margin: 0 0 20px;
    font-size: .95em;
    border: 1px solid transparent;
}

.ezmeal-success { background: #f0fdf4; border-color: #bbf7d0; color: var(--ml-green); }
.ezmeal-error   { background: #fef2f2; border-color: #fecaca; color: var(--ml-red);   }
.ezmeal-updated { background: #eff6ff; border-color: #bfdbfe; color: var(--ml-blue);  }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.ezmeal-btn {
    display: inline-block;
    padding: 9px 20px;
    border-radius: var(--ml-radius);
    font-size: .9em;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s, color .15s;
    border: 1px solid transparent;
    line-height: 1.4;
}

.ezmeal-btn-primary {
    background: var(--ml-blue);
    color: var(--ml-white);
}
.ezmeal-btn-primary:hover,
.ezmeal-btn-primary:focus {
    background: var(--ml-blue-dark);
    color: var(--ml-white);
}

.ezmeal-btn-secondary {
    background: var(--ml-white);
    color: var(--ml-muted);
    border-color: var(--ml-border);
}
.ezmeal-btn-secondary:hover {
    border-color: #9ca3af;
    color: var(--ml-text);
}

.ezmeal-btn-outline {
    background: var(--ml-white);
    color: var(--ml-text);
    border-color: var(--ml-border);
}
.ezmeal-btn-outline:hover {
    border-color: var(--ml-blue);
    color: var(--ml-blue);
}

.ezmeal-btn:focus {
    outline: none;
    box-shadow: var(--ml-focus-ring);
}

/* --------------------------------------------------------------------------
   Form
   -------------------------------------------------------------------------- */

.ezmeal-form-wrap { max-width: 640px; }

.ezmeal-field { margin-bottom: 22px; }

.ezmeal-field label,
.ezmeal-field > span.label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--ml-text);
    font-size: .95em;
}

.ezmeal-field .req { color: var(--ml-red); }

.ezmeal-field input[type="text"],
.ezmeal-field input[type="number"],
.ezmeal-field input[type="date"] {
    padding: 8px 12px;
    border: 1px solid var(--ml-border);
    border-radius: var(--ml-radius);
    font-size: 1em;
    color: var(--ml-text);
    background: var(--ml-white);
    width: 100%;
    max-width: 300px;
    box-sizing: border-box;
    transition: border-color .15s;
}

.ezmeal-field input:focus {
    outline: none;
    border-color: var(--ml-blue);
    box-shadow: var(--ml-focus-ring);
}

.date-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.day-of-week {
    color: var(--ml-muted);
    font-style: italic;
    font-size: .9em;
}

.ezmeal-hint {
    margin: 6px 0 0;
    font-size: .82em;
    color: var(--ml-muted);
}

.ezmeal-hint kbd {
    background: var(--ml-bg);
    border: 1px solid var(--ml-border);
    border-radius: 3px;
    padding: 1px 5px;
    font-size: .85em;
    font-family: monospace;
}

.ezmeal-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 28px;
}

/* --------------------------------------------------------------------------
   Tag input
   -------------------------------------------------------------------------- */

.tag-input-wrap {
    position: relative;
    background: var(--ml-white);
    border: 1px solid var(--ml-border);
    border-radius: var(--ml-radius);
    padding: 8px;
    min-height: 46px;
    max-width: 520px;
    cursor: text;
    box-sizing: border-box;
    transition: border-color .15s;
}

.tag-input-wrap:focus-within {
    border-color: var(--ml-blue);
    box-shadow: var(--ml-focus-ring);
}

.tag-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 4px;
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
    border-radius: 4px;
    padding: 3px 8px;
    font-size: .85em;
    line-height: 1.4;
}

.tag-chip-remove {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: #60a5fa;
    font-size: 1.1em;
    line-height: 1;
    display: flex;
    align-items: center;
}

.tag-chip-remove:hover { color: var(--ml-red); }

#tag_text_input {
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
    padding: 4px 4px !important;
    margin: 0 !important;
    max-width: 100%;
    width: auto;
    min-width: 180px;
    font-size: .9em;
    background: transparent;
    color: var(--ml-text);
}

.tag-suggestions {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--ml-white);
    border: 1px solid var(--ml-border);
    border-radius: var(--ml-radius);
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    display: none;
    max-height: 220px;
    overflow-y: auto;
}

.tag-suggestion {
    padding: 9px 14px;
    cursor: pointer;
    font-size: .9em;
    color: var(--ml-text);
}

.tag-suggestion:hover,
.tag-suggestion[aria-selected="true"] {
    background: var(--ml-bg);
    color: var(--ml-blue);
}

/* --------------------------------------------------------------------------
   Table page
   -------------------------------------------------------------------------- */

.ezmeal-table-wrap { width: 100%; }

/* Averages row */
.ezml-averages {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.ezml-avg-card {
    flex: 1;
    min-width: 130px;
    background: var(--ml-white);
    border: 1px solid var(--ml-border);
    border-radius: var(--ml-radius);
    padding: 16px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--ml-shadow-sm);
}

.ezml-avg-label {
    font-size: .72em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ml-muted);
}

.ezml-avg-value {
    font-size: 2.2em;
    font-weight: 700;
    color: var(--ml-blue);
    line-height: 1;
}

.ezml-avg-sub {
    font-size: .72em;
    color: var(--ml-muted);
}

/* Toolbar */
.ezml-toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

/* Table */
.ezml-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9em;
    background: var(--ml-white);
    border: 1px solid var(--ml-border);
    border-radius: var(--ml-radius);
    overflow: hidden;
}

.ezml-table thead {
    background: var(--ml-bg);
}

.ezml-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: .75em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--ml-muted);
    border-bottom: 2px solid var(--ml-border);
    white-space: nowrap;
}

.ezml-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--ml-border);
    vertical-align: top;
    color: var(--ml-text);
}

.ezml-table tbody tr:last-child td { border-bottom: none; }
.ezml-table tbody tr:hover td { background: #fafbff; }

.ezml-table th.num,
.ezml-table td.num { text-align: center; }

.ezml-table .actions-col { width: 60px; }

.ezml-edit-link {
    font-size: .8em;
    color: var(--ml-blue);
    text-decoration: none;
}
.ezml-edit-link:hover { text-decoration: underline; }

.ezml-item-list {
    margin: 0;
    padding-left: 16px;
    list-style: disc;
}

.ezml-item-list li { margin-bottom: 2px; }
.ezml-empty { color: var(--ml-muted); }
.ezml-empty-state {
    text-align: center;
    padding: 48px 0;
    color: var(--ml-muted);
    font-style: italic;
}

/* Pagination */
.ezml-pagination {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 24px;
    flex-wrap: wrap;
}

.ezml-pagination a {
    padding: 6px 13px;
    border: 1px solid var(--ml-border);
    border-radius: var(--ml-radius);
    font-size: .85em;
    color: var(--ml-text);
    text-decoration: none;
    transition: background .15s, color .15s;
}

.ezml-pagination a:hover,
.ezml-pagination a.active {
    background: var(--ml-blue);
    color: var(--ml-white);
    border-color: var(--ml-blue);
}

/* --------------------------------------------------------------------------
   Chart
   -------------------------------------------------------------------------- */

.ezml-chart-wrap { width: 100%; }

.ezml-chart-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.ezml-range-btn {
    padding: 7px 16px;
    border: 1px solid var(--ml-border);
    border-radius: var(--ml-radius);
    background: var(--ml-white);
    font-size: .85em;
    cursor: pointer;
    color: var(--ml-text);
    transition: all .15s;
}

.ezml-range-btn:hover,
.ezml-range-btn.active {
    background: var(--ml-blue);
    color: var(--ml-white);
    border-color: var(--ml-blue);
}

.ezml-range-btn:focus {
    outline: none;
    box-shadow: var(--ml-focus-ring);
}

.ezml-chart-container {
    position: relative;
    height: 360px;
    background: var(--ml-white);
    border: 1px solid var(--ml-border);
    border-radius: var(--ml-radius);
    padding: 16px;
    box-sizing: border-box;
    box-shadow: var(--ml-shadow-sm);
}

.ezml-chart-container canvas {
    max-height: 100%;
}

/* --------------------------------------------------------------------------
   Responsive — narrow screens
   -------------------------------------------------------------------------- */

@media (max-width: 640px) {
    .ezml-table thead { display: none; }

    .ezml-table tr {
        display: block;
        border: 1px solid var(--ml-border);
        border-radius: var(--ml-radius);
        margin-bottom: 12px;
        background: var(--ml-white);
    }

    .ezml-table td {
        display: flex;
        gap: 12px;
        align-items: flex-start;
        border-bottom: 1px solid var(--ml-border);
        padding: 9px 12px;
    }

    .ezml-table td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: .75em;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--ml-muted);
        min-width: 90px;
        flex-shrink: 0;
        padding-top: 2px;
    }

    .ezml-table td.num { justify-content: flex-start; }

    .ezml-avg-card { min-width: 100px; }
}

/* --------------------------------------------------------------------------
   Print styles
   -------------------------------------------------------------------------- */

@media print {
    .ezml-toolbar,
    .ezml-pagination,
    .ezml-chart-controls,
    .ezml-chart-container,
    .ezml-print-btn,
    .ezml-edit-link,
    .actions-col,
    .ezmeal-form-wrap,
    nav,
    header,
    footer,
    aside { display: none !important; }

    .ezml-averages { flex-wrap: nowrap; }

    .ezml-avg-card {
        border: 1px solid #ccc !important;
        box-shadow: none !important;
    }

    .ezml-table {
        border: 1px solid #ccc !important;
        font-size: .8em;
        box-shadow: none !important;
    }

    .ezml-table th {
        background: #f0f0f0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body { font-size: 12pt; }
}
