/* 
   CALCULADORA RESCUE V3 - DARK PREMIUM DESIGN
   Fixed Auto-Open, High Contrast, No Clipping.
*/
:root {
  --calc-scale: 1;
  --calc-bg: #1e1e1e; /* Professional Dark Grey */
  --calc-btn-num: #2d2d2d;
  --calc-btn-op: #3d3d3d;
  --calc-accent: #0078d4;
  --calc-text: #ffffff;
  --calc-text-dim: rgba(255, 255, 255, 0.6);
}

.calculadora-window {
  position: fixed !important;
  width: 380px !important;
  min-width: 320px !important;
  height: 750px !important;
  min-height: 500px !important;
  background: #ffffff !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  border-radius: 24px !important;
  z-index: 20000 !important;
  display: none;
  flex-direction: column !important;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.15) !important;
  overflow: hidden !important;
  color: #344767 !important;
  font-family: 'Inter', sans-serif !important;
}

.calculadora-window:not(.positioned) {
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
}

.calculadora-window.active {
  display: flex !important;
}

.calculadora-header {
  padding: 15px 20px !important;
  background: #f8f9fa !important;
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  border-bottom: 1px solid #eee !important;
  cursor: grab !important;
}

.calculadora-header span {
  font-weight: 700 !important;
  color: #344767 !important;
}

/* DISPLAY */
.calculadora-display-container {
  padding: 40px 25px !important;
  background: #fff !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-end !important;
}

.calc-history-input {
  font-size: 1.1rem !important;
  color: #8392ab !important;
  background: transparent !important;
  border: none !important;
  border-bottom: 1px solid transparent !important;
  text-align: right !important;
  width: 100% !important;
  padding: 0 !important;
  margin-bottom: 5px !important;
  transition: all 0.2s !important;
  outline: none !important;
}

.calc-history-input:focus {
  color: #344767 !important;
  border-bottom-color: rgba(13, 110, 253, 0.2) !important;
}

#calc-screen {
  font-size: 3.5rem; /* Sin !important para permitir cambio dinámico */
  font-weight: 800 !important;
  color: #344767 !important;
  text-align: right !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  width: 100% !important;
  word-break: keep-all !important;
  min-height: 3rem !important;
  display: block !important;
}

/* MEMORY BAR */
.calc-memory-bar {
  display: flex !important;
  justify-content: space-around !important;
  padding: 10px 20px !important;
  background: #f8f9fa !important;
  border-top: 1px solid #eee !important;
  border-bottom: 1px solid #eee !important;
}

.btn-calc-mem {
  background: #ffffff !important;
  color: #344767 !important;
  border: 1px solid #dee2e6 !important;
  border-radius: 8px !important;
  padding: 8px 12px !important;
  font-size: 0.9rem !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  transition: all 0.2s !important;
}

.btn-calc-mem:hover:not(:disabled) {
  background: #e9ecef !important;
  border-color: #0d6efd !important;
  color: #0d6efd !important;
}

.btn-calc-mem:disabled {
  opacity: 0.4 !important;
  cursor: not-allowed !important;
  color: #6c757d !important;
}

/* BUTTONS GRID */
.calculadora-buttons {
  flex-grow: 1 !important;
  display: grid !important;
  grid-template-columns: repeat(4, 1fr) !important;
  gap: 10px !important;
  padding: 20px !important;
  background: #fff !important;
}

.calculadora-buttons .btn {
  background: #f8f9fa !important;
  color: #344767 !important; /* FORCED DARK TEXT */
  border: 1px solid transparent !important;
  border-radius: 12px !important;
  font-size: 1.25rem !important;
  font-weight: 600 !important;
  transition: all 0.2s !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.calculadora-buttons .btn:hover {
  background: #edf2f7 !important;
  transform: translateY(-2px) !important;
}

.btn-calc-num {
  background: #fff !important;
  border-color: #eee !important;
  color: #344767 !important;
}

.btn-calc-op {
  background: #eef2ff !important;
  color: #0d6efd !important;
}

.calculadora-window .btn-calc-op i,
.calculadora-window .btn-calc-op .bi,
.calculadora-window .btn-calc-op i::before,
.calculadora-window .calculadora-buttons .btn-calc-op [class^="bi-"],
.calculadora-window .calculadora-buttons .btn-calc-op [class*=" bi-"] {
  color: #0d6efd !important;
}

.btn-calc-action {
  background: #0d6efd !important;
  color: #ffffff !important;
}

.calculadora-window .btn-calc-action i,
.calculadora-window .btn-calc-action .bi,
.calculadora-window .btn-calc-action i::before,
.calculadora-window .calculadora-buttons .btn-calc-action [class^="bi-"],
.calculadora-window .calculadora-buttons .btn-calc-action [class*=" bi-"] {
  color: #ffffff !important;
}

.btn-calc-equal {
  background: #0d6efd !important;
  color: #ffffff !important;
  box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3) !important;
  font-size: 1.5rem !important;
}

