:root {
    --primary: #00f2fe;
    --secondary: #4facfe;
    --bg: #0a0a0c;
    --card-bg: rgba(255, 255, 255, 0.05);
    --text: #ffffff;
    --text-dim: #a0a0a0;
    --glass: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    height: 100dvh;
    /* Dynamic viewport height */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Strict no-scroll */
    position: fixed;
    width: 100%;
}

.dashboard {
    padding: 0 4px;
    /* Reduced side padding to give more room to the cards */
    padding-top: calc(0.15rem + env(safe-area-inset-top));
    padding-bottom: calc(0.1rem + env(safe-area-inset-bottom));
    height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 0.1rem;
    /* Slightly increased gap for better vertical breathing room */
    max-width: 600px;
    /* High max-width to allow growth on wider screens */
    margin: 0 auto;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}

header {
    margin-bottom: 0.05rem;
    /* Shrunk spacing */
}

.header-main {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.header-content-grid {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.header-content-grid h1 {
    font-size: 0.9rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
    letter-spacing: -0.5px;
}

#local-timer {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    font-family: 'Courier New', Courier, monospace;
}

#country-tag {
    font-size: 0.6rem;
    color: var(--primary);
    /* Matched to timer color */
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.subtitle {
    font-size: 0.65rem;
    margin: 0;
    opacity: 0.8;
}

.disclaimer-bottom {
    font-size: 0.5rem;
    /* Reduced to fit mobile */
    color: var(--text);
    /* Use system text color */
    background: rgba(45, 90, 39, 0.15);
    /* Subtle medical green background */
    border: 1px dashed rgba(255, 215, 0, 0.4);
    padding: 3px;
    border-radius: 6px;
    text-align: center;
    line-height: 1.15;
    margin-top: 2px;
    width: 100%;
    box-sizing: border-box;
    font-weight: 600;
    flex-shrink: 0;
}

#temp-card {
    border-left: 3px solid #ff5722;
    grid-column: span 2;
    height: 28px !important;
    /* Slightly taller for readability */
    min-height: 28px !important;
    padding: 0 0.6rem !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    background: rgba(255, 87, 34, 0.05);
    /* Subtle tint */
    border-radius: 6px;
    margin-top: 0.1rem;
}

#temp-card h3 {
    margin: 0;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
}

#temp-card .stat-value {
    font-size: 0.9rem;
    margin: 0;
    font-weight: 700;
    color: #fff;
}

#temp-card .subtitle {
    font-size: 0.6rem;
    margin: 0;
    opacity: 0.9;
}

.dev-tag {
    font-size: 0.6rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 8px;
}

.dev-tag b {
    color: var(--text);
    font-weight: 700;
}

.wa-link {
    color: #25D366;
    /* Set to primary WhatsApp green natively */
    opacity: 1;
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    /* Subtle light background to pop icon */
    padding: 2px;
    border-radius: 4px;
}

.wa-link:hover {
    transform: scale(1.2);
    box-shadow: 0 0 10px rgba(37, 211, 102, 0.4);
}

.rahmah-logo-container {
    width: 50px;
    height: 50px;
    min-width: 50px;
    min-height: 50px;
    border-radius: 50%;
    position: relative;
    background: #FFD700;
    /* Matching full logo base color */
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3), inset 0 0 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    flex-shrink: 0;
    cursor: pointer;
    perspective: 1000px;
}

.logo-ball {
    width: 200%;
    height: 100%;
    display: flex;
    gap: 0;
    /* Ensuring no space between slices */
    position: absolute;
    left: 0;
    top: 0;
    background: #FFD700;
    /* Unified ball base */
    animation: logo-rotate 12s linear infinite;
    will-change: transform;
}

.logo-slice {
    width: 50%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #FFD700;
    margin-right: -1px;
    /* Slight overlap to prevent sub-pixel gaps */
}

.logo-slice svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.3));
}

