@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --hc-red: #B85450;
    --hc-dark-red: #9A3F3C;
    --hc-light-gray: #F8F9FA;
    --hc-gray: #E9ECEF;
    --hc-dark-gray: #495057;
    --hc-text: #212529;
    --hc-border: #DEE2E6;
    --success: #28A745;
    --warning: #FFC107;
    --danger: #DC3545;
    --info: #17A2B8;
    --primary: #007BFF;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #FFFFFF;
    color: var(--hc-text);
    line-height: 1.6;
}

.header {
    background: var(--hc-red);
    color: white;
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 18px;
    font-weight: 300;
}

.logo .company {
    font-weight: 600;
}

.tabs {
    background: white;
    border-bottom: 2px solid var(--hc-border);
    display: flex;
    padding: 0;
    max-width: 1400px;
    margin: 0 auto;
}

.tab {
    padding: 14px 24px;
    border: none;
    background: none;
    color: var(--hc-dark-gray);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab:hover {
    background: var(--hc-light-gray);
}

.tab.active {
    color: var(--hc-red);
    border-bottom-color: var(--hc-red);
    background: var(--hc-light-gray);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: white;
    border: 1px solid var(--hc-border);
    border-radius: 8px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.metric-card {
    background: white;
    border: 1px solid var(--hc-border);
    border-radius: 8px;
    padding: 16px;
    position: relative;
    overflow: hidden;
}

.metric-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--hc-red);
}

.metric-card.success::before { background: var(--success); }
.metric-card.warning::before { background: var(--warning); }
.metric-card.info::before { background: var(--info); }

