/* ═══════════════════════════════════════════════════
   KalkulatorPRO v1.0 — Premium Modern Theme
   ═══════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Inter:wght@400;500;600;700&display=swap');

/* ─── CSS VARIABLES ─── */
:root {
  /* LIGHT THEME */
  --bg: #f0f2f5;
  --bg-gradient: linear-gradient(180deg, #eef2f7 0%, #e2e8f0 100%);
  --panel-bg: #ffffff;
  --sidebar-bg: #f8fafc;
  --border: #e2e8f0;
  --border-focus: #10b981;
  
  --text-main: #0f172a;
  --text-subtle: #475569;
  --text-muted: #94a3b8;
  
  --btn-bg: #ffffff;
  --btn-text: #0f172a;
  --btn-border: #e2e8f0;
  --btn-active-bg: #00c853; /* Active tab green */
  --btn-active-text: #ffffff;
  
  --terminal-bg: #f8fafc;
  --terminal-text: #1e293b;
  --terminal-prefix: #475569;
  
  --input-bg: #f8fafc;
  --input-border: #e2e8f0;
  --input-text: #0f172a;
  --input-placeholder: #94a3b8;
  
  --theme-toggle-bg: #f1f5f9;
  --theme-toggle-border: #cbd5e1;
  --theme-toggle-color: #0f172a;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.04), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
  
  --scrollbar-track: #f1f5f9;
  --scrollbar-thumb: #cbd5e1;
}

[data-theme="dark"] {
  /* DARK THEME */
  --bg: #0c0d0e;
  --bg-gradient: none;
  --panel-bg: #141517;
  --sidebar-bg: #0f1011;
  --border: #22252a;
  --border-focus: #00ff66;
  
  --text-main: #ffffff;
  --text-subtle: #7a828e;
  --text-muted: #4e535c;
  
  --btn-bg: #ffffff; /* Sleek white buttons in dark mode */
  --btn-text: #000000;
  --btn-border: #22252a;
  --btn-active-bg: #00ff66; /* Vibrant active green tab */
  --btn-active-text: #000000;
  
  --terminal-bg: #17181a;
  --terminal-text: #e2e8f0;
  --terminal-prefix: #7a828e;
  
  --input-bg: #1a1c1f;
  --input-border: #22252a;
  --input-text: #ffffff;
  --input-placeholder: #4e535c;
  
  --theme-toggle-bg: #00ff66; /* Neon green in dark mode */
  --theme-toggle-border: #00ff66;
  --theme-toggle-color: #000000;
  
  --shadow-sm: none;
  --shadow-md: none;
  --shadow-lg: none;
  
  --scrollbar-track: #141517;
  --scrollbar-thumb: #22252a;
}

/* ─── RESET & BASE ─── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: 'Space Mono', 'Inter', monospace;
  font-size: 13px;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--text-main);
  overflow: hidden;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* ─── DESKTOP BACKGROUND (Clean subtle gradient) ─── */
.desktop-bg {
  display: none; /* Removed legacy waves to match cleaner premium mockups */
}

/* ─── GLOBAL MENU BAR ─── */
.menu-bar {
  position: relative;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 24px;
  background: transparent;
  color: var(--text-main);
  font-size: 13px;
  user-select: none;
  flex-shrink: 0;
}

.menu-bar-left {
  display: flex;
  gap: 20px;
  font-family: 'Space Mono', monospace;
  letter-spacing: 0.5px;
}

.menu-bar-right {
  display: flex;
  align-items: center;
}

.theme-toggle {
  cursor: pointer;
  font-size: 15px;
  background: var(--theme-toggle-bg);
  border: 1px solid var(--theme-toggle-border);
  color: var(--theme-toggle-color);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.theme-toggle:hover {
  transform: translateY(-1px);
}

/* ─── MAIN LAYOUT ─── */
.app-layout {
  position: relative;
  z-index: 10;
  display: flex;
  height: calc(100vh - 48px);
  overflow: hidden;
  padding: 8px 16px 16px 16px;
  gap: 16px;
}

.desktop-area {
  flex: 1;
  display: flex;
  gap: 16px;
  overflow: hidden;
}

/* ─── PREMIUM WINDOWS ─── */
.retro-window {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.window-titlebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 8px 20px;
  background: transparent;
  color: var(--text-main);
  font-weight: 700;
  font-family: 'Space Mono', monospace;
  font-size: 16px;
  letter-spacing: -0.2px;
  user-select: none;
  min-height: 40px;
}

.window-dots {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.window-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.window-dot.red { background: #ff5f56; }
.window-dot.orange { background: #ffbd2e; }
.window-dot.green { background: #27c93f; }

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

/* ─── CALCULATOR WINDOW ─── */
.calc-window {
  flex: 1;
  min-width: 0;
  max-height: 100%;
}

.history-window {
  width: 320px;
  flex-shrink: 0;
  max-height: 100%;
}

/* ─── TAB NAVIGATION ─── */
.tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  margin-bottom: 20px;
}

.tab-btn {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--btn-text);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tab-btn:hover {
  border-color: var(--border-focus);
}

.tab-btn.active {
  background: var(--btn-active-bg) !important;
  color: var(--btn-active-text) !important;
  border-color: var(--btn-active-bg) !important;
}

/* ─── TAB CONTENT ─── */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.tab-title {
  display: none; /* Hide legacy text title since we use modernized window-titlebar */
}

/* ─── INPUT FIELDS & SELECTS ─── */
.retro-input {
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  padding: 12px 14px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--input-text);
  width: 100%;
  outline: none;
  transition: all 0.15s ease;
}

.retro-input:focus {
  border-color: var(--border-focus);
}

.retro-input::placeholder {
  color: var(--input-placeholder);
}

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

.input-label {
  display: block;
  font-weight: 700;
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.input-row {
  display: flex;
  gap: 16px;
}

.input-row > * {
  flex: 1;
}

.retro-select {
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  padding: 12px 14px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--input-text);
  width: 100%;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%23888888' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  transition: all 0.15s ease;
}

.retro-select:focus {
  border-color: var(--border-focus);
}

/* ─── GRID FOR OPERATOR BUTTONS ─── */
.op-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.op-btn {
  font-family: 'Space Mono', monospace;
  font-size: 15px;
  font-weight: 700;
  padding: 12px 8px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-text);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.1s ease;
  text-align: center;
}

.op-btn:hover {
  border-color: var(--border-focus);
  transform: translateY(-1px);
}

.op-btn.active {
  background: var(--text-main);
  color: var(--panel-bg);
  border-color: var(--text-main);
  transform: translateY(0);
}

/* ─── HITUNG ACTION BUTTON ─── */
.btn-hitung {
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  width: 100%;
  padding: 14px 20px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-text);
  cursor: pointer;
  border-radius: 8px;
  margin-top: 10px;
  transition: all 0.15s ease;
}

.btn-hitung:hover {
  border-color: var(--border-focus);
  transform: translateY(-1px);
}

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

/* ─── RESULT TERMINAL ─── */
.result-terminal {
  background: var(--terminal-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-top: 16px;
  min-height: 120px;
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: var(--terminal-text);
  overflow-x: auto;
  transition: all 0.2s ease;
}

.result-terminal .prefix {
  color: var(--terminal-prefix);
  font-weight: 700;
}

.result-terminal .step-line {
  margin: 4px 0;
  line-height: 1.5;
}

.result-terminal .step-line::before {
  content: '> ';
  color: var(--terminal-prefix);
}

.result-terminal .error-text {
  color: #ff5f56;
  font-weight: 700;
}

.result-terminal .cursor-blink::after {
  content: '█';
  animation: cursor-blink-anim 1s step-end infinite;
  color: var(--text-main);
}

@keyframes cursor-blink-anim {
  50% { opacity: 0; }
}

/* ─── RESULT BADGES (GRID LAYOUTS) ─── */
.badge-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.result-badge {
  background: var(--terminal-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  transition: all 0.15s ease;
}

.result-badge .badge-label {
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-subtle);
  margin-bottom: 6px;
}

.result-badge .badge-value {
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  word-break: break-all;
}

.badge-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

/* ─── BONUS SUB-WINDOW STYLINGS ─── */
.bonus-row {
  display: flex;
  gap: 16px;
}

.bonus-col {
  flex: 1;
  min-width: 0;
}

.bonus-col .sub-window {
  background: transparent;
  border: none;
}

.bonus-col .sub-titlebar {
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: 8px;
  padding-left: 2px;
}

.bonus-col .sub-body {
  border: 1px solid var(--border);
  background: var(--panel-bg);
  border-radius: 10px;
  padding: 16px;
}

/* ─── HISTORY PANEL ─── */
.history-body {
  background: var(--terminal-bg);
  border-top: 1px solid var(--border);
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.history-item {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: var(--terminal-text);
  padding: 8px;
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
}

.history-item:hover {
  background: var(--input-bg);
}

/* ─── SIDEBAR PANEL (Tools Shortcut Bar) ─── */
.sidebar-icons {
  width: 80px;
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 8px;
  gap: 12px;
  flex-shrink: 0;
  overflow-y: auto;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.sidebar-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 12px;
}

.sidebar-title .tools-label {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-subtle);
}

.sidebar-title .version-label {
  font-family: 'Space Mono', monospace;
  font-size: 8px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 10px 6px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-subtle);
  font-family: 'Space Mono', monospace;
  width: 100%;
  transition: all 0.15s ease;
}

.sidebar-icon:hover {
  background: var(--input-bg);
  color: var(--text-main);
}

.sidebar-icon.active {
  background: var(--panel-bg) !important;
  border-color: var(--border) !important;
  color: var(--text-main) !important;
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .sidebar-icon.active {
  background: #ffffff !important;
  border-color: #ffffff !important;
  color: #000000 !important;
}

[data-theme="dark"] .sidebar-icon.active .icon-label {
  color: #000000 !important;
}

.sidebar-icon .icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

.sidebar-icon .sidebar-svg {
  width: 22px;
  height: 22px;
  transition: stroke 0.15s ease;
}

.sidebar-icon .icon-label {
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  text-align: center;
  color: var(--text-subtle);
}

/* ─── RETRO CUSTOM SCROLLBAR ─── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

/* ─── LOGIC SIMULATOR CONTAINER & DETAILS ─── */
.logic-gate-container {
  display: flex;
  gap: 16px;
  background: var(--terminal-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  align-items: stretch;
}

.gate-inputs {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  flex: 0 0 90px;
}

.binary-toggle-btn {
  font-family: 'Space Mono', monospace;
  font-size: 18px;
  font-weight: 700;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text-main);
  cursor: pointer;
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
  box-shadow: var(--shadow-sm);
}

.binary-toggle-btn.active {
  background: #27c93f !important;
  color: #ffffff !important;
  border-color: #27c93f !important;
}

.gate-visualizer-box {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.gate-visualizer-title, .table-title {
  background: var(--terminal-bg);
  color: var(--text-subtle);
  font-family: 'Space Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  padding: 6px 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.gate-visualizer-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
}

.gate-truth-table-container {
  flex: 0 0 180px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.truth-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
  font-family: 'Space Mono', monospace;
}

.truth-table th, .truth-table td {
  border: 1px solid var(--border);
  padding: 6px;
  text-align: center;
}

.truth-table th {
  background: var(--terminal-bg);
  color: var(--text-subtle);
  font-weight: 700;
}

.truth-table tr.active-row {
  background: #3b82f6 !important;
  color: #ffffff !important;
  font-weight: 700;
}

/* SVG Logic Styles */
.gate-svg-wire {
  stroke-width: 3px;
  fill: none;
  stroke-linecap: round;
}

.gate-svg-wire.active {
  stroke: #27c93f;
}

.gate-svg-wire.inactive {
  stroke: var(--border);
}

.gate-svg-body {
  stroke: var(--text-main);
  stroke-width: 3px;
  fill: var(--terminal-bg);
}

.gate-svg-bubble {
  stroke: var(--text-main);
  stroke-width: 3px;
  fill: var(--panel-bg);
}

.gate-svg-text {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  fill: var(--text-main);
  font-weight: 700;
}

.op-grid-7 {
  grid-template-columns: repeat(7, 1fr);
}

.logic-mode-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

/* ─── LOADING INDICATOR ─── */
.loading-text {
  color: var(--border-focus);
  font-weight: 700;
}

.loading-text::after {
  content: '...';
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

/* ─── CLEAR HISTORY BUTTON ─── */
.btn-clear-history {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-subtle);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-clear-history:hover {
  background: #ff5f56;
  color: #ffffff;
  border-color: #ff5f56;
}

/* ─── RESPONSIVE LAYOUTS ─── */
@media (max-width: 960px) {
  /* FIX: Use 100dvh to prevent mobile browser URL bar from clipping content */
  html, body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .app-layout {
    flex-direction: column;
    height: calc(100vh - 48px);
    height: calc(100dvh - 48px);
    overflow: hidden; /* Keep layout fixed, allow inner scroll */
  }

  .desktop-area {
    flex-direction: column;
    flex: 1; /* Take up all available space above sidebar */
    overflow-y: auto; /* Native scrolling for content */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 20px; /* Safe space at the bottom */
  }

  .calc-window {
    flex: none; /* Allow window to expand */
    max-height: none;
  }

  .window-body {
    overflow-y: visible; /* Remove nested scroll from calc window */
  }

  .history-window {
    width: 100%;
    flex: none;
    height: 320px; /* Fixed height for history pane */
    max-height: none;
  }

  .sidebar-icons {
    width: 100%;
    flex-direction: row;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 12px;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0; /* Keep sidebar strictly at the bottom */
  }

  .sidebar-title {
    display: none;
  }

  .sidebar-icon {
    min-width: 60px;
    padding: 6px;
  }

  .bonus-row {
    flex-direction: column;
  }

  .input-row {
    flex-direction: column;
    gap: 12px;
  }

  .op-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .badge-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 600px) {
  .menu-bar-left { display: none; }
  .op-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