/* 3D Spherical Shine Overlay */
.logo-shine {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0) 60%),
        radial-gradient(circle at 65% 65%, rgba(0, 0, 0, 0.25) 0%, rgba(0, 0, 0, 0) 65%),
        inset -5px -5px 15px rgba(0, 0, 0, 0.2),
        inset 5px 5px 15px rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    pointer-events: none;
    z-index: 2;
    border: 0.5px solid rgba(255, 215, 0, 0.2);
    /* Blend the edge */
}

@keyframes logo-rotate {
    0% {
        transform: translateX(0);
    }

    100% {
        transform: translateX(-50%);
    }
}

.rahmah-logo-container:hover .logo-ball {
    animation-duration: 6s;
    /* Spins faster on hover */
}

h1 {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 1px;
    background: linear-gradient(to right, #ffffff, #e0e0e0);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

header .subtitle {
    font-size: 0.7rem;
    opacity: 0.7;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.1rem;
    /* Increase gap slightly to match the dashboard's new rhythm */
    margin: 0;
    flex-shrink: 0;
}

.stat-card {
    background: var(--card-bg);
    backdrop-filter: blur(6px);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.2rem 0.4rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 94px;
    /* Increased by 1.25x (75 * 1.25) */
}

#temp-card {
    grid-column: span 2;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    height: 60px !important;
    /* Redistributed height to Trend/Stats */
    min-height: 60px !important;
}

.stat-card h3 {
    font-size: 0.55rem;
    text-transform: uppercase;
    color: var(--text-dim);
    margin: 0;
}

.stat-value {
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1;
}

.stat-secondary {
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.8);
    margin: 0;
}

.stat-card .subtitle {
    font-size: 0.52rem;
    color: var(--text-dim);
    margin: 0;
}

/* New Action Card Row (Horizontal Stack) */
.action-row-horizontal {
    display: flex;
    justify-content: space-between;
    gap: 0.2rem;
    margin: 0.1rem 0;
    width: 100%;
}

.action-card {
    flex: 1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 0.5rem 0.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 60px;
    /* Compacted action icons */
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
    outline: none;
}

.action-card:active {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(0.96);
}

.action-card svg {
    fill: #00f2fe;
    /* Exactly match the cyan in screenshot */
    margin-bottom: 2px;
}

.action-card span {
    font-size: 0.58rem;
    font-weight: 500;
    color: #ffffff;
    opacity: 0.9;
}

/* Consolidated Layout Architecture */
.master-bottom-row {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    width: 100%;
    margin-top: 0.05rem;
    flex: 1;
    min-height: 0;
}

.trend-section {
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.35rem 0.45rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
    /* Stretch till end of scan above circle */
    min-height: 0;
}

.trend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.trend-header h3 {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-dim);
    margin: 0;
}

.scan-section {
    width: 100%;
    height: 55px;
    /* Compacted to maintain fixed screen size */
    background: rgba(45, 90, 39, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
}

#camera-container {
    width: 65px;
    /* Proportional to 95px height */
    height: 65px;
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
    border-radius: 50%;
    border: 3px solid var(--primary);
    /* Thicker border for better visibility */
    overflow: hidden;
    background: #000;
}

.scan-button {
    width: 65px;
    /* Balanced with camera size */
    height: 65px;
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
    border-radius: 50%;
    background: #00f2fe;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px rgba(0, 242, 254, 0.5);
    cursor: pointer;
}

.scan-info h2 {
    font-size: 0.95rem;
    color: #00f2fe;
    margin: 0;
}

.chart-legend {
    display: flex;
    gap: 0.5rem;
}

.legend-item {
    font-size: 0.5rem;
    display: flex;
    align-items: center;
    gap: 3px;
    color: var(--text-dim);
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.dot.hr {
    background: var(--primary);
    box-shadow: 0 0 5px var(--primary);
}

.dot.spo2 {
    background: #ffab00;
    box-shadow: 0 0 5px #ffab00;
}

.trend-chart-area {
    width: 100%;
    flex: 1;
    /* Match section growth */
    position: relative;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    min-height: 0;
}

#trend-svg {
    width: 100%;
    height: 100%;
}

