/* ==========================================================================
   DESIGN SYSTEM & VARIABLES
   ========================================================================== */
:root {
  --bg-primary: #f1f5f9;
  --bg-secondary: #e2e8f0;
  --bg-card: rgba(255, 255, 255, 0.65);
  --bg-input: rgba(248, 250, 252, 0.8);
  --bg-drawer: rgba(255, 255, 255, 0.94);
  --bg-toast: rgba(255, 255, 255, 0.9);
  
  --border-color: rgba(15, 23, 42, 0.08);
  --border-glow: rgba(6, 182, 212, 0.15);
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  /* Accent Colors */
  --accent-cyan: #0891b2;
  --accent-blue: #2563eb;
  --accent-rose: #e11d48;
  --accent-gradient: linear-gradient(135deg, #0891b2 0%, #2563eb 100%);
  --danger-gradient: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
  
  /* Keyboard/Buttons */
  --btn-num-bg: rgba(15, 23, 42, 0.03);
  --btn-num-hover: rgba(15, 23, 42, 0.07);
  --btn-num-active: rgba(15, 23, 42, 0.12);
  
  --btn-operator-bg: rgba(37, 99, 235, 0.07);
  --btn-operator-hover: rgba(37, 99, 235, 0.13);
  --btn-operator-text: #2563eb;
  
  --btn-action-bg: rgba(15, 23, 42, 0.06);
  --btn-action-hover: rgba(15, 23, 42, 0.11);
  --btn-action-text: #334155;
  
  /* Shadows & Blur */
  --shadow-premium: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 10px 10px -5px rgba(0, 0, 0, 0.02);
  --shadow-glow: 0 0 20px rgba(6, 182, 212, 0.06);
  --blur-amount: 20px;
  
  /* Font Family */
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ==========================================================================
   GLOBAL RESET
   ========================================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(6, 182, 212, 0.08) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.08) 0px, transparent 50%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* ==========================================================================
   APP CONTAINER & HEADER
   ========================================================================== */
.app-container {
  width: 100%;
  max-width: 440px;
  height: 95vh;
  max-height: 800px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  position: relative;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 0 4px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 20px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 8px rgba(6, 182, 212, 0.3));
}

.logo h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  gap: 12px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

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

/* ==========================================================================
   MAIN CONTENT AREA (CALCULATOR)
   ========================================================================== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  height: calc(100% - 64px);
}

.calculator-card {
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(var(--blur-amount));
  -webkit-backdrop-filter: blur(var(--blur-amount));
  border: 1px solid var(--border-color);
  border-radius: 32px;
  padding: 24px;
  box-shadow: var(--shadow-premium);
  position: relative;
  overflow: hidden;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.calculator-card:hover {
  border-color: rgba(6, 182, 212, 0.25);
  box-shadow: var(--shadow-premium), var(--shadow-glow);
}

/* Neon glow effect background in card */
.calculator-glow {
  position: absolute;
  top: -150px;
  right: -150px;
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, rgba(6, 182, 212, 0.12) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* Display Screen */
.display-screen {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 20px 24px;
  margin-bottom: 24px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.display-formula {
  font-size: 16px;
  color: var(--text-secondary);
  min-height: 24px;
  letter-spacing: 0.5px;
  word-break: break-all;
  text-align: right;
  max-width: 100%;
}

.display-input {
  font-size: 40px;
  font-weight: 500;
  margin-top: 8px;
  word-wrap: break-word;
  word-break: break-all;
  max-width: 100%;
  letter-spacing: -0.5px;
  line-height: 1.1;
  transition: font-size 0.15s ease;
}

/* Keypad Grid */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  position: relative;
  z-index: 1;
}

.btn {
  font-family: var(--font-sans);
  font-size: 20px;
  font-weight: 500;
  height: 60px;
  border-radius: 16px;
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  outline: none;
}

.btn:active {
  transform: scale(0.94);
}

.btn-num {
  background: var(--btn-num-bg);
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-num:hover {
  background: var(--btn-num-hover);
  border-color: rgba(15, 23, 42, 0.08);
}

.btn-num:active {
  background: var(--btn-num-active);
}

.btn-operator {
  background: var(--btn-operator-bg);
  color: var(--btn-operator-text);
  font-size: 22px;
  border-color: rgba(59, 130, 246, 0.05);
}

.btn-operator:hover {
  background: var(--btn-operator-hover);
  border-color: rgba(59, 130, 246, 0.15);
  color: var(--btn-operator-text);
}

.btn-action {
  background: var(--btn-action-bg);
  color: var(--btn-action-text);
  border-color: var(--border-color);
}

.btn-action:hover {
  background: var(--btn-action-hover);
  border-color: rgba(15, 23, 42, 0.1);
}

.btn-danger {
  color: var(--accent-rose);
  background: rgba(244, 63, 94, 0.06);
  border-color: rgba(244, 63, 94, 0.1);
}

.btn-danger:hover {
  background: rgba(244, 63, 94, 0.12);
  border-color: rgba(244, 63, 94, 0.2);
}

.btn-zero {
  grid-column: span 2;
}

.btn-equals {
  background: var(--accent-gradient);
  color: #ffffff;
  font-weight: 600;
  font-size: 22px;
  box-shadow: 0 4px 14px rgba(6, 182, 212, 0.3);
}

.btn-equals:hover {
  box-shadow: 0 6px 20px rgba(6, 182, 212, 0.45);
  filter: brightness(1.1);
}

/* ==========================================================================
   SLIDE-OUT SIDEBAR DRAWERS
   ========================================================================== */
.drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-drawer);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: 32px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-premium);
}

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

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
}

