/* ==========================================================================
   Accounting Calculator & Header Badge Styles
   Sahakari CBS
   ========================================================================== */

/* Combined Accounting Calculator & Last Result Button */
.header-calc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 30px !important;
    min-height: 30px !important;
    max-height: 30px !important;
    box-sizing: border-box !important;
    border-radius: var(--radius-sm, 4px) !important;
    border: 1px solid var(--border-subtle, #cbd5e1);
    background: #ffffff;
    color: #475569;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.15s ease;
    outline: none;
    text-decoration: none;
    padding: 0 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    vertical-align: middle;
    gap: 6px;
    line-height: 1 !important;
}

.header-calc-btn:not(.has-result) {
    width: 30px !important;
    padding: 0 !important;
}

.header-calc-btn:hover {
    background: #f8fafc;
    color: #0f172a;
    border-color: var(--border-strong, #cbd5e1);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.header-calc-btn.has-result {
    width: auto !important;
    max-width: 220px;
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border-color: #86efac;
    color: #166534;
    padding: 0 8px !important;
    box-shadow: 0 1px 2px rgba(22, 101, 52, 0.08);
}

.header-calc-btn.has-result:hover {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    border-color: #4ade80;
    color: #14532d;
    box-shadow: 0 2px 4px rgba(22, 101, 52, 0.12);
}

.header-calc-btn .calc-icon {
    font-size: 0.75rem;
    color: inherit;
    flex-shrink: 0;
    line-height: 1;
}

.header-calc-btn.has-result .calc-icon {
    color: #15803d;
}

.header-calc-btn .calc-btn-val {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, monospace;
    font-size: 0.74rem;
    font-weight: 800;
    color: #0f172a;
    line-height: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 130px;
}

.header-calc-btn .calc-btn-copy {
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    width: 18px;
    height: 18px;
    color: #15803d;
    font-size: 0.72rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    transition: all 0.15s ease;
    line-height: 1;
    flex-shrink: 0;
}

.header-calc-btn .calc-btn-copy:hover {
    color: #047857;
    background: rgba(22, 101, 52, 0.12);
    transform: scale(1.12);
}

/* Backward compatibility for header-calc-result-pill */
.header-calc-result-pill {
    display: none !important;
}

/* Pulsing highlight animation when calculator closes and updates result */
@keyframes calcPillFlash {
    0% {
        transform: scale(0.92);
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
        border-color: #22c55e;
        background: #bbf7d0;
    }
    50% {
        transform: scale(1.08);
        box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
        border-color: #16a34a;
        background: #86efac;
    }
    100% {
        transform: scale(1);
        box-shadow: 0 1px 2px rgba(22, 101, 52, 0.08);
    }
}

.calc-pill-highlight {
    animation: calcPillFlash 0.85s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Variables */
:root {
    --calc-drawer-width: 285px; /* Matches --sidebar-width (285px) */
}

/* Push main content to the left when calculator is open (No blur, No covering) */
@media (min-width: 769px) {
    html.calc-drawer-open .main-content {
        margin-right: var(--calc-drawer-width) !important;
        width: calc(100% - var(--sidebar-width) - var(--calc-drawer-width)) !important;
        transition: margin-right 0.25s cubic-bezier(0.16, 1, 0.3, 1), 
                    width 0.25s cubic-bezier(0.16, 1, 0.3, 1), 
                    margin-left 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* No backdrop blur or dimming - keep main window 100% visible and interactive */
.accounting-calc-backdrop {
    display: none !important;
    pointer-events: none !important;
    backdrop-filter: none !important;
    background: transparent !important;
}

/* Right-Side Docked Calculator Bar (Matches Left Sidebar Aesthetic) */
.accounting-calc-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--calc-drawer-width);
    max-width: 100vw;
    background: var(--sidebar-bg, #27272a);
    border-left: 1px solid var(--sidebar-divider, #3f3f46);
    box-shadow: none !important; /* Flat design without shadow to match sidebar */
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateX(105%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--sidebar-text, #f4f4f5);
    outline: none;
}

.accounting-calc-drawer.open {
    transform: translateX(0);
}

/* Drawer Header */
.calc-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--sidebar-bg, #27272a);
    color: var(--sidebar-text, #f4f4f5);
    border-bottom: 1px solid var(--sidebar-divider, #3f3f46);
    flex-shrink: 0;
}

.calc-drawer-title-area {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.calc-drawer-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--border-radius);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #e4e4e7;
    font-size: 0.82rem;
    flex-shrink: 0;
}

.calc-drawer-titles {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.calc-drawer-heading {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--sidebar-text, #f4f4f5);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calc-drawer-sub {
    font-size: 0.62rem;
    color: #a1a1aa;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calc-drawer-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.calc-drawer-btn {
    background: transparent;
    border: 1px solid var(--sidebar-divider, #3f3f46);
    color: #a1a1aa;
    width: 28px;
    height: 28px;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.calc-drawer-btn:hover {
    background: var(--sidebar-hover, #3f3f46);
    color: #ffffff;
    border-color: #52525b;
}

.calc-drawer-close-btn {
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.calc-drawer-close-btn:hover {
    background: #ef4444;
    color: #ffffff;
    border-color: #ef4444;
}

/* Mode & Memory Bar */
.calc-mode-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: #202023;
    border-bottom: 1px solid var(--sidebar-divider, #3f3f46);
    font-size: 0.68rem;
    flex-shrink: 0;
}

.calc-memory-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #a1a1aa;
    font-weight: 600;
    font-size: 0.66rem;
}

.calc-memory-indicator.active {
    color: #60a5fa;
}

.calc-format-toggle {
    display: inline-flex;
    background: #18181b;
    border: 1px solid var(--sidebar-divider, #3f3f46);
    border-radius: 4px;
    padding: 2px;
    gap: 2px;
}

.calc-format-btn {
    background: transparent;
    border: none;
    font-size: 0.62rem;
    font-weight: 600;
    color: #a1a1aa;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.12s ease;
}

.calc-format-btn:hover {
    color: #ffffff;
}

.calc-format-btn.active {
    background: #3f3f46;
    color: #ffffff;
    font-weight: 700;
}

/* Display Screen */
.calc-display-section {
    background: #18181b;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    color: #ffffff;
    border-bottom: 1px solid var(--sidebar-divider, #3f3f46);
    position: relative;
    flex-shrink: 0;
}

.calc-expression-tape {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, monospace;
    font-size: 0.78rem;
    color: #cbd5e1;
    min-height: 20px;
    text-align: right;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
    user-select: text;
    cursor: default;
    padding-bottom: 2px;
}

.calc-expression-tape::-webkit-scrollbar {
    height: 3px;
}

.calc-expression-tape::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.calc-main-display {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, monospace;
    font-size: 1.65rem;
    font-weight: 700;
    color: #ffffff;
    text-align: right;
    line-height: 1.2;
    margin: 2px 0 4px 0;
    letter-spacing: -0.02em;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    word-break: break-all;
    user-select: text;
}

.calc-main-display::-webkit-scrollbar {
    display: none;
}

.calc-words-preview {
    font-size: 0.62rem;
    color: #71717a;
    text-align: right;
    min-height: 15px;
    line-height: 1.2;
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Quick Tools Strip (Copy & Paste) */
.calc-tools-strip {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    padding: 6px 12px;
    background: #202023;
    border-bottom: 1px solid var(--sidebar-divider, #3f3f46);
    flex-shrink: 0;
}

.calc-tool-btn {
    background: #27272a;
    border: 1px solid var(--sidebar-divider, #3f3f46);
    border-radius: 5px;
    color: #d4d4d8;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 5px 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.12s ease;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 5px;
    user-select: none;
}

.calc-tool-btn:hover {
    background: #3f3f46;
    border-color: #52525b;
    color: #ffffff;
}

.calc-tool-btn:active {
    background: #18181b;
}

.calc-tool-btn.action-copy {
    color: #86efac;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.calc-tool-btn.action-copy:hover {
    background: rgba(34, 197, 94, 0.16);
    border-color: rgba(34, 197, 94, 0.4);
    color: #ffffff;
}

.calc-tool-btn.action-paste {
    color: #93c5fd;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.25);
}

.calc-tool-btn.action-paste:hover {
    background: rgba(59, 130, 246, 0.16);
    border-color: rgba(59, 130, 246, 0.4);
    color: #ffffff;
}

/* Main Keypad with Clear High-Contrast Borders */
.calc-keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    padding: 8px 10px;
    background: var(--sidebar-bg, #27272a);
    flex-shrink: 0;
    border-bottom: 1px solid var(--sidebar-divider, #3f3f46);
}

.calc-key {
    background: #323236;
    border: 1.5px solid #52525b; /* Clear high-contrast border without neon */
    border-radius: 6px;
    height: 38px;
    font-size: 0.98rem;
    font-weight: 600;
    color: #f4f4f5;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: all 0.1s ease;
    box-shadow: none;
}

.calc-key:hover {
    background: #3f3f46;
    border-color: #71717a;
    color: #ffffff;
}

.calc-key:active,
.calc-key.key-active-flash {
    background: #52525b;
    border-color: #a1a1aa;
}

/* Functional Key Variations */
.calc-key.key-op {
    background: #1e293b;
    border: 1.5px solid #3b82f6; /* Clear blue border for contrast */
    color: #93c5fd;
    font-weight: 700;
    font-size: 1.05rem;
}

.calc-key.key-op:hover {
    background: #2563eb;
    border-color: #60a5fa;
    color: #ffffff;
}

.calc-key.key-op.active-op {
    background: #2563eb;
    color: #ffffff;
    border-color: #93c5fd;
}

.calc-key.key-mem {
    background: #202023;
    border: 1.5px solid #3f3f46;
    color: #a1a1aa;
    font-size: 0.74rem;
    font-weight: 700;
}

.calc-key.key-mem:hover {
    background: #323236;
    border-color: #52525b;
    color: #f4f4f5;
}

.calc-key.key-clear {
    background: #2f191d;
    border: 1.5px solid #ef4444; /* Clean contrast red border */
    color: #fca5a5;
    font-weight: 700;
}

.calc-key.key-clear:hover {
    background: #dc2626;
    border-color: #f87171;
    color: #ffffff;
}

.calc-key.key-equals {
    background: #2563eb;
    border: 1.5px solid #60a5fa;
    color: #ffffff;
    font-size: 1.25rem;
    font-weight: 700;
}

.calc-key.key-equals:hover {
    background: #1d4ed8;
    border-color: #93c5fd;
}

.calc-key.key-equals:active,
.calc-key.key-equals.key-active-flash {
    background: #1e40af;
    border-color: #bfdbfe;
}

/* History Section */
.calc-history-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 100px;
    background: #202023;
    border-top: 1px solid var(--sidebar-divider, #3f3f46);
    overflow: hidden;
}

.calc-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 10px;
    background: var(--sidebar-bg, #27272a);
    border-bottom: 1px solid var(--sidebar-divider, #3f3f46);
    font-size: 0.68rem;
    font-weight: 600;
    color: #a1a1aa;
}

.calc-history-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.calc-hist-action-btn {
    background: #323236;
    border: 1px solid #52525b;
    color: #d4d4d8;
    font-size: 0.64rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.12s ease;
}

.calc-hist-action-btn:hover {
    background: #3f3f46;
    border-color: #71717a;
    color: #ffffff;
}

.calc-hist-action-btn.btn-clear-hist {
    border-color: #7f1d1d;
    color: #fca5a5;
}

.calc-hist-action-btn.btn-clear-hist:hover {
    background: #dc2626;
    border-color: #ef4444;
    color: #ffffff;
}

.calc-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scrollbar-width: thin;
    scrollbar-color: #3f3f46 #202023;
}

.calc-history-list::-webkit-scrollbar {
    width: 4px;
}

.calc-history-list::-webkit-scrollbar-track {
    background: #202023;
}

.calc-history-list::-webkit-scrollbar-thumb {
    background: #3f3f46;
    border-radius: 4px;
}

.calc-history-list::-webkit-scrollbar-thumb:hover {
    background: #52525b;
}

.calc-history-item {
    background: var(--sidebar-bg, #27272a);
    border: 1px solid var(--sidebar-divider, #3f3f46);
    border-radius: 5px;
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    cursor: pointer;
    transition: all 0.12s ease;
}

.calc-history-item:hover {
    border-color: #52525b;
    background: #323236;
}

.calc-hist-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.62rem;
    color: #71717a;
}

.calc-hist-time {
    font-family: monospace;
    color: #71717a;
}

.calc-hist-expr {
    font-size: 0.7rem;
    color: #a1a1aa;
    font-family: monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calc-hist-res-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.calc-hist-res {
    font-size: 0.88rem;
    font-weight: 700;
    color: #f4f4f5;
    font-family: monospace;
}

.calc-hist-copy-btn {
    background: transparent;
    border: none;
    color: #71717a;
    font-size: 0.7rem;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: all 0.12s ease;
}

.calc-hist-copy-btn:hover {
    color: #ffffff;
    background: #3f3f46;
}

.calc-history-empty {
    text-align: center;
    color: #71717a;
    font-size: 0.72rem;
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.calc-history-empty i {
    color: #52525b !important;
}

/* Toast for quick copy feedback */
.calc-copy-toast {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: #18181b;
    border: 1px solid var(--sidebar-divider, #3f3f46);
    color: #f4f4f5;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: var(--border-radius);
    pointer-events: none;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 10001;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.calc-copy-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

@media (max-width: 480px) {
    .accounting-calc-drawer {
        width: 100vw;
    }
}