.chart-empty {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.6rem;
    color: var(--text-dim);
    text-align: center;
    width: 80%;
}

.action-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.profile-btn {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--text);
    padding: 0.3rem 0.2rem;
    border-radius: 10px;
    font-size: 0.6rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
}

.profile-btn svg {
    width: 16px;
    height: 16px;
    fill: var(--primary);
}

.intel-btn {
    border-color: #ffd70033;
}

/* SOS Button Styles */
.sos-container {
    margin: 0.5rem 0;
    width: 100%;
}

.sos-btn {
    background: rgba(255, 59, 48, 0.1);
    border: 1px solid rgba(255, 59, 48, 0.3);
    color: #ff3b30;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.sos-btn:hover {
    background: rgba(255, 59, 48, 0.2);
    transform: translateY(-2px);
}

.sos-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.sos-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(255, 59, 48, 0.2);
    top: 0;
    left: 0;
    animation: sos-pulse 2s infinite;
    pointer-events: none;
}

@keyframes sos-pulse {
    0% {
        transform: scale(1);
        opacity: 0.5;
    }

    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* Cleaning redundant blocks */

#scan-status {
    font-size: 0.9rem;
    margin-bottom: 0.2rem;
    color: var(--primary);
}

#scan-instruction {
    font-size: 0.65rem;
}

/* Intelligence Modal Styles */
.intel-content {
    width: 95% !important;
    max-width: 550px;
    max-height: 85vh;
    overflow-y: auto;
    padding-top: 1rem !important;
}

.intel-grid {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-top: 1rem;
}

.intel-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 12px;
    padding: 1rem;
    position: relative;
    padding-left: 3.5rem;
}

.intel-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.5rem;
}

.intel-card h4 {
    font-size: 0.9rem;
    color: var(--primary);
    margin: 0 0 0.3rem 0;
}

.intel-card p {
    font-size: 0.7rem;
    color: var(--text-dim);
    line-height: 1.5;
    margin: 0;
}

.intel-card strong {
    color: #fff;
    font-weight: 600;
}

.disclaimer {
    font-size: 0.55rem;
    color: var(--text-dim);
    text-align: center;
    margin-top: 0.5rem;
    padding: 0 1rem;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: #111;
    border: 1px solid var(--glass-border);
    padding: 1.5rem;
    border-radius: 20px;
    width: 85%;
}

.modal-content h2 {
    font-size: 1.1rem;
    margin: 0;
    font-weight: 700;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 1rem;
}

.close-btn {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.close-btn svg {
    width: 18px;
    height: 18px;
}

.close-btn:hover {
    background: rgba(255, 59, 48, 0.1);
    color: #ff3b30;
    transform: rotate(90deg);
}

.form-group {
    margin-top: 1rem;
}

.form-group label {
    font-size: 0.7rem;
    color: var(--text-dim);
    display: block;
    margin-bottom: 0.3rem;
}

.form-group input,
.form-group select {
    width: 100%;
    background: #222;
    border: 1px solid var(--glass-border);
    padding: 0.6rem;
    border-radius: 8px;
    color: white;
}

.history-controls {
    display: flex;
    justify-content: space-around;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.5rem 0;
}

.filter-btn,
.report-btn {
    flex: 1;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.6rem 0.3rem;
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-btn span,
.report-btn span {
    font-size: 0.55rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-btn.active {
    background: rgba(0, 242, 254, 0.1);
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.15);
}

.filter-btn svg,
.report-btn svg {
    width: 20px;
    height: 20px;
}

.report-btn {
    background: rgba(255, 171, 0, 0.08);
    border-color: rgba(255, 171, 0, 0.3);
}

.report-btn:active {
    transform: scale(0.95);
    background: rgba(255, 171, 0, 0.15);
}

.save-btn {
    width: 100%;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    border: none;
    padding: 0.8rem;
    border-radius: 10px;
    color: white;
    font-weight: 700;
    margin-top: 1.5rem;
}