.drawer-header h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--text-primary);
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
}

.drawer-footer {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border-color);
}

/* Custom Scrollbar for Drawer Body */
.drawer-body::-webkit-scrollbar {
  width: 6px;
}

.drawer-body::-webkit-scrollbar-track {
  background: transparent;
}

.drawer-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

.drawer-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   HISTORY LIST & STATE LAYOUTS
   ========================================================================== */
.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  background: rgba(15, 23, 42, 0.01);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item:hover {
  background: rgba(15, 23, 42, 0.03);
  border-color: rgba(6, 182, 212, 0.25);
  transform: translateY(-1px);
}

.history-item:active {
  transform: translateY(0);
}

.history-expr {
  font-size: 14px;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  word-break: break-all;
}

.history-res {
  font-size: 20px;
  font-weight: 600;
  color: var(--accent-cyan);
  word-break: break-all;
}

.history-time {
  font-size: 10px;
  color: var(--text-muted);
  align-self: flex-start;
  margin-top: 6px;
}

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  flex: 1;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 14px;
}

.hidden {
  display: none !important;
}

/* Loader / Spinner */
.spinner-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1;
  color: var(--text-secondary);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(0, 0, 0, 0.06);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   SETTINGS FORM
   ========================================================================== */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
  width: 100%;
}

.form-group input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.15);
}

.help-text {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-full {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  padding: 12px 16px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  outline: none;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 10px rgba(6, 182, 212, 0.2);
}

.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 14px rgba(6, 182, 212, 0.35);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-full {
  width: 100%;
}

.btn-primary:active, .btn-secondary:active {
  transform: scale(0.98);
}

/* Connection Status */
.connection-status-panel {
  background: rgba(15, 23, 42, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px;
  margin-top: 10px;
}

.connection-status-panel h3 {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 10px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  position: relative;
}

.status-dot.online {
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.status-dot.offline {
  background-color: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}

.status-dot.connecting {
  background-color: #f59e0b;
  box-shadow: 0 0 8px #f59e0b;
  animation: pulse 1.2s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

#status-text {
  font-size: 13px;
  font-weight: 500;
}

/* ==========================================================================
   NOTIFICATION TOAST
   ========================================================================== */
.toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-toast);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-premium);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-success {
  border-left: 3px solid #10b981;
}

.toast-error {
  border-left: 3px solid #ef4444;
}

.toast-info {
  border-left: 3px solid #3b82f6;
}
