/* ============================================
   Calculator-Cloud.com - Advanced Mobile CSS
   Dark mode, gestures, voice, history, and more
   ============================================ */

/* ============================================
   CSS CUSTOM PROPERTIES FOR THEMING
   ============================================ */

:root {
    /* Light mode (default) */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #888888;
    --border-color: #dee2e6;
    --border-color-light: #e9ecef;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --accent-color: #053b7d;
    --accent-light: #0a5a9c;
    --success-color: #28a745;
    --error-color: #dc3545;
    --warning-color: #ffc107;
    --input-bg: #ffffff;
    --card-bg: #ffffff;
    --nav-bg: linear-gradient(135deg, #053b7d 0%, #0a5a9c 100%);
    --overlay-bg: rgba(0, 0, 0, 0.5);
}

/* ============================================
   DARK MODE STYLES
   ============================================ */

.dark-mode {
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #808080;
    --border-color: #404040;
    --border-color-light: #333333;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --accent-color: #4a90d9;
    --accent-light: #6aa8ec;
    --input-bg: #2d2d2d;
    --card-bg: #1e1e1e;
    --nav-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --overlay-bg: rgba(0, 0, 0, 0.7);
}

/* Apply dark mode to all elements */
.dark-mode body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.dark-mode header,
.dark-mode .header {
    background: var(--nav-bg) !important;
}

.dark-mode .calculator-container,
.dark-mode .calculator-card {
    background-color: var(--card-bg);
    border-color: var(--border-color);
    box-shadow: 0 4px 20px var(--shadow-color);
}

.dark-mode input,
.dark-mode select,
.dark-mode textarea {
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.dark-mode input:focus,
.dark-mode select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.2);
}

.dark-mode #result,
.dark-mode .result {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.dark-mode #result h3,
.dark-mode .result h3 {
    color: var(--accent-light);
}

.dark-mode #result table th {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.dark-mode #result table td {
    color: var(--text-secondary);
    border-color: var(--border-color-light);
}

.dark-mode .category-header {
    background: var(--nav-bg);
}

.dark-mode .calculators-grid .calculator-card {
    background-color: var(--card-bg);
    border-color: var(--border-color);
}

.dark-mode .calculator-card:hover {
    box-shadow: 0 8px 30px var(--shadow-color);
}

.dark-mode .calculator-card-title,
.dark-mode .calculator-card h3 {
    color: var(--text-primary);
}

.dark-mode .calculator-card p,
.dark-mode .calculator-card-description {
    color: var(--text-secondary);
}

