@import url(https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css);

:root {
  --primary: #3498db;
  --secondary: #2980b9;
  --header-bg: #2c3e50;
  --danger: #e74c3c;
  --success: #27ae60;
  --info: #82aaff;
  --warning: #f39c12;

  /* Force Dark Mode Theme by Default */
  --color-bg-dark: #1e293b;
  --color-surface-dark: #334155;
  --color-border-dark: #475569;
  --color-text-dark: #e2e8f0;
  --color-text-secondary-dark: #94a3b8;
  --color-text-tertiary-dark: #64748b;

  --color-bg: var(--color-bg-dark);
  --color-surface: var(--color-surface-dark);
  --color-border: var(--color-border-dark);
  --color-text: var(--color-text-dark);
  --color-text-secondary: var(--color-text-secondary-dark);
  --color-text-tertiary: var(--color-text-tertiary-dark);
  --color-recording: var(--danger);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --transition: 0.2s ease-in-out;

  --font-primary: 'Segoe UI', -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-mono: 'SF Mono', ui-monospace, Menlo, Monaco, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-primary);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  transition: background-color var(--transition), color var(--transition);
}

.container {
  max-width: 1800px;
  min-height: 95vh;
  margin: 2.5vh auto;
  background: var(--color-surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.header {
  background: var(--header-bg);
  color: white;
  padding: 20px 40px;
  text-align: center;
  border-bottom: 4px solid var(--primary);
}
.header h1 { font-size: 2.2em; margin-bottom: 4px; display: inline-block; }
.header p { font-size: 1em; opacity: 0.9; font-style: italic; }

.version-badge {
    font-size: 0.5em;
    vertical-align: super;
    background: rgba(255,255,255,0.2);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    font-family: var(--font-mono);
}

.main-content { display: flex; flex: 1; overflow: hidden; }
.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--color-bg);
  padding: 25px;
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.sidebar-section {
  background-color: var(--color-surface);
  border-radius: 8px;
  padding: 20px;
  border: 1px solid var(--color-border);
}
.sidebar-section h3 {
  font-size: 1.1em;
  color: var(--color-text);
  border-bottom: 2px solid var(--primary);
  padding-bottom: 10px;
  margin-bottom: 20px;
}
.recording-controls { text-align: center; }
.record-button {
  position: relative;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  z-index: 1;
}
.record-button-inner {
  width: 100%; height: 100%; border-radius: 50%;
  background: var(--color-surface); border: 2px solid var(--color-border);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text); font-size: 32px;
  box-shadow: var(--shadow-md); transition: all var(--transition);
}
.record-button:hover .record-button-inner { transform: scale(1.05); }
.record-button.recording .record-button-inner {
  background-color: var(--color-recording); border-color: var(--color-recording);
  color: white; animation: pulse 1.5s infinite;
}
.record-button:disabled .record-button-inner {
    cursor: not-allowed; background-color: var(--color-border); opacity: 0.5;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7); }
  70% { box-shadow: 0 0 0 15px rgba(231, 76, 60, 0); }
  100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

#liveRecordingUI canvas { width: 100%; height: 60px; }
#liveRecordingUI .live-recording-timer {
  font-family: var(--font-mono); font-size: 2em;
  text-align: center; margin-top: 15px; color: var(--primary);
  transition: color var(--transition);
}
.recording-limit-warning {
    text-align: center;
    font-size: 0.9em;
    color: var(--warning);
    margin-top: 10px;
    font-weight: 500;
}
#liveRecordingUI.is-warning .live-recording-timer {
    color: var(--warning);
}

/* --- STORAGE PROGRESS BAR --- */
.storage-progress-container {
    width: 100%;
    height: 6px;
    background: var(--color-border);
    margin-top: 15px;
    border-radius: 3px;
    overflow: hidden;
}
.storage-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary);
    transition: width 0.5s linear, background-color 0.3s ease;
}
#liveRecordingUI.is-warning .storage-progress-bar {
    background: var(--warning);
}

