* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

:root {
    --primary-blue: #2196F3;
    --dark-blue: #1976D2;
    --light-blue: #E3F2FD;
    --primary-green: #4CAF50;
    --dark-green: #2E7D32;
    --light-green: #C8E6C9;
    --accent-yellow: #FFD54F;
    --accent-red: #FF7043;
    --accent-orange: #FF9800;
    --accent-purple: #7E57C2;
    --accent-pink: #E91E63;
    --accent-teal: #009688;
    --background: #F5F9F5;
    --card-white: #FFFFFF;
    --text-dark: #2C3E50;
    --text-light: #666666;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    --border-radius: 12px;
}

* {
    -webkit-tap-highlight-color: transparent;
    -webkit-focus-ring-color: transparent;
}

*:focus { outline: none !important; }

/* FIX 1: Body height fix for Android */
html {
    height: 100%;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    background-color: var(--background);
    color: var(--text-dark);
    height: 100vh;
    min-height: -webkit-fill-available; /* Fix for mobile Safari/Android */
    overflow: hidden;
    position: fixed; /* Prevent address bar show/hide issues */
    width: 100%;
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(200, 230, 201, 0.3) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(33, 150, 243, 0.1) 0%, transparent 20%);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: none; /* Prevent pull-to-refresh */
}

/* Prevent auto-zoom on input focus in Android */
input, select, textarea {
    font-size: 16px !important;
}

/* Splash Screen */
#splash {
  position: fixed;
  inset: 0;
  background: #2196F3;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  width: 100vw;
  height: 100vh;
  height: -webkit-fill-available; /* Android fix */
}

#splash img {
   width: 100%;
  height: 100%;
  object-fit: cover;
  animation: zoomIn 1s ease;
}

@keyframes zoomIn {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* Navbar */
.navbar {
    background: linear-gradient(135deg, var(--dark-blue), var(--primary-blue));
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
    height: 60px;
    min-height: 60px; /* Prevent collapse */
    position: relative;
    z-index: 100;
    width: 100%;
}

.navbar-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
}

.hamburger-btn {
    background: none;
    border: none;
    color: white;
    font-size: 22px;
    cursor: pointer;
    padding: 5px;
    border-radius: 6px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;
}

.hamburger-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh; /* Use vh instead of % */
    max-height: 100vh;
    background: linear-gradient(135deg, var(--dark-blue), var(--primary-blue));
    color: white;
    box-shadow: 5px 0 20px rgba(0, 0, 0, 0.2);
    transition: left 0.3s ease;
    z-index: 200;
    overflow-y: auto;
    overflow-x: hidden;
    padding-top: 60px;
    padding-bottom: env(safe-area-inset-bottom, 20px); /* Safe area for Android */
    -webkit-overflow-scrolling: touch;
}

.navbar.green-mode {
    background: linear-gradient(135deg, var(--dark-green), var(--primary-green));
}

.sidebar.green-bg {
    background: linear-gradient(180deg, var(--dark-green), var(--primary-green));
}

.sidebar.active {
    left: 0;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    display: none;
}

.sidebar-overlay.active {
    display: block;
}

.sidebar-header {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 10px;
}

