/* ================================================================
   STENO POWER MODE — stili dedicati
   Tutti gli stili sono prefissati con .sp- per non collidere
   ================================================================ */

.sp-panel {
  position: fixed;
  top: 90px;
  right: 12px;
  width: 320px;
  max-height: calc(100vh - 110px);
  background: rgba(20, 22, 28, 0.97);
  color: #eaeaea;
  border: 1px solid rgba(0, 123, 255, 0.4);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6);
  z-index: 1400; /* sotto a Controlli Stenotipista (1500) e altri popup */
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

/* Quando minimizzato (header solo) */
.sp-panel.sp-minimized {
  width: 160px;
  max-height: 42px;
}

.sp-panel.sp-minimized .sp-body {
  display: none !important;
}

/* Quando il pannello è APERTO, restringi la typing-section
   così la textarea non finisce sotto e va a capo correttamente */
body.sp-panel-open .typing-section {
  padding-right: 350px !important;
  transition: padding-right 0.2s ease;
}

body.sp-panel-open .stenografa-controls {
  right: 350px !important; /* sposta anche l'ingranaggio Controlli Stenotipista */
}

/* Forza il word-wrap della textarea (a volte non si applica con larghezze grandi) */
#liveTypingArea {
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  word-break: break-word !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
}

.sp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: linear-gradient(135deg, #0066cc, #004999);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.3px;
  color: #fff;
}

.sp-collapse-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 4px;
  color: #fff;
  width: 24px;
  height: 24px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  font-weight: 700;
}

.sp-collapse-btn:hover {
  background: rgba(255, 255, 255, 0.35);
}

.sp-body {
  overflow-y: auto;
  padding: 10px 12px;
}

.sp-body::-webkit-scrollbar { width: 6px; }
.sp-body::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }

.sp-section {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sp-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.sp-section-title {
  font-weight: 600;
  margin-bottom: 8px;
  color: #7fc4ff;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sp-mini-btn {
  background: rgba(0, 123, 255, 0.2);
  border: 1px solid rgba(0, 123, 255, 0.4);
  color: #7fc4ff;
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 12px;
}

.sp-mini-btn:hover {
  background: rgba(0, 123, 255, 0.4);
}

/* Pulsanti generici */
.sp-btn {
  border: none;
  border-radius: 5px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: opacity 0.15s, transform 0.1s;
}

.sp-btn:hover {
  opacity: 0.9;
}

.sp-btn:active {
  transform: scale(0.97);
}

.sp-btn-primary {
  background: #0d6efd;
  color: #fff;
}

.sp-btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #eaeaea;
  width: 100%;
  margin-top: 6px;
}

.sp-btn-danger {
  background: #dc3545;
  color: #fff;
}

/* Sezione AI */
.sp-mic-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 11px;
}

.sp-mic-row label {
  color: #aaa;
  flex-shrink: 0;
}

.sp-mic-row select {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #eaeaea;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 11px;
  max-width: 220px;
}

.sp-mic-refresh {
  font-size: 10px !important;
  padding: 3px 6px !important;
  background: rgba(255, 255, 255, 0.08) !important;
  color: #aaa !important;
  margin-top: 0 !important;
  width: auto !important;
  margin-bottom: 8px !important;
}

.sp-vu-container {
  margin-bottom: 8px;
}

.sp-vu-label {
  font-size: 10px;
  color: #888;
  margin-bottom: 3px;
}

.sp-vu-bar {
  height: 8px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.sp-vu-fill {
  height: 100%;
  width: 0%;
  background: #444;
  transition: width 0.05s linear, background 0.1s;
  border-radius: 3px;
}

.sp-ai-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sp-ai-status {
  font-size: 11px;
  color: #aaa;
}

.sp-ai-status.listening {
  color: #ff5050;
  animation: sp-pulse 1.4s infinite;
  font-weight: 600;
}

@keyframes sp-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.sp-hint {
  font-size: 10px;
  color: #888;
  margin-top: 6px;
  font-style: italic;
}

/* Griglia snippets */
.sp-snippets-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  margin-bottom: 6px;
}

.sp-snippet-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  color: #eaeaea;
  padding: 5px 6px;
  font-size: 11px;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 36px;
}

.sp-snippet-btn:hover:not(.empty) {
  background: rgba(0, 123, 255, 0.25);
  border-color: rgba(0, 123, 255, 0.5);
}

.sp-snippet-btn.empty {
  cursor: default;
  opacity: 0.4;
}

.sp-snippet-key {
  font-weight: 700;
  color: #7fc4ff;
  font-size: 10px;
}

.sp-snippet-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #ddd;
}

/* Tabs glossario */
.sp-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 8px;
  background: rgba(0, 0, 0, 0.3);
  padding: 3px;
  border-radius: 5px;
}

