/**
 * Child Growth Monitoring Portal - Core Stylesheet
 * Healthcare SaaS UI Design System
 */

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Navigation & Header */
.app-header {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--text-primary);
    cursor: pointer;
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary), #0284c7);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(2, 132, 199, 0.3);
}

.brand-title {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    display: flex;
    flex-direction: column;
}

.brand-subtitle {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--primary);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
    cursor: pointer;
}

.nav-link:hover, .nav-link.active {
    color: var(--primary);
    background-color: var(--primary-light);
}

.child-badge {
    background-color: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--primary-border);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

/* Theme Selector */
.theme-select {
    background-color: var(--bg-subtle);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.theme-select:focus {
    outline: 2px solid var(--primary);
    border-color: var(--primary);
}

/* Main Content Area */
.app-main {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 4rem;
}

/* Views Management */
.portal-view {
    display: none;
}

.portal-view.active {
    display: block;
    animation: fadeIn 0.25s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Typography & Headings */
h1, h2, h3, h4, h5 {
    color: var(--text-primary);
    font-weight: 700;
    line-height: 1.25;
}

.page-title {
    font-size: 1.6rem;
    margin-bottom: 0.35rem;
    letter-spacing: -0.02em;
}

.page-desc {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
}

/* Cards & Surfaces */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 1.15rem;
    font-weight: 600;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
    text-decoration: none;
    line-height: 1;
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
}

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

.btn-secondary {
    background-color: var(--bg-subtle);
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-secondary:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    background-color: var(--danger);
    color: #ffffff;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-strong);
    color: var(--text-secondary);
}

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

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
}

.btn-block {
    width: 100%;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}

.form-hint {
    font-size: 0.775rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.form-control {
    width: 100%;
    padding: 0.65rem 0.85rem;
    font-size: 0.925rem;
    font-family: inherit;
    color: var(--text-primary);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-control.is-invalid {
    border-color: var(--danger);
    background-color: var(--danger-light);
}

.form-control.is-valid {
    border-color: var(--success);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}

/* Captcha Component Box */
.captcha-container {
    background-color: var(--bg-subtle);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin: 1.25rem 0;
}

.captcha-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.captcha-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.captcha-render-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.captcha-canvas {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background-color: #ffffff;
    box-shadow: var(--shadow-sm);
    display: block;
    cursor: default;
}

.captcha-tools {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    border: 1px solid var(--border);
    background-color: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-icon.rotating svg {
    animation: spin 0.5s ease-in-out;
}

.btn-icon.playing {
    color: #ffffff;
    background-color: var(--primary);
}

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

.captcha-error {
    font-size: 0.8rem;
    color: var(--danger);
    font-weight: 500;
    margin-top: 0.4rem;
    display: none;
}

/* Shake Animation */
.shake-animation {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-3px, 0, 0); }
    40%, 60% { transform: translate3d(3px, 0, 0); }
}

/* Alert Boxes */
.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    border: 1px solid transparent;
}

.alert-danger {
    background-color: var(--danger-light);
    color: var(--danger-text);
    border-color: rgba(239, 68, 68, 0.3);
}

.alert-warning {
    background-color: var(--warning-light);
    color: var(--warning-text);
    border-color: rgba(245, 158, 11, 0.3);
}

.alert-info {
    background-color: var(--info-light);
    color: var(--info-text);
    border-color: rgba(59, 130, 246, 0.3);
}

.alert-success {
    background-color: var(--success-light);
    color: var(--success-text);
    border-color: rgba(16, 185, 129, 0.3);
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    line-height: 1;
}

.badge-success {
    background-color: var(--success-light);
    color: var(--success-text);
}

.badge-warning {
    background-color: var(--warning-light);
    color: var(--warning-text);
}

.badge-danger {
    background-color: var(--danger-light);
    color: var(--danger-text);
}

.badge-info {
    background-color: var(--info-light);
    color: var(--info-text);
}

.badge-secondary {
    background-color: var(--bg-hover);
    color: var(--text-muted);
}

/* Metric / Stat Cards */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.metric-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.4rem;
}

.metric-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.metric-sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Measurement History Table */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    text-align: left;
}

.table th {
    background-color: var(--bg-subtle);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.table tbody tr:hover {
    background-color: var(--bg-subtle);
}

/* Chart Canvas Wrapper */
.chart-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.chart-wrapper {
    position: relative;
    height: 380px;
    width: 100%;
}

/* Modal Overlay */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
    backdrop-filter: blur(2px);
}

.modal-backdrop.active {
    display: flex;
}

.modal-dialog {
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-width: 540px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modalPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-body {
    padding: 1.5rem;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 1rem 1.5rem;
    background-color: var(--bg-subtle);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Credential Display Box */
.cred-box {
    background: linear-gradient(135deg, var(--primary-light), var(--bg-surface));
    border: 2px dashed var(--primary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin: 1rem 0;
    text-align: center;
}

.cred-row {
    margin: 0.75rem 0;
}

.cred-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.cred-val {
    font-family: monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 0.08em;
    user-select: all;
}

/* Footer */
.app-footer {
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border);
    padding: 1.5rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: auto;
}

/* Mobile Bottom Navigation */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border);
    z-index: 60;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.mobile-nav-inner {
    display: flex;
    justify-content: space-around;
    padding: 0.4rem 0.5rem;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    gap: 0.2rem;
}

.mobile-nav-item.active {
    color: var(--primary);
    font-weight: 600;
}

@media (max-width: 768px) {
    .mobile-nav {
        display: block;
    }
    .app-main {
        padding-bottom: 5rem;
    }
    .desktop-nav {
        display: none;
    }
    .header-inner {
        padding: 0.6rem 1rem;
    }
    .chart-wrapper {
        height: 300px;
    }
}