.sidebar-header h3 {
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.sidebar-menu {
    list-style: none;
    padding: 0 15px;
}

.sidebar-item {
    margin-bottom: 5px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 14px 18px;
    color: white;
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.3s;
    font-size: 15px;
    font-weight: 500;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-link:active, .sidebar-link.active {
    background: rgba(255, 255, 255, 0.15);
}

.sidebar-link i {
    font-size: 18px;
    width: 24px;
}

.sidebar-link.home i {
    color: #FFD700;
}

.sidebar-link.normal i {
    color: var(--light-blue);
}

.sidebar-link.grocery i {
    color: var(--accent-yellow);
}

.sidebar-link.converter i {
    color: var(--accent-orange);
}

.sidebar-link.history i {
    color: var(--light-green);
}

.sidebar-link.help i {
    color: #BB86FC;
}

/* FIX 2: Main container height calculation */
.container {
    height: calc(100vh - 60px) !important;
    min-height: calc(100vh - 60px);
    max-height: calc(100vh - 60px);
    padding: 15px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* FIX 3: Calculator container height */
.calculator-container {
    background-color: var(--card-white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    height: 100% !important;
    min-height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Home Screen */

.home-screen {
    padding: 15px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* ADD THIS */
}

.app-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 5px;
    flex: 1;
    min-height: 0;
    align-content: start; /* Start grid from top, don't stretch */
    grid-auto-rows: min-content; /* Don't let rows expand too much */
}

.app-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 5px;
    border-radius: 12px;
    background-color: #f9f9f9;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid #eee;
    /* REMOVED: min-height: 120px; */
    height: auto; /* Let content determine height */
    justify-content: center;
    min-height: 100px; /* Minimum but not too big */
    max-height: 130px; /* Maximum limit */
    overflow: hidden;
}
.app-item:active {
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
    background-color: white;
}

.app-icon {
    width: 50px; /* Reduced from 60px */
    height: 50px; /* Reduced from 60px */
    border-radius: 12px; /* Reduced from 15px */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px; /* Reduced from 28px */
    margin-bottom: 8px; /* Reduced from 10px */
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
}

.app-icon.blue {
    background: linear-gradient(135deg, var(--primary-blue), var(--dark-blue));
    color: white;
}

.app-icon.green {
    background: linear-gradient(135deg, var(--primary-green), var(--dark-green));
    color: white;
}

.app-icon.orange {
    background: linear-gradient(135deg, var(--accent-orange), #F57C00);
    color: white;
}

.app-icon.purple {
    background: linear-gradient(135deg, var(--accent-purple), #512DA8);
    color: white;
}

.app-name {
    font-size: 13px; /* Reduced from 14px */
    font-weight: 600;
    color: var(--text-dark);
    text-align: center;
    line-height: 1.2;
    padding: 0 3px;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Limit text to 2 lines */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.quick-info {
    margin-top: 15px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.info-card {
    background: linear-gradient(135deg, var(--light-blue), #E8F5E9);
    border-radius: 10px;
    padding: 12px; /* Reduced from 15px */
    display: flex;
    align-items: center;
    gap: 12px;
    border-left: 4px solid var(--primary-blue);
    min-height: auto; /* Don't force height */
}

.info-icon {
    font-size: 20px; /* Reduced from 24px */
    color: var(--primary-blue);
    flex-shrink: 0;
}

.info-text {
    font-size: 13px; /* Reduced from 14px */
    color: var(--text-dark);
    font-weight: 500;
    line-height: 1.3;
}

.footer {
    text-align: center;
    padding: 10px 0;
    color: var(--text-light);
    font-size: 11px; /* Reduced from 12px */
    margin-top: auto; /* Push to bottom */
    border-top: 1px solid #eee;
    padding-top: 10px;
    flex-shrink: 0; 
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}


/* For short screens */
@media (max-height: 700px) {
    .home-screen {
        padding: 10px;
    }
    
    .app-grid {
        gap: 10px;
        margin-top: 5px;
    }
    
    .app-item {
        padding: 10px 5px;
        min-height: 95px;
        max-height: 115px;
    }
    
    .app-icon {
        width: 46px;
        height: 46px;
        font-size: 20px;
        margin-bottom: 7px;
    }
    
    .app-name {
        font-size: 12px;
    }
    
    .quick-info {
        margin-top: 10px;
        margin-bottom: 8px;
    }
    
    .info-card {
        padding: 10px;
        gap: 10px;
    }
    
    .info-icon {
        font-size: 18px;
    }
    
    .info-text {
        font-size: 12px;
    }
    
    .footer {
        padding-top: 8px;
        font-size: 10px;
    }
}

/* For landscape mode */
@media (orientation: landscape) and (max-height: 500px) {
    .home-screen {
        padding: 8px;
    }
    
    .app-grid {
        grid-template-columns: repeat(4, 1fr); /* 4 columns in landscape */
        gap: 8px;
    }
    
    .app-item {
        min-height: 80px;
        max-height: 100px;
        padding: 8px 3px;
    }
    
    .app-icon {
        width: 36px;
        height: 36px;
        font-size: 18px;
        margin-bottom: 4px;
    }
    
    .app-name {
        font-size: 11px;
        -webkit-line-clamp: 1; /* 1 line in landscape */
    }
    
    .quick-info {
        margin-top: 8px;
        margin-bottom: 6px;
    }
    
    .info-card {
        padding: 8px;
        gap: 8px;
    }
}

/* Normal Calculator Styles */
.normal-calculator {
    padding: 15px;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Prevent overflow */
}

.calculator-display {
    background-color: #222;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 15px;
    text-align: right;
    color: white;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    font-family: 'Courier New', monospace;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.calculation {
    font-size: 18px;
    color: #aaa;
    min-height: 25px;
    word-break: break-all;
}

.result {
    font-size: 40px;
    font-weight: 700;
    margin-top: 5px;
    word-break: break-all;
}

/* FIX 5: Calculator buttons grid */
.calculator-buttons {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 10px;
    min-height: 0; /* Critical for Android grid layout */
}

.calc-btn {
    border: none;
    border-radius: 12px;
    font-size: 24px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    min-height: 0;
    -webkit-tap-highlight-color: transparent;
}

.calc-btn:active {
    transform: scale(0.95);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.number {
    background-color: #f5f5f5;
    color: #333;
}

.number:active {
    background-color: #e8e8e8;
}

.zero {
    grid-column: span 2;
}

.operator {
    background-color: var(--primary-blue);
    color: white;
    font-size: 26px;
}

.operator:active {
    background-color: var(--dark-blue);
}

.equals {
    background-color: var(--primary-green);
    color: white;
    grid-row: span 2;
    font-size: 30px;
}

.equals:active {
    background-color: var(--dark-green);
}

.clear {
    background-color: #ff6b6b;
    color: white;
    font-size: 22px;
}

.clear:active {
    background-color: #ff5252;
}

.function {
    background-color: #ffb74d;
    color: white;
    font-size: 22px;
}

.function:active {
    background-color: #ffa726;
}

.backspace {
    background-color: #9c27b0;
    color: white;
    font-size: 22px;
}

.backspace:active {
    background-color: #7b1fa2;
}

/* Grocery Calculator */
.grocery-calculator {
    padding: 15px;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.mode-toggle {
    display: flex;
    background-color: var(--light-green);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 15px;
    position: relative;
}

.mode-slider {
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    background: linear-gradient(90deg, var(--primary-green), var(--dark-green));
    border-radius: 8px;
    transition: transform 0.3s ease;
}

.mode-btn {
    flex: 1;
    text-align: center;
    padding: 10px 5px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 2;
    color: var(--dark-green);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    -webkit-tap-highlight-color: transparent;
}

.mode-btn.active {
    color: white;
}

.input-group {
    margin-bottom: 15px;
}

.input-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--dark-green);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.currency-symbol {
    position: absolute;
    left: 12px;
    font-size: 16px;
    font-weight: 600;
    color: var(--dark-green);
}

.unit-symbol {
    position: absolute;
    right: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-light);
}

.input-field {
    width: 100%;
    padding: 12px 40px;
    font-size: 18px;
    font-weight: 600;
    border: 2px solid var(--light-green);
    border-radius: 8px;
    text-align: center;
    color: var(--text-dark);
    transition: border-color 0.3s;
    -webkit-appearance: none;
    appearance: none;
    background-color: white;
}

.input-field:focus {
    border-color: var(--primary-green);
}

.auto-calculation {
    background-color: var(--light-green);
    border-radius: 8px;
    padding: 10px;
    margin: 10px 0;
    text-align: center;
    font-size: 14px;
    color: var(--dark-green);
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.result-container {
    background: linear-gradient(135deg, var(--primary-green), var(--dark-green));
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    color: white;
    margin-top: 10px;
}

.grocery-result-label {
    font-size: 14px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.grocery-result-value {
    font-size: 28px;
    font-weight: 700;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.mode-content-container {
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.mode-content {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 15px;
}

.btn {
    padding: 12px;
    border-radius: 8px;
    border: none;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-calculate {
    background: linear-gradient(135deg, var(--accent-yellow), var(--accent-orange));
    color: var(--text-dark);
}

.btn-clear {
    background: linear-gradient(135deg, #E0E0E0, #BDBDBD);
    color: var(--text-dark);
}

.btn:active {
    transform: translateY(0);
}

/* Android-specific fixes */
@media (max-width: 480px) {
    .container {
        padding: 10px;
    }
    
    .calculator-buttons {
        gap: 8px;
    }
    
    .calc-btn {
        font-size: 22px;
    }
    
    .result {
        font-size: 32px;
    }
}


/* Fix for Android address bar show/hide */
@media (max-height: 700px) {
    body {
        height: 100%;
    }
    
    .container {
        height: calc(100% - 60px) !important;
    }
}

/* Safe area support for notches */
@supports (padding-top: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .navbar {
        padding-top: max(15px, env(safe-area-inset-top));
        height: calc(60px + env(safe-area-inset-top));
    }
    
    .sidebar {
        padding-top: calc(60px + env(safe-area-inset-top));
    }
}

/* Prevent text selection on Android */
* {
    -webkit-user-select: none;
    user-select: none;
}

input, textarea {
    -webkit-user-select: text;
    user-select: text;
}