.sp-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: #aaa;
  padding: 5px 4px;
  font-size: 11px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.15s;
}

.sp-tab.active {
  background: #0d6efd;
  color: #fff;
  font-weight: 600;
}

.sp-tab:hover:not(.active) {
  background: rgba(255, 255, 255, 0.08);
  color: #eaeaea;
}

/* Lista glossario */
.sp-glossary-list {
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 8px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 5px;
  padding: 4px;
}

.sp-glossary-list::-webkit-scrollbar { width: 5px; }
.sp-glossary-list::-webkit-scrollbar-thumb { background: #444; }

.sp-entry {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
}

.sp-entry-text {
  flex: 1;
  background: transparent;
  border: none;
  color: #eaeaea;
  text-align: left;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 3px;
  font-size: 12px;
}

.sp-entry-text:hover {
  background: rgba(0, 123, 255, 0.25);
}

.sp-entry-del {
  background: transparent;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 3px;
  line-height: 1;
}

.sp-entry-del:hover {
  background: rgba(220, 53, 69, 0.3);
  color: #ff8888;
}

.sp-empty {
  text-align: center;
  color: #777;
  padding: 12px;
  font-style: italic;
  font-size: 11px;
}

/* Aggiungi voce */
.sp-add-row {
  display: flex;
  gap: 4px;
}

.sp-add-row input {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  color: #eaeaea;
  padding: 6px 8px;
  font-size: 12px;
}

.sp-add-row input:focus {
  outline: none;
  border-color: #0d6efd;
  background: rgba(255, 255, 255, 0.12);
}

.sp-add-row .sp-btn {
  width: 32px;
  padding: 6px;
}

.sp-shortcuts-help {
  font-size: 10px;
  color: #777;
  text-align: center;
  padding: 6px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  line-height: 1.5;
}

/* ================================================================
   MODALE EDITOR SNIPPETS
   ================================================================ */
.sp-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.sp-modal {
  background: #1e2028;
  color: #eaeaea;
  border-radius: 10px;
  padding: 24px;
  width: min(500px, 90%);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.sp-modal h3 {
  margin: 0 0 16px 0;
  color: #7fc4ff;
  font-size: 16px;
}

.sp-snip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.sp-snip-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sp-snip-row label {
  font-weight: 700;
  color: #7fc4ff;
  width: 32px;
  flex-shrink: 0;
  font-size: 12px;
}

.sp-snip-row input {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  color: #eaeaea;
  padding: 6px 8px;
  font-size: 12px;
}

.sp-snip-row input:focus {
  outline: none;
  border-color: #0d6efd;
}

.sp-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.sp-modal-actions .sp-btn {
  padding: 8px 18px;
  width: auto;
  margin-top: 0;
}

/* ================================================================
   RICERCA VELOCE Ctrl+K
   ================================================================ */
.sp-search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  backdrop-filter: blur(3px);
}

.sp-search-box {
  width: min(560px, 90%);
  background: #1e2028;
  color: #eaeaea;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(0, 123, 255, 0.3);
}

#sp-search-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  padding: 16px 20px;
  font-size: 16px;
  outline: none;
  box-sizing: border-box;
}

.sp-search-results {
  max-height: 50vh;
  overflow-y: auto;
}

.sp-search-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}

.sp-search-row:hover, .sp-search-row.active {
  background: rgba(13, 110, 253, 0.25);
  border-left-color: #0d6efd;
}

.sp-search-cat {
  font-size: 16px;
  width: 22px;
}

.sp-search-text {
  flex: 1;
  font-size: 14px;
}

.sp-search-empty {
  padding: 24px;
  text-align: center;
  color: #777;
  font-style: italic;
}

/* ================================================================
   SUGGERIMENTO AI (banner in basso)
   ================================================================ */
.sp-ai-suggestion {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(40, 167, 69, 0.95), rgba(25, 135, 84, 0.95));
  color: #fff;
  padding: 14px 22px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 9000;
  max-width: 80%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: sp-slide-up 0.25s ease-out;
}

@keyframes sp-slide-up {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.sp-ai-prefix {
  font-weight: 700;
  margin-right: 4px;
}

.sp-ai-text {
  font-style: italic;
}

.sp-ai-hint {
  font-size: 11px;
  opacity: 0.85;
  margin-left: 8px;
  font-style: normal;
  white-space: nowrap;
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 900px) {
  .sp-panel {
    width: 280px;
    top: 70px;
    right: 6px;
  }
  .sp-ai-suggestion {
    max-width: 95%;
    font-size: 13px;
  }
}

@media (max-width: 600px) {
  .sp-panel {
    width: calc(100vw - 20px);
    right: 10px;
  }
}