.btn-calc-equal:hover {
  background: #0257d5 !important;
  color: #ffffff !important;
}

.calculadora-window .btn-calc-equal,
.calculadora-window .btn-calc-equal span,
.calculadora-window #btn-calc-equal,
.calculadora-window #btn-calc-equal span,
.calculadora-buttons .btn-calc-equal,
.calculadora-buttons #btn-calc-equal {
  color: #ffffff !important;
  background: #0d6efd !important;
}

/* HISTORY DRAWER - FIXED COLORS */
.calc-saved-pane {
  position: absolute !important;
  top: 0 !important;
  left: -100% !important;
  width: 100% !important;
  height: 100% !important;
  background: #ffffff !important;
  z-index: 100 !important;
  transition: left 0.3s ease !important;
  padding: 20px !important;
  display: flex !important;
  flex-direction: column !important;
  color: #344767 !important;
}

.calc-saved-pane.active {
  left: 0 !important;
}

.calc-saved-header {
  font-weight: 700 !important;
  margin-bottom: 20px !important;
  border-bottom: 2px solid #f1f3f5 !important;
  padding-bottom: 10px !important;
}

.saved-item {
  background: #f8f9fa !important;
  border-radius: 12px !important;
  padding: 15px !important;
  margin-bottom: 10px !important;
  cursor: pointer !important;
  transition: background 0.2s !important;
}

.saved-item:hover { background: #edf2f7 !important; }

.saved-item .title { font-weight: 700 !important; color: #344767 !important; font-size: 1.2rem !important; }
.saved-item .comment { font-style: italic !important; color: #8392ab !important; font-size: 0.9rem !important; }

/* FOOTER SAVE */
.calc-save-tool {
  padding: 25px !important;
  background: #f8f9fa !important;
  border-top: 1px solid #eee !important;
}

#calc-save-comment {
  border-radius: 12px !important;
  border: 1px solid #ddd !important;
  padding: 12px !important;
  background: #fff !important;
  color: #344767 !important;
}

.calculadora-resizer {
  position: absolute !important;
  bottom: 0 !important;
  right: 0 !important;
  width: 30px !important;
  height: 30px !important;
  cursor: nwse-resize !important;
  z-index: 10000 !important;
  background: transparent !important;
}

.calculadora-resizer::before {
  content: "" !important;
  position: absolute !important;
  right: 2px !important;
  bottom: 2px !important;
  width: 0 !important;
  height: 0 !important;
  border-style: solid !important;
  border-width: 0 0 16px 16px !important;
  border-color: transparent transparent #cbd5e0 transparent !important;
  opacity: 0.8 !important;
}

.calculadora-resizer::after {
  content: "" !important;
  position: absolute !important;
  right: 6px !important;
  bottom: 6px !important;
  width: 10px !important;
  height: 10px !important;
  border-right: 2px solid #6c757d !important;
  border-bottom: 2px solid #6c757d !important;
  opacity: 0.6 !important;
}

.calculadora-resizer:hover::before {
  border-color: transparent transparent #a8b8d8 transparent !important;
  opacity: 1 !important;
}

.calculadora-resizer:hover::after {
  border-color: #0d6efd !important;
  opacity: 1 !important;
}

#calc-save-comment {
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.1);
  background: rgba(255,255,255,0.8);
  padding: 8px 12px;
}

/* Saved Operations Area */
.calc-saved-toggle {
  position: absolute;
  left: calc(10px * var(--calc-scale));
  bottom: calc(10px * var(--calc-scale));
  z-index: 20;
}

.calc-saved-pane {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--calc-bg);
  z-index: 30;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.calc-saved-pane.active {
  transform: translateX(0);
}

.calc-saved-header {
  padding: 15px;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  font-weight: bold;
}

.calc-saved-list {
  flex-grow: 1;
  overflow-y: auto;
  padding: 10px;
}

.saved-item {
  background: rgba(0,0,0,0.02);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.saved-item:hover {
  background: rgba(0,0,0,0.05);
}

.saved-item .title {
  font-weight: bold;
  font-size: calc(14px * var(--calc-scale));
  display: block;
}

.saved-item .comment {
  font-size: calc(11px * var(--calc-scale));
  color: var(--calc-text-muted);
  font-style: italic;
}

/* Resizer */
.calculadora-resizer {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 20px;
  height: 20px;
  cursor: nwse-resize;
  z-index: 40;
}

.calculadora-resizer::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--calc-text-muted);
  border-bottom: 2px solid var(--calc-text-muted);
  opacity: 0.5;
}

.animate-pop-in {
  animation: calcPopIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes calcPopIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