.metric-label {
    font-size: 11px;
    color: var(--hc-dark-gray);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.metric-value {
    font-size: 24px;
    font-weight: 700;
    margin-top: 4px;
}

.metric-detail {
    font-size: 12px;
    color: #6c757d;
    margin-top: 2px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
}

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

.btn-primary:hover {
    background: var(--hc-dark-red);
}

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

.btn-outline {
    background: white;
    border: 1px solid var(--hc-border);
    color: var(--hc-text);
}

.table-container {
    background: white;
    border: 1px solid var(--hc-border);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
}

.table-header {
    background: var(--hc-light-gray);
    padding: 12px 16px;
    border-bottom: 1px solid var(--hc-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

th {
    background: #FAFBFC;
    padding: 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--hc-dark-gray);
    border-bottom: 2px solid var(--hc-border);
}

td {
    padding: 12px;
    font-size: 13px;
    border-bottom: 1px solid #F3F4F6;
}

tr:hover {
    background: #FAFBFC;
}

.tag {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.tag.valid { background: #D4EDDA; color: #155724; }
.tag.invalid { background: #F8D7DA; color: #721C24; }
.tag.pending { background: #FFF3CD; color: #856404; }
.tag.reimbursed { background: #D1ECF1; color: #0C5460; }

.config-section {
    background: white;
    border: 1px solid var(--hc-border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.config-section h3 {
    font-size: 16px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--hc-border);
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.config-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.config-item label {
    font-size: 13px;
    font-weight: 600;
    color: var(--hc-dark-gray);
}

.config-item input,
.config-item select,
.config-item textarea {
    padding: 8px 12px;
    border: 1px solid var(--hc-border);
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
}

.config-item textarea {
    min-height: 200px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 12px;
}

.config-item .help-text {
    font-size: 11px;
    color: #6c757d;
}

.config-item .status {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    margin-top: 4px;
}

.status.connected {
    background: #D4EDDA;
    color: #155724;
}

.status.error {
    background: #F8D7DA;
    color: #721C24;
}

.status.pending {
    background: #FFF3CD;
    color: #856404;
}

.chart-container {
    background: white;
    border: 1px solid var(--hc-border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    height: 250px; /* CRITICAL: Fixed height to prevent infinite growth */
}

.chart-container canvas {
    max-height: 180px !important; /* Enforce maximum canvas height */
}

.upload-area {
    border: 2px dashed var(--hc-border);
    border-radius: 8px;
    padding: 40px;
    text-align: center;
    margin-bottom: 20px;
    background: var(--hc-light-gray);
    cursor: pointer;
    transition: all 0.3s;
}

.upload-area:hover {
    border-color: var(--hc-red);
    background: white;
}

.upload-area.dragover {
    background: #E3F2FD;
    border-color: var(--primary);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--hc-border);
}

.modal-body {
    padding: 20px;
}

.carousel-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: white;
    border: 2px solid var(--hc-border);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 24px;
    color: var(--hc-red);
    z-index: 1001;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.carousel-nav-btn:hover {
    background: var(--hc-red);
    color: white;
    border-color: var(--hc-red);
    transform: translateY(-50%) scale(1.1);
}

.carousel-nav-left {
    left: -60px;
}

.carousel-nav-right {
    right: -60px;
}

@media (max-width: 900px) {
    .carousel-nav-btn {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .carousel-nav-left {
        left: 10px;
    }
    
    .carousel-nav-right {
        right: 10px;
    }
}

.processing-item {
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 6px;
    background: var(--hc-light-gray);
    display: flex;
    align-items: center;
    gap: 12px;
}

.processing-item.active {
    background: #E3F2FD;
    border-left: 3px solid var(--primary);
}

.processing-item.success {
    background: #D4EDDA;
    border-left: 3px solid var(--success);
}

.processing-item.error {
    background: #F8D7DA;
    border-left: 3px solid var(--danger);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--hc-red);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 2000;
    animation: slideIn 0.3s;
}

@keyframes slideIn {
    from { transform: translateX(400px); }
    to { transform: translateX(0); }
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--info); }

.empty-state {
    text-align: center;
    padding: 40px;
    color: #6c757d;
}

#fileInput {
    display: none;
}

.info-box {
    background: #E3F2FD;
    border-left: 4px solid var(--primary);
    padding: 12px;
    margin-bottom: 16px;
    border-radius: 4px;
    font-size: 13px;
}

.info-box h4 {
    margin-bottom: 8px;
    font-size: 14px;
}

.log-viewer {
    background: #1E1E1E;
    color: #D4D4D4;
    padding: 12px;
    border-radius: 4px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 11px;
    max-height: 300px;
    overflow-y: auto;
    margin-top: 12px;
}

.log-entry {
    margin-bottom: 4px;
    padding: 2px 0;
}

.log-entry.info { color: #4FC3F7; }
.log-entry.success { color: #81C784; }
.log-entry.error { color: #E57373; }
.log-entry.warning { color: #FFB74D; }

@media (max-width: 768px) {
    .tabs {
        overflow-x: auto;
    }
    
    .config-grid {
        grid-template-columns: 1fr;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* ======================================
   Mobile/iOS PWA Optimizations
   ====================================== */

/* iOS Safe Area Support */
body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Mobile-first adjustments */
@media (max-width: 768px) {
    .header {
        padding: env(safe-area-inset-top) 0 12px 0;
    }

    /* Fix header content stacking on mobile */
    .header-content {
        flex-direction: column;
        align-items: center;
        gap: 4px;
        text-align: center;
    }

    .logo {
        font-size: 16px;
    }

    .header-content > div:last-child {
        font-size: 11px !important;
        opacity: 0.8;
    }

    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab {
        white-space: nowrap;
        font-size: 13px;
        padding: 12px 16px;
    }

    .container {
        padding: 16px;
    }

    /* Make buttons bigger for touch */
    .btn {
        min-height: 44px;
        font-size: 15px;
    }

    /* Improve form inputs for mobile */
    input, select, textarea {
        font-size: 16px !important; /* Prevents iOS zoom */
    }

    /* Card spacing on mobile */
    .card {
        margin-bottom: 16px;
    }

    /* Modal improvements */
    .modal-content {
        max-width: 95% !important;
        margin: 10px;
    }

    /* Table improvements */
    table {
        font-size: 13px;
    }

    th, td {
        padding: 8px 6px;
    }

    /* Stack action bar buttons on mobile */
    .action-bar {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .action-bar > div {
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Fieldset responsive design */
    fieldset {
        padding: 12px !important;
    }

    fieldset legend {
        font-size: 13px !important;
    }

    fieldset > div {
        flex-direction: column !important;
    }

    fieldset .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Documentation alignment fixes */
.card {
    margin-bottom: 24px;
}

.card h3 {
    margin-top: 0;
    margin-bottom: 12px;
}

.card h4 {
    margin-top: 16px;
    margin-bottom: 8px;
}

.card p {
    margin-bottom: 12px;
}

.card ul, .card ol {
    margin: 12px 0;
    padding-left: 24px;
}

.card li {
    margin-bottom: 8px;
}

/* iOS-style touches */
@supports (-webkit-touch-callout: none) {
    /* iOS-specific styles */
    input, select, textarea, button {
        -webkit-appearance: none;
        appearance: none;
    }
    
    .btn {
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Smooth scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }
}

/* Prevent text size adjust on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Better touch targets */
button, a, .clickable {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ======================================
   Documentation Quick Navigation - Sticky
   ====================================== */

#docQuickNav {
    position: sticky;
    top: 0;
    z-index: 50;
    transition: box-shadow 0.2s;
}

/* Smooth scrolling for anchor links */
html {
    scroll-behavior: smooth;
}

/* ======================================
   Actions Sidebar - Responsive Design
   ====================================== */

#actionsSidebar {
    position: sticky;
    top: 20px;
    align-self: flex-start;
}

@media (max-width: 1024px) {
    /* Stack sidebar below content on tablets and mobile */
    .container > div[style*="display: flex"] {
        flex-direction: column-reverse !important;
    }

    #actionsSidebar {
        width: 100% !important;
        position: static !important;
        margin-bottom: 20px;
    }

    #actionsSidebar > div {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 16px;
    }

    #actionsSidebar h4 {
        display: none;
    }
}

/* ======================================
   Analytics Tab Fixes - Prevent Infinity Stretching
   ====================================== */

#analytics .container {
    max-width: 1400px;
    overflow: hidden;
}

/* Constrain canvas elements */
#analytics canvas {
    max-width: 100%;
    max-height: 300px !important;
    height: 200px !important;
}

/* Fix grid layouts in analytics */
#analytics .card {
    min-height: 0;
    max-height: none;
}

/* Constrain chart containers */
#analytics .card canvas {
    display: block;
    width: 100% !important;
    height: 200px !important;
}

/* Table container constraints */
#analytics .table-container {
    max-height: 600px;
    overflow-y: auto;
}

/* Grid layout fixes */
#analytics > .container > div[style*="grid"] {
    display: grid;
    overflow: hidden;
}

/* Prevent grid items from expanding infinitely */
#analytics .card:has(canvas) {
    overflow: hidden;
    max-height: 280px;
}
