/* ============================================================
   Allpa Botanicals — Shared Tool Styles
   Mobile-first base for all internal tools.
   ============================================================ */

:root {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --border: #e2e5ea;
    --text: #1a1e2e;
    --text-secondary: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --green-border: #86efac;
    --yellow: #ca8a04;
    --yellow-bg: #fef9c3;
    --yellow-border: #fde047;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --red-border: #fca5a5;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,.12);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

/* --- Header --- */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-brand h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header-back {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-decoration: none;
    white-space: nowrap;
}

.header-back:hover {
    color: var(--primary);
}

.header-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: 0.4rem;
}

/* --- Tabs --- */

.tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 49px;
    z-index: 99;
}

.tab {
    flex: 1;
    padding: 0.65rem;
    border: none;
    background: none;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* --- Main --- */

.main { padding: 1rem; }

.view { display: none; }
.view.active { display: block; }

/* --- Buttons --- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--surface);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

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

.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary { background: var(--bg); }

.btn-full { width: 100%; margin-top: 1rem; }

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

.search-input, .date-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    background: var(--surface);
    color: var(--text);
}

.search-input { flex: 1; min-width: 150px; }
.date-input { width: auto; }

/* --- Filter Button Group --- */

.status-filters {
    display: flex;
    gap: 0;
    width: 100%;
}

.status-filter-btn {
    flex: 1;
    padding: 0.45rem 0.5rem;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.status-filter-btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.status-filter-btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.status-filter-btn:not(:first-child) { border-left: none; }

.status-filter-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* --- Stats Grid --- */

.log-stats {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    text-align: center;
}

.stat-item .stat-value {
    font-size: 1.3rem;
    font-weight: 700;
}

.stat-item .stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.stat-green { color: var(--green); }
.stat-red { color: var(--red); }
.stat-yellow { color: var(--yellow); }

/* --- Loading + Spinners --- */

.loading-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 40vh;
    gap: 1rem;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-small {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Stats Grid --- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    margin-top: 2px;
}

.stat-sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* --- Panels --- */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.panel h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

/* --- Two-column layout --- */

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .two-col { grid-template-columns: 1fr; }
}

/* --- Tables --- */

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    padding: 8px 10px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

tr:hover td {
    background: var(--bg);
}

td a {
    color: var(--primary);
    text-decoration: none;
}

td a:hover {
    text-decoration: underline;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* --- Toolbar --- */

.toolbar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    align-items: center;
}

.filter-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    background: var(--surface);
    color: var(--text);
}

.toolbar-count {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-left: auto;
}

/* --- Badges --- */

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-green { background: var(--green-bg); color: var(--green); }
.badge-pass { background: var(--green-bg); color: var(--green); }
.badge-fail { background: var(--red-bg); color: var(--red); }
.badge-recheck { background: var(--yellow-bg); color: var(--yellow); }

/* --- Pagination --- */

.pagination {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
    align-items: center;
}

.pagination .btn {
    padding: 0.4rem 0.85rem;
    font-size: 0.82rem;
    min-width: 36px;
}

/* --- Button sizes --- */

.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.82rem;
}

/* --- Modal --- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.5);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem 1rem;
    animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg);
    border-radius: 50%;
    font-size: 1.2rem;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Detail Body --- */

.detail-body img {
    width: 100%;
    border-radius: var(--radius);
    margin-bottom: 1rem;
}

.detail-body h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.detail-body .detail-status {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.detail-body .detail-section {
    margin-bottom: 1rem;
}

.detail-body .detail-section h4 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.detail-body .detail-section p,
.detail-body .detail-section li {
    font-size: 0.85rem;
}

.detail-body .detail-section ul {
    list-style: disc;
    padding-left: 1.2rem;
}

/* --- Collapsible Details --- */

.raw-response {
    margin-top: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.raw-response summary {
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    background: var(--bg);
    user-select: none;
}

.raw-response pre {
    padding: 0.75rem;
    font-size: 0.72rem;
    line-height: 1.45;
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    background: var(--bg);
    overflow-x: auto;
    max-height: 50vh;
    white-space: pre-wrap;
    word-break: break-word;
}

/* --- Pagination --- */

.log-pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* --- Utilities --- */

[hidden] { display: none !important; }

@media (min-width: 600px) {
    .main { padding: 1.5rem; }
    .header { padding: 0.75rem 1.5rem; }
    .log-stats { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-count {
        margin-left: 0;
        text-align: center;
    }
}

.empty-msg {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem 1rem;
}

.nowrap {
    white-space: nowrap;
}