.action-buttons-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.action-button {
  background: var(--color-bg); color: var(--color-text-secondary);
  border: 1px solid var(--color-border); border-radius: 6px;
  padding: 12px; font-size: 0.9em; font-weight: 600;
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; gap: 8px; transition: var(--transition);
}
.action-button:hover {
  background-color: var(--primary); color: white; border-color: var(--primary);
}
.action-button:disabled {
    cursor: not-allowed; background-color: var(--color-border);
    color: var(--color-text-tertiary); border-color: var(--color-border);
}

/* DRG SPECIAL BUTTON */
.action-button.drg-btn { color: #2dd4bf; border-color: rgba(45, 212, 191, 0.3); }
.action-button.drg-btn:hover { background-color: #0f766e; border-color: #2dd4bf; color: white; }

/* --- POLISHING STYLE TOGGLE --- */
.style-toggle-container {
    margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between; font-size: 0.9em;
}
.toggle-label { color: var(--color-text-secondary); font-weight: 600; }
.toggle-wrapper { display: flex; align-items: center; gap: 8px; }
.mode-text { font-size: 0.85em; color: var(--color-text-tertiary); transition: color 0.2s; }
input:not(:checked) ~ .mode-text:first-of-type { color: var(--color-text); font-weight: bold; }
input:checked ~ .mode-text:last-of-type { color: var(--primary); font-weight: bold; }
.switch { position: relative; display: inline-block; width: 40px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--color-surface); border: 1px solid var(--color-border); transition: .4s;
}
.slider:before {
    position: absolute; content: ""; height: 14px; width: 14px; left: 2px; bottom: 2px;
    background-color: var(--color-text-secondary); transition: .4s;
}
input:checked + .slider { background-color: rgba(52, 152, 219, 0.2); border-color: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); background-color: var(--primary); }
.slider.round { border-radius: 20px; }
.slider.round:before { border-radius: 50%; }

/* --- BYOK SETTINGS --- */
.api-key-input {
    width: 100%; background-color: var(--color-bg); border: 1px solid var(--color-border);
    color: var(--color-text); padding: 10px; border-radius: 6px;
    font-family: var(--font-mono); font-size: 0.85em; outline: none; transition: border-color 0.2s;
}
.api-key-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2); }
.api-key-input::placeholder { color: var(--color-text-tertiary); font-style: italic; }

/* --- DYNAMIC PARTNER WIDGET --- */
.promo-section {
    padding: 0 !important; border: none !important; background: transparent !important;
    box-shadow: none !important; overflow: hidden; margin-top: 20px; text-align: center;
    min-height: 100px; 
}
.promo-link {
    display: block; border-radius: 8px; overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease; border: 1px solid var(--color-border);
    background-color: var(--color-surface);
}
.promo-link:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.3); border-color: var(--primary); }
.promo-image { width: 100%; height: auto; display: block; image-rendering: -webkit-optimize-contrast; }