.dark-mode footer {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.dark-mode a {
    color: var(--accent-light);
}

.dark-mode .mobile-bottom-nav {
    background: var(--nav-bg);
}

.dark-mode .mobile-search-modal {
    background-color: var(--bg-primary);
}

.dark-mode .mobile-search-input {
    background-color: var(--input-bg);
    color: var(--text-primary);
}

.dark-mode .mobile-search-result-item {
    border-color: var(--border-color);
    color: var(--text-primary);
}

.dark-mode .mobile-search-result-item:active {
    background-color: var(--bg-tertiary);
}

.dark-mode .mobile-search-result-category {
    color: var(--text-muted);
}

/* Dark mode for scientific calculator */
.dark-mode .scidis,
.dark-mode #display {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.dark-mode .scinm,
.dark-mode .sciop {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.dark-mode .scifunc {
    background: linear-gradient(145deg, #2d3748 0%, #1a202c 100%);
}

/* Dark mode floating toggle button */
.dark-mode-float-toggle {
    display: none;
    position: fixed;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 10px var(--shadow-color);
    cursor: pointer;
    z-index: 9990;
    font-size: 18px;
    transition: all 0.3s ease;
}

.dark-mode-float-toggle:hover {
    transform: scale(1.1);
}

@media (min-width: 769px) {
    .dark-mode-float-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============================================
   SWIPE GESTURE STYLES
   ============================================ */

.swipe-hint {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom, 0));
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    z-index: 9990;
    pointer-events: none;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.swipe-hint.show {
    opacity: 1;
    transform: translateY(0);
}

.swipe-hint-content {
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    backdrop-filter: blur(10px);
}

.swipe-hint-content i {
    font-size: 18px;
    animation: swipe-hint-anim 1.5s ease-in-out infinite;
}

.swipe-hint-content i:first-child {
    animation-direction: alternate;
}

.swipe-hint-content i:last-child {
    animation-direction: alternate-reverse;
}

@keyframes swipe-hint-anim {
    0%, 100% { transform: translateX(0); opacity: 1; }
    50% { transform: translateX(-5px); opacity: 0.5; }
}

/* ============================================
   CALCULATOR HISTORY PANEL
   ============================================ */

.history-fab {
    display: none;
    position: fixed;
    bottom: calc(150px + env(safe-area-inset-bottom, 0));
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
    color: white;
    font-size: 20px;
    border: none;
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.4);
    cursor: pointer;
    z-index: 9996;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.history-fab:active {
    transform: scale(0.9);
}

@media (max-width: 768px) {
    .history-fab {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

.history-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 400px;
    background: var(--bg-primary);
    z-index: 10002;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0 30px var(--shadow-color);
}

.history-panel.show {
    transform: translateX(0);
}

.history-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: var(--accent-color);
    color: white;
}

.history-panel-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.history-panel-header h3 i {
    margin-right: 10px;
}

.history-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 5px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.history-close:hover {
    opacity: 1;
}

.history-panel-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.history-item {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.history-item:active {
    background: var(--bg-secondary);
}

.history-item-calc {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 15px;
    margin-bottom: 4px;
}

.history-item-result {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 4px;
    word-break: break-word;
}

.history-item-time {
    color: var(--text-muted);
    font-size: 12px;
}

.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}

.history-empty i {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.3;
}

.history-empty p {
    font-size: 16px;
    margin: 0 0 8px;
}

.history-empty small {
    font-size: 13px;
}

.history-panel-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.history-clear-btn {
    width: 100%;
    padding: 12px;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.history-clear-btn:active {
    opacity: 0.8;
}

/* ============================================
   VOICE INPUT STYLES
   ============================================ */

.voice-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.voice-input-wrapper input {
    padding-right: 50px !important;
}

.voice-input-btn {
    position: absolute;
    right: 8px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-color);
    color: white;
    border: none;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.voice-input-btn:active {
    transform: scale(0.9);
}

.voice-input-btn.listening {
    background: var(--error-color);
    animation: pulse-recording 1.5s ease-in-out infinite;
}

.voice-input-btn .recording {
    animation: blink 0.8s ease-in-out infinite;
}

@keyframes pulse-recording {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4); }
    50% { box-shadow: 0 0 0 12px rgba(220, 53, 69, 0); }
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.voice-listening-ui {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    z-index: 10003;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.voice-listening-ui.show {
    opacity: 1;
    visibility: visible;
}

.voice-listening-content {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 300px;
    width: 90%;
    box-shadow: 0 10px 40px var(--shadow-color);
}

.voice-listening-indicator {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}

.voice-listening-indicator span {
    width: 8px;
    height: 40px;
    background: var(--accent-color);
    border-radius: 4px;
    animation: voice-wave 1s ease-in-out infinite;
}

.voice-listening-indicator span:nth-child(2) {
    animation-delay: 0.1s;
}

.voice-listening-indicator span:nth-child(3) {
    animation-delay: 0.2s;
}

@keyframes voice-wave {
    0%, 100% { transform: scaleY(0.5); }
    50% { transform: scaleY(1); }
}

.voice-listening-text {
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 500;
    margin: 0 0 20px;
    min-height: 27px;
}

.voice-listening-cancel {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: none;
    padding: 10px 30px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.voice-listening-cancel:active {
    background: var(--border-color);
}

/* ============================================
   ENHANCED FORM VALIDATION STYLES
   ============================================ */

.input-validation-icon {
    position: absolute;
    right: 55px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    pointer-events: none;
}

.voice-input-wrapper .input-validation-icon {
    right: 55px;
}

.validation-message {
    position: absolute;
    bottom: -22px;
    left: 0;
    right: 0;
    font-size: 12px;
    color: var(--error-color);
    animation: fadeIn 0.2s ease;
}

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

/* Enhanced input states */
.input-error {
    border-color: var(--error-color) !important;
    background-color: rgba(220, 53, 69, 0.05) !important;
}

.input-success {
    border-color: var(--success-color) !important;
    background-color: rgba(40, 167, 69, 0.05) !important;
}

.input-warning {
    border-color: var(--warning-color) !important;
    background-color: rgba(255, 193, 7, 0.05) !important;
}

/* ============================================
   QUICK ACTION MENU STYLES
   ============================================ */

.quick-action-menu {
    position: fixed;
    bottom: calc(150px + env(safe-area-inset-bottom, 0));
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9997;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.quick-action-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.quick-action-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 25px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 4px 15px var(--shadow-color);
    transition: all 0.2s ease;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.quick-action-item:active {
    transform: scale(0.95);
}

.quick-action-item i {
    width: 20px;
    text-align: center;
    color: var(--accent-color);
}

/* ============================================
   ACTION SHEET STYLES
   ============================================ */

.action-sheet {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    z-index: 10004;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.action-sheet.show {
    opacity: 1;
    visibility: visible;
}

.action-sheet-content {
    background: var(--card-bg);
    width: 100%;
    max-width: 500px;
    border-radius: 15px 15px 0 0;
    padding: 10px 0;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.action-sheet.show .action-sheet-content {
    transform: translateY(0);
}

.action-sheet-item {
    padding: 18px 25px;
    font-size: 16px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    transition: background 0.2s;
}

.action-sheet-item:active {
    background: var(--bg-secondary);
}

.action-sheet-item i {
    width: 24px;
    text-align: center;
    color: var(--accent-color);
}

.action-sheet-item.cancel {
    margin-top: 8px;
    border-top: 1px solid var(--border-color);
    color: var(--error-color);
    justify-content: center;
    font-weight: 600;
}

/* ============================================
   LANDSCAPE MODE ADJUSTMENTS
   ============================================ */

body.landscape .history-panel {
    max-width: 50%;
}

body.landscape .voice-listening-content {
    padding: 25px;
}

body.landscape .quick-action-menu {
    bottom: calc(70px + env(safe-area-inset-bottom, 0));
}

body.landscape .history-fab {
    bottom: calc(70px + env(safe-area-inset-bottom, 0));
}

/* ============================================
   REDUCED MOTION SUPPORT
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .voice-listening-indicator span {
        animation: none;
        transform: scaleY(0.7);
    }

    .swipe-hint-content i {
        animation: none;
    }
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */

@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --text-primary: #000000;
    }

    .dark-mode {
        --border-color: #ffffff;
        --text-primary: #ffffff;
    }

    input, select, button {
        border-width: 2px;
    }
}

/* ============================================
   PRINT STYLES (HIDE MOBILE UI)
   ============================================ */

@media print {
    .mobile-bottom-nav,
    .history-fab,
    .history-panel,
    .quick-action-menu,
    .mobile-fab,
    .scroll-to-top,
    .voice-input-btn,
    .swipe-hint,
    .dark-mode-float-toggle {
        display: none !important;
    }
}