/* --- EMBEDDED MEDICAL MONITOR (Sidebar Widget) --- */
.medical-monitor {
    background-color: #000 !important; /* Equipment Black */
    border: 1px solid #333;
    padding: 0 !important;
    overflow: hidden;
    min-height: 120px;
    display: flex;
    flex-direction: column;
}
.monitor-screen {
    position: relative; width: 100%; height: 100%; padding: 15px;
    display: flex; flex-direction: column; justify-content: space-between;
}
.ekg-readout {
    width: 100%; height: 60px; overflow: hidden; position: relative;
    border-bottom: 1px solid #1a1a1a; margin-bottom: 10px;
}
.ekg-svg { width: 100%; height: 100%; }
.ekg-line {
    fill: none; stroke: #00f3ff; stroke-width: 2;
    stroke-miterlimit: 10; stroke-dasharray: 1000; stroke-dashoffset: 1000;
    animation: drawHeartbeat 2.0s linear infinite; filter: drop-shadow(0 0 4px rgba(0, 243, 255, 0.6));
}
@keyframes drawHeartbeat {
    0% { stroke-dashoffset: 1000; opacity: 0; } 15% { opacity: 1; }
    85% { stroke-dashoffset: 0; opacity: 1; } 100% { stroke-dashoffset: 0; opacity: 0; }
}
.monitor-stats {
    display: flex; justify-content: space-between; align-items: center; font-family: 'Courier New', monospace;
}
.stat-group { display: flex; flex-direction: column; }
.stat-label { font-size: 0.7em; color: #555; font-weight: bold; }
.stat-value { font-size: 1.2em; color: #00f3ff; font-weight: bold; text-shadow: 0 0 5px rgba(0, 243, 255, 0.4); }
.stat-value.processing-text { animation: blinkText 1s infinite; color: #f39c12; text-shadow: none; }
.blink { animation: blinkHeart 1s infinite; color: #e74c3c; font-size: 0.8em; vertical-align: middle; }
@keyframes blinkHeart { 0% { opacity: 0.3; } 50% { opacity: 1; } 100% { opacity: 0.3; } }
@keyframes blinkText { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

.status-log-section { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.status-header {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 10px;
}
.status-header h3 { border: none; margin: 0; padding: 0; }
.user-status-text {
  flex-grow: 1; text-align: right; font-size: 1.0em; font-weight: 500;
  padding: 0 10px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; transition: color var(--transition);
}
.user-status-text.is-idle { color: var(--color-text-secondary); }
.user-status-text.is-working { color: var(--primary); }
.user-status-text.is-success { color: var(--success); }
.user-status-text.is-error { color: var(--danger); }
.user-status-text.is-warning { color: var(--warning); }

.log-toggle-button {
  background: none; border: none; color: var(--color-text-tertiary);
  cursor: pointer; font-size: 0.8em; font-weight: bold;
  display: flex; align-items: center; gap: 4px;
}
.log-toggle-button i { transition: transform var(--transition); }
.status-log-container.is-expanded .log-toggle-button i { transform: rotate(180deg); }

.status-log-container {
  max-height: 0; overflow: hidden;
  transition: max-height 0.3s ease-out; flex: 1; min-height: 0;
}
.status-log-container.is-expanded { max-height: 100%; }
.status-log {
  height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  font-family: var(--font-mono); font-size: 12px; padding: 10px;
  background-color: var(--color-bg); border-radius: 4px;
  color: var(--color-text-secondary); display: flex; flex-direction: column-reverse;
}
.log-message {
  padding: 4px 0; white-space: pre-wrap; word-wrap: break-word;
  border-top: 1px solid var(--color-border);
}
.log-message:last-child { border-top: none; }
.log-message.log-success { color: var(--success); }
.log-message.log-error { color: var(--danger); }
.log-message.log-info { color: var(--color-text-secondary); }
.log-message.log-warning { color: var(--warning); }
.log-message.log-model { color: var(--info); font-weight: bold; }

.content-area { flex-grow: 1; padding: 25px 40px; height: 100%; overflow-y: auto; }
.note-area { height: 100%; display: flex; flex-direction: column; }
.note-header {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 16px; border-bottom: 1px solid var(--color-border); margin-bottom: 12px;
}
.editor-title {
  font-size: 22px; font-weight: 600; outline: none;
  flex-grow: 1; margin-right: 24px;
  color: var(--color-text);
}
[contenteditable][placeholder]:empty::before {
  content: attr(placeholder); color: var(--color-text-tertiary); cursor: text;
}
[contenteditable][placeholder]:empty:focus::before { content: ""; }

.tab-navigation-container {
  background: var(--color-bg); border: 1px solid var(--color-border);
  border-radius: 10px; padding: 4px;
}
.tab-navigation { position: relative; display: flex; }
.tab-button {
  background: transparent; border: none; padding: 6px 16px;
  font-size: 13px; font-weight: 500; color: var(--color-text-secondary);
  border-radius: 6px; cursor: pointer; transition: var(--transition);
  position: relative; z-index: 1;
}
.tab-button:hover { color: var(--color-text); }
.tab-button.active { color: var(--color-text); }
.active-tab-indicator {
  position: absolute; top: 0; left: 0; width: 0; height: 100%;
  background-color: var(--color-surface); border-radius: 6px;
  transition: left 0.3s ease, width 0.3s ease; z-index: 0; box-shadow: var(--shadow-sm);
}
.note-content-wrapper { flex: 1; overflow-y: auto; position: relative; }
.note-content {
  outline: none; font-size: 16px; line-height: 1.7;
  padding: 12px 0; display: none;
  color: var(--color-text);
}
.note-content.active { display: block; }

.footer {
  background: var(--header-bg); color: white; padding: 15px 40px;
  text-align: center; font-size: 0.9em; font-style: italic; opacity: 0.8;
}
.footer p { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0; }
.footer-separator { opacity: 0.3; }
.footer-link {
    color: white; text-decoration: none; font-size: 0.9em; opacity: 0.4;
    transition: opacity 0.2s, color 0.2s; display: inline-flex; align-items: center; gap: 5px;
}
.footer-link:hover { opacity: 1; color: var(--primary); }

.hidden { display: none !important; }

@media (max-width: 900px) {
  .main-content { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--color-border); }
  .content-area { height: auto; }
}

/* =========================================
   MARKDOWN FIDELITY LAYER (LIVE EDITOR)
   ========================================= */

.note-content * { color: var(--color-text) !important; background-color: transparent !important; }

.note-content h1, .note-content h2, .note-content h3 { 
  margin: 1.25em 0 0.75em 0; font-weight: 600; color: var(--color-text); 
}
.note-content h1 { font-size: 1.8em; border-bottom: 1px solid var(--color-border); padding-bottom: 0.3em; }
.note-content h2 { font-size: 1.5em; }
.note-content h3 { font-size: 1.25em; }

.note-content p { margin-bottom: 1em; }
.note-content strong { font-weight: bold; color: var(--primary); }
.note-content em { font-style: italic; }

.note-content ul, .note-content ol { margin-bottom: 1em; padding-left: 2em; }
.note-content li { margin-bottom: 0.25em; }

.note-content table {
    width: 100%; border-collapse: collapse; margin: 1em 0; font-size: 0.95em;
    border: 1px solid var(--color-border);
}
.note-content th {
    background-color: var(--color-bg); border: 1px solid var(--color-border);
    padding: 10px; font-weight: 600; text-align: left; color: var(--info);
}
.note-content td { border: 1px solid var(--color-border); padding: 8px 10px; }

.note-content blockquote {
    border-left: 4px solid var(--primary); margin: 1em 0; padding-left: 1em;
    color: var(--color-text-secondary); font-style: italic;
    background: rgba(52, 152, 219, 0.1); border-radius: 0 4px 4px 0; padding: 8px 16px;
}

.note-content pre {
    background-color: var(--color-bg); padding: 1em; border-radius: 6px; margin-bottom: 1em;
    font-family: var(--font-mono); border: 1px solid var(--color-border); overflow-x: auto;
}
.note-content code {
    font-family: var(--font-mono); background-color: var(--color-bg);
    padding: 2px 4px; border-radius: 4px; font-size: 0.9em; color: var(--warning);
}
.note-content pre code { color: var(--color-text); background-color: transparent; padding: 0; }

/* DRG SEPARATOR */
.drg-separator {
    border: 0; height: 1px; background: var(--color-border); margin: 20px 0; position: relative;
}
.drg-separator::after {
    content: "◈"; position: absolute; left: 50%; top: -10px; transform: translateX(-50%);
    background: var(--color-bg); color: var(--color-text-secondary); padding: 0 10px; font-size: 14px;
}

/* --- PDF MODAL (Legacy) --- */
.pdf-modal {
    position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center; backdrop-filter: blur(5px);
}
.pdf-modal-content {
    background-color: var(--color-surface); width: 90%; max-width: 900px; height: 90%;
    border-radius: 12px; display: flex; flex-direction: column; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5); border: 1px solid var(--color-border);
}
.pdf-modal-header {
    padding: 20px; border-bottom: 1px solid var(--color-border); display: flex; justify-content: space-between; align-items: center;
    background-color: var(--color-bg); border-top-left-radius: 12px; border-top-right-radius: 12px;
}
.pdf-modal-header h2 { font-size: 1.25em; color: var(--color-text); margin: 0; }
.pdf-modal-actions { display: flex; gap: 10px; }
.modal-btn { padding: 8px 16px; border: none; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.9em; transition: opacity 0.2s; }
.modal-btn.cancel { background: transparent; color: var(--color-text-secondary); border: 1px solid var(--color-border); }
.modal-btn.cancel:hover { background: var(--color-bg-dark); color: var(--color-text); }
.modal-btn.confirm { background: var(--primary); color: white; }
.modal-btn.confirm:hover { opacity: 0.9; }
.pdf-scroll-container { flex: 1; overflow-y: hidden; padding: 0; background-color: #525659; display: flex; justify-content: center; align-items: center; }
.pdf-preview-frame { width: 100%; height: 100%; border: none; background: #fff; }

/* --- DEMO MODAL STYLES --- */
.demo-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.9); z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(8px);
}
.demo-wrapper {
    position: relative; width: 90%; 
    /* Fix: Reduced max-width for square video to prevent it filling entire screen vertically */
    max-width: 700px; 
    background: #000; border-radius: 12px; overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    border: 1px solid var(--color-border);
}
.demo-close-btn {
    position: absolute; top: 15px; right: 15px; z-index: 100;
    background: rgba(255,255,255,0.1); border: none; color: white;
    width: 36px; height: 36px; border-radius: 50%; font-size: 18px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
.demo-close-btn:hover { background: rgba(255,255,255,0.3); }

.demo-video-container {
    position: relative; width: 100%; 
    /* Fix: Square aspect ratio and height limit */
    aspect-ratio: 1/1; 
    max-height: 80vh; 
    background: #000; margin: 0 auto;
}
.demo-poster {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background-size: cover; background-position: center;
    z-index: 50; transition: opacity 0.3s ease;
}
.demo-play-icon {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    z-index: 60; pointer-events: none; transition: opacity 0.3s ease, transform 0.2s;
}
.play-icon-circle {
    width: 80px; height: 80px; border-radius: 50%;
    background: rgba(52, 152, 219, 0.9);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 30px rgba(52, 152, 219, 0.5);
    color: white; font-size: 32px; padding-left: 5px;
}
#demoVideo {
    width: 100%; height: 100%; display: block; outline: none; z-index: 10;
}

/* State when playing: Hide Poster & Icon */
.is-playing .demo-poster,
.is-playing .demo-play-icon {
    opacity: 0; pointer-events: none;
}

/* --- CONFIRMATION TOAST --- */
.toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
    background: var(--color-surface); border: 1px solid var(--color-border);
    padding: 15px 25px; border-radius: 8px; box-shadow: 0 15px 40px rgba(0,0,0,0.6);
    display: flex; flex-direction: column; gap: 12px; z-index: 2000;
    min-width: 300px; animation: slideUp 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.toast-content { display: flex; align-items: center; gap: 12px; color: var(--color-text); font-weight: 500; font-size: 1.05em; }
.toast-content i { color: var(--warning); font-size: 1.2em; }
.toast-actions { display: flex; gap: 10px; justify-content: flex-end; }
.toast-btn {
    padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer;
    font-size: 0.9em; font-weight: 600; transition: all 0.2s;
}
.toast-btn.cancel { background: transparent; color: var(--color-text-secondary); border: 1px solid var(--color-border); }
.toast-btn.cancel:hover { background: var(--color-bg); color: var(--color-text); }
.toast-btn.confirm { background: var(--danger); color: white; }
.toast-btn.confirm:hover { background: #c0392b; box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3); }

@keyframes slideUp { from { transform: translate(-50%, 40px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* --- LOADING OVERLAY --- */
.loading-overlay {
    position: fixed; z-index: 10000; left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center;
    color: white; font-size: 1.5em; flex-direction: column; gap: 20px; backdrop-filter: blur(3px);
}
.loading-content {
    background: var(--color-surface); padding: 30px 50px; border-radius: 10px;
    border: 1px solid var(--color-border); display: flex; flex-direction: column; align-items: center; gap: 15px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5); color: var(--color-text);
}
.loading-content i { font-size: 2em; color: var(--primary); }