/* ── Segments Framework — BlinkOS ── */

/* ── Segment Container ── */
.segment-container {
  margin: 12px 0;
  border-radius: 12px;
  overflow: hidden;
}

.segment-wrapper {
  background: var(--bg-secondary);
  border: 1px solid var(--bg-hover);
  border-radius: 12px;
  overflow: hidden;
}

/* ── Segment Header ── */
.segment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--bg-hover);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.segment-header:hover {
  background: var(--bg-hover, rgba(255,255,255,0.06));
}

.segment-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.segment-icon {
  font-size: 16px;
}

.segment-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.segment-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.segment-refresh-btn,
.segment-collapse-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.segment-refresh-btn:hover,
.segment-collapse-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ── Segment Body ── */
.segment-body {
  padding: 0;
}

/* ── Loading Skeleton ── */
.segment-skeleton {
  padding: 16px;
}

.segment-skeleton-line {
  height: 14px;
  margin-bottom: 10px;
  border-radius: 4px;
  background: linear-gradient(90deg, 
    var(--bg-hover) 25%,
    var(--bg-tertiary) 50%,
    var(--bg-hover) 75%
  );
  background-size: 200% 100%;
  animation: segment-shimmer 1.5s infinite;
}

@keyframes segment-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Error State ── */
.segment-error {
  padding: 20px;
  text-align: center;
  color: var(--text-secondary);
}

.segment-error-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.segment-error-message {
  font-size: 14px;
  margin-bottom: 12px;
}

.segment-retry-btn {
  background: var(--accent-primary, #5865f2);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.segment-retry-btn:hover {
  opacity: 0.85;
}

.segment-loading-retry {
  padding: 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

/* ══════════════════════════════════════════
   EMAIL VIEWER SEGMENT
   ══════════════════════════════════════════ */

.email-thread {
  padding: 0;
}

.email-thread-count {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--bg-hover);
}

/* ── Email Card ── */
.email-card {
  border-bottom: 1px solid var(--bg-hover);
}

.email-card:last-child {
  border-bottom: none;
}

.email-card-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.email-card-header:hover {
  background: var(--bg-hover);
}

.email-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.email-meta {
  flex: 1;
  min-width: 0;
}

.email-sender {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-subject {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.email-details {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.email-address {
  opacity: 0.7;
}

.email-expand-icon {
  color: var(--text-secondary);
  font-size: 12px;
  padding-top: 4px;
  flex-shrink: 0;
}

/* ── Email Recipients ── */
.email-recipients {
  padding: 0 16px 6px 16px;
  font-size: 12px;
  color: var(--text-secondary);
}

.email-to, .email-cc {
  margin-bottom: 2px;
}

.email-recipients strong {
  color: var(--text-secondary);
}

/* ── Email Preview (collapsed) ── */
.email-preview {
  padding: 0 16px 10px 16px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Email Body ── */
.email-card-body {
  padding: 4px 16px 12px 16px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-height: 300px;
  overflow-y: auto;
}

.email-card-body::-webkit-scrollbar {
  width: 4px;
}

.email-card-body::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 2px;
}

/* Quoted text in email body */
.email-quoted {
  border-left: 3px solid var(--accent-primary, #5865f2);
  padding-left: 12px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* Forwarded message markers */
.email-forward-marker {
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 0;
  border-top: 1px solid var(--bg-hover);
  margin-top: 8px;
}

/* Links in email body */
.email-link {
  color: var(--accent-primary, #5865f2);
  text-decoration: none;
}

.email-link:hover {
  text-decoration: underline;
}

/* ══════════════════════════════════════════
   DATA TABLE SEGMENT
   ══════════════════════════════════════════ */

.data-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table-th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--bg-hover);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color 0.15s;
}

.data-table-th:hover {
  color: var(--text-primary);
}

.data-table-th.sort-asc::after {
  content: ' ▲';
  font-size: 10px;
}

.data-table-th.sort-desc::after {
  content: ' ▼';
  font-size: 10px;
}

.data-table-td {
  padding: 10px 14px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--bg-hover);
}

.data-table-row-even {
  background: transparent;
}

.data-table-row-odd {
  background: transparent;
}

.data-table tbody tr:hover {
  background: var(--bg-hover);
}

.data-table-footer {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--bg-hover);
}

/* ══════════════════════════════════════════
   DYNAMIC SEGMENT (iframe)
   ══════════════════════════════════════════ */

.dynamic-segment-iframe {
  display: block;
  border: none;
  border-radius: 0 0 12px 12px;
  background: var(--bg-secondary);
}

/* ══════════════════════════════════════════
   SEGMENT TEXT BLOCKS (between segments)
   ══════════════════════════════════════════ */

.segment-text-block {
  /* Inherit parent message styling */
}

/* ══════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════ */

@media (max-width: 480px) {
  .email-card-body {
    padding-left: 16px;
  }
  
  .email-recipients {
    padding-left: 16px;
  }
  
  .email-preview {
    padding-left: 16px;
  }
  
  .email-avatar {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }
  
  .data-table-th,
  .data-table-td {
    padding: 8px 10px;
    font-size: 13px;
  }
}

/* Long email thread cap — scrollable at segment level for very long threads */
.email-thread {
  max-height: 500px;
  overflow-y: auto;
}

.email-thread::-webkit-scrollbar {
  width: 4px;
}

.email-thread::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 2px;
}

/* Email HTML wrapper — handles scrolling on iOS */
.email-iframe-wrapper {
  width: 100%;
  max-height: 400px;
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid var(--bg-tertiary, #e0e0e0);
}

.email-shadow-host {
  display: block;
  width: 100%;
  background: #ffffff;
  min-height: 50px;
}

/* Prevent parent swipe gestures from stealing horizontal scroll touches */
.email-iframe-wrapper,
.email-shadow-host,
.email-card-body {
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
}
/* ── Segment Fullscreen Mode ── */

.segment-fullscreen-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  pointer-events: none;
}

.segment-fullscreen-overlay.active {
  display: flex;
  flex-direction: column;
  pointer-events: auto;
}

.segment-fullscreen-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.segment-fullscreen-overlay.visible .segment-fullscreen-backdrop {
  opacity: 1;
}

.segment-fullscreen-content {
  position: absolute;
  top: 48px; /* below chat header */
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary, #1a1a1a);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s ease;
  z-index: 101;
}

.segment-fullscreen-overlay.visible .segment-fullscreen-content {
  transform: translateY(0);
}

/* Drag handle */
.segment-fullscreen-handle {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 0 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.segment-fullscreen-handle-bar {
  width: 36px;
  height: 4px;
  background: var(--text-muted, #666);
  border-radius: 2px;
}

/* Fullscreen body — contains the segment */
.segment-fullscreen-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 8px 16px;
}

/* When segment is fullscreen, remove max-height constraints */
.segment-is-fullscreen .segment-body {
  max-height: none !important;
}

.segment-is-fullscreen .email-thread {
  max-height: none !important;
}

.segment-is-fullscreen .email-card-body {
  max-height: none !important;
}

.segment-is-fullscreen .email-iframe-wrapper {
  max-height: none !important;
}

.segment-is-fullscreen .dynamic-segment-iframe {
  max-height: none !important;
  height: auto !important;
  min-height: 400px;
}

/* Segment wrapper styling in fullscreen */
.segment-is-fullscreen .segment-wrapper {
  border: none;
  border-radius: 0;
  background: transparent;
}

.segment-is-fullscreen .segment-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--bg-tertiary, #333);
}

/* Fullscreen expand button on segment header */
.segment-fullscreen-btn {
  background: none;
  border: none;
  color: var(--text-muted, #888);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background 0.2s, color 0.2s;
}

.segment-fullscreen-btn:hover {
  background: var(--bg-hover, #333);
  color: var(--text-primary, #fff);
}

/* Mobile: fullscreen content takes more space */
@media (max-width: 480px) {
  .segment-fullscreen-content {
    top: 0;
    border-radius: 0;
  }
}
/* ── Image Lightbox Segment ── */

.lightbox-wrapper {
  width: 100%;
}

/* Grid layout */
.lightbox-grid {
  display: grid;
  gap: 4px;
  border-radius: 8px;
  overflow: hidden;
}

.lightbox-grid-cell {
  overflow: hidden;
  border-radius: 0;
}

.lightbox-grid-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  aspect-ratio: 1;
}

/* Single image */
.lightbox-image-wrapper {
  border-radius: 8px;
  overflow: hidden;
}

.lightbox-image {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  max-height: 400px;
  object-fit: contain;
  background: var(--bg-secondary, #222);
}

.lightbox-image-error {
  padding: 20px;
  text-align: center;
  color: var(--text-muted, #888);
  background: var(--bg-secondary, #222);
  border-radius: 8px;
}

/* Preview + thumbnails layout */
.lightbox-preview {
  position: relative;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-secondary, #111);
  cursor: pointer;
}

.lightbox-main-image {
  width: 100%;
  max-height: 350px;
  object-fit: contain;
  display: block;
  transition: opacity 0.2s ease;
}

/* Nav arrows */
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  font-size: 24px;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 50%;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.2s;
  z-index: 2;
}

.lightbox-nav:hover {
  background: rgba(0, 0, 0, 0.8);
}

.lightbox-nav-prev { left: 8px; }
.lightbox-nav-next { right: 8px; }

/* Counter */
.lightbox-counter {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 10px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* Thumbnail strip */
.lightbox-thumbstrip {
  display: flex;
  gap: 4px;
  padding: 8px 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.lightbox-thumbstrip::-webkit-scrollbar {
  height: 3px;
}

.lightbox-thumbstrip::-webkit-scrollbar-thumb {
  background: var(--bg-hover, #444);
  border-radius: 2px;
}

.lightbox-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  border: 2px solid transparent;
  opacity: 0.6;
  transition: opacity 0.2s, border-color 0.2s;
}

.lightbox-thumb:hover {
  opacity: 0.9;
}

.lightbox-thumb.active {
  opacity: 1;
  border-color: var(--accent-primary, #007AFF);
}

/* Caption */
.lightbox-caption {
  padding: 8px 4px 4px;
  font-size: 13px;
  color: var(--text-secondary, #aaa);
  text-align: center;
}

/* Fullscreen overlay (fallback when SegmentFullscreen not available) */
.lightbox-fullscreen-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lightbox-fullscreen-image {
  max-width: 95%;
  max-height: 90vh;
  object-fit: contain;
  cursor: pointer;
}

.lightbox-fullscreen-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-fullscreen-counter {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 14px;
  padding: 4px 12px;
  border-radius: 12px;
}

/* Swipe prevention for thumbnail strip */
.lightbox-thumbstrip {
  touch-action: pan-x;
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .lightbox-main-image {
    max-height: 250px;
  }
  
  .lightbox-thumb {
    width: 48px;
    height: 48px;
  }
  
  .lightbox-nav {
    font-size: 20px;
    padding: 6px 10px;
  }
}
/* ── Video Player Segment ── */

.video-player-wrapper {
  width: 100%;
}

.video-player-embed {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

.video-player-iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.video-player-native {
  width: 100%;
  max-height: 400px;
  border-radius: 8px;
  background: #000;
}

.video-player-title {
  padding: 8px 4px 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary, #fff);
}

/* ── Web View Segment ── */

.web-view-wrapper {
  width: 100%;
  border: 1px solid var(--bg-tertiary, #333);
  border-radius: 8px;
  overflow: hidden;
}

.web-view-titlebar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-secondary, #222);
  border-bottom: 1px solid var(--bg-tertiary, #333);
  font-size: 12px;
}

.web-view-title-text {
  font-weight: 500;
  color: var(--text-primary, #fff);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.web-view-url {
  color: var(--text-muted, #888);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.web-view-open-btn {
  color: var(--accent-primary, #007AFF);
  text-decoration: none;
  font-size: 16px;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
}

.web-view-open-btn:hover {
  background: var(--bg-hover, #333);
}

.web-view-iframe-container {
  width: 100%;
  overflow: hidden;
  touch-action: pan-x pan-y;
}

.web-view-iframe {
  width: 100%;
  border: none;
  background: white;
}

.web-view-warning {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  background: rgba(255, 200, 0, 0.1);
  border-top: 1px solid var(--bg-tertiary, #333);
  font-size: 12px;
  color: var(--text-secondary, #aaa);
}

.web-view-warning a {
  color: var(--accent-primary, #007AFF);
  text-decoration: none;
}

/* Mobile */
@media (max-width: 480px) {
  .web-view-url { display: none; }
  .video-player-native { max-height: 250px; }
}
/* ── Calendar Event Segment ── */

.cal-event-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.cal-event-date-badge {
  flex-shrink: 0;
  width: 56px;
  background: var(--accent-primary, #007AFF);
  border-radius: 10px;
  text-align: center;
  padding: 6px 4px;
  color: white;
}

.cal-event-month {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  opacity: 0.9;
}

.cal-event-day {
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
}

.cal-event-weekday {
  font-size: 10px;
  opacity: 0.8;
}

.cal-event-details {
  flex: 1;
  min-width: 0;
}

.cal-event-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary, #fff);
  margin-bottom: 4px;
}

.cal-event-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary, #aaa);
  margin-bottom: 2px;
}

.cal-event-meta-icon {
  font-size: 12px;
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}

.cal-event-link {
  color: var(--accent-primary, #007AFF);
  text-decoration: none;
}

.cal-event-link:hover {
  text-decoration: underline;
}

.cal-event-description {
  font-size: 13px;
  color: var(--text-muted, #888);
  margin-top: 6px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cal-event-source {
  font-size: 11px;
  color: var(--text-muted, #666);
  margin-top: 4px;
  font-style: italic;
}

.cal-event-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.cal-event-action-btn {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg-tertiary, #333);
  color: var(--text-secondary, #aaa);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}

.cal-event-action-btn:hover {
  background: var(--bg-hover, #444);
  color: var(--text-primary, #fff);
}

/* Mobile */
@media (max-width: 480px) {
  .cal-event-date-badge {
    width: 48px;
  }
  .cal-event-day {
    font-size: 20px;
  }
}
/* ── BlinkOS Settings Segment ── */

.settings-segment-wrapper {
  width: 100%;
}

.settings-section {
  margin-bottom: 12px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary, #aaa);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--bg-tertiary, #333);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  position: relative;
}

.settings-row + .settings-row {
  border-top: 1px solid var(--bg-tertiary, #2a2a2a);
}

.settings-label {
  font-size: 14px;
  color: var(--text-primary, #fff);
}

/* Toggle switch */
.settings-toggle {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--bg-tertiary, #444);
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
  padding: 0;
  flex-shrink: 0;
}

.settings-toggle.active {
  background: var(--accent-primary, #007AFF);
}

.settings-toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  display: block;
}

.settings-toggle.active .settings-toggle-knob {
  transform: translateX(20px);
}

/* Select dropdown */
.settings-select {
  background: var(--bg-tertiary, #333);
  color: var(--text-primary, #fff);
  border: 1px solid var(--bg-hover, #444);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  cursor: pointer;
  min-width: 100px;
}

.settings-select:focus {
  outline: none;
  border-color: var(--accent-primary, #007AFF);
}

/* Model container */
.settings-model-container {
  font-size: 13px;
  color: var(--text-muted, #888);
}

/* Saved toast */
.settings-saved-toast {
  position: absolute;
  right: 60px;
  font-size: 11px;
  color: #4CAF50;
  animation: settings-fade 1.5s ease-out forwards;
}

@keyframes settings-fade {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Compact mode */
.settings-segment-wrapper.compact .settings-section-header {
  font-size: 12px;
  margin-bottom: 4px;
}

.settings-segment-wrapper.compact .settings-row {
  padding: 4px;
}

.settings-segment-wrapper.compact .settings-label {
  font-size: 13px;
}
/* ── Saved Segments ── */

.saved-segments-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.saved-segment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-secondary, #222);
  border-radius: 8px;
  transition: background 0.15s;
}

.saved-segment-item:hover {
  background: var(--bg-hover, #333);
}

.saved-segment-info {
  flex: 1;
  min-width: 0;
}

.saved-segment-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary, #fff);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-segment-meta {
  font-size: 11px;
  color: var(--text-muted, #888);
  margin-top: 2px;
}

.saved-segment-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.saved-segment-btn {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg-tertiary, #333);
  color: var(--text-secondary, #aaa);
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}

.saved-segment-btn:hover {
  background: var(--accent-primary, #007AFF);
  color: white;
}

.saved-segment-delete {
  padding: 4px 8px;
}

.saved-segment-delete:hover {
  background: #ff3b30;
}

/* ── Pin Button ── */
.segment-pin-btn {
  background: none;
  border: none;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.segment-pin-btn:hover {
  opacity: 1;
}
/* ── Document Editor Segment ── */
.doc-editor-wrapper {
  background: var(--bg-secondary, #1a1a2e);
  border: 1px solid var(--border-color, rgba(255,255,255,0.08));
  border-radius: 12px;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* Title bar */
.doc-editor-title-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-tertiary, rgba(255,255,255,0.03));
  border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.06));
}

.doc-editor-title-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.doc-editor-title-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary, #e0e0e0);
  font-size: 14px;
  font-weight: 600;
  padding: 2px 4px;
  border-radius: 4px;
  outline: none;
}

.doc-editor-title-input:focus {
  background: rgba(255,255,255,0.05);
}

.doc-editor-title-input[readonly] {
  cursor: default;
}

.doc-editor-status {
  font-size: 11px;
  color: var(--text-muted, #888);
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  white-space: nowrap;
  flex-shrink: 0;
}

.doc-editor-status-edited {
  color: #4ade80;
  background: rgba(74,222,128,0.1);
}

/* Toolbar */
.doc-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  background: var(--bg-tertiary, rgba(255,255,255,0.02));
  border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.06));
  flex-wrap: wrap;
  overflow-x: auto;
}

.doc-editor-toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary, #aaa);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}

.doc-editor-toolbar-btn:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text-primary, #e0e0e0);
}

.doc-editor-toolbar-btn:active {
  background: rgba(255,255,255,0.12);
}

.doc-editor-toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border-color, rgba(255,255,255,0.08));
  margin: 0 4px;
  flex-shrink: 0;
}

/* Rich editor area */
.doc-editor-area {
  min-height: 150px;
  max-height: 500px;
  overflow-y: auto;
  padding: 16px 20px;
  color: var(--text-primary, #e0e0e0);
  font-size: var(--doc-font-size, 14px);
  line-height: 1.7;
  font-family: var(--doc-font-family, inherit);
  outline: none;
}

.doc-editor-rich {
  cursor: text;
}

.doc-editor-rich:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted, #666);
  pointer-events: none;
}

.doc-editor-rich:focus {
  background: rgba(255,255,255,0.01);
}

/* Rich editor formatting */
.doc-editor-rich h1 {
  font-size: 24px;
  font-weight: 700;
  margin: 16px 0 8px;
  line-height: 1.3;
}

.doc-editor-rich h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 14px 0 6px;
  line-height: 1.3;
}

.doc-editor-rich h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 12px 0 4px;
  line-height: 1.4;
}

.doc-editor-rich p {
  margin: 0 0 8px;
}

.doc-editor-rich ul, .doc-editor-rich ol {
  padding-left: 24px;
  margin: 4px 0 8px;
}

.doc-editor-rich li {
  margin: 2px 0;
}

.doc-editor-rich blockquote {
  border-left: 3px solid var(--accent-color, #7c3aed);
  margin: 8px 0;
  padding: 4px 16px;
  color: var(--text-secondary, #aaa);
  background: rgba(255,255,255,0.02);
  border-radius: 0 6px 6px 0;
}

.doc-editor-rich a {
  color: var(--accent-color, #7c3aed);
  text-decoration: underline;
}

.doc-editor-rich code {
  background: rgba(255,255,255,0.06);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
}

.doc-editor-rich pre {
  background: rgba(0,0,0,0.2);
  padding: 12px 16px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}

.doc-editor-rich pre code {
  background: none;
  padding: 0;
}

.doc-editor-rich hr {
  border: none;
  border-top: 1px solid var(--border-color, rgba(255,255,255,0.1));
  margin: 16px 0;
}

.doc-editor-rich table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
}

.doc-editor-rich th, .doc-editor-rich td {
  border: 1px solid var(--border-color, rgba(255,255,255,0.1));
  padding: 6px 10px;
  text-align: left;
}

.doc-editor-rich th {
  background: rgba(255,255,255,0.04);
  font-weight: 600;
}

/* Textarea (markdown/plain) */
.doc-editor-textarea {
  width: 100%;
  min-height: 150px;
  max-height: 500px;
  padding: 16px 20px;
  background: transparent;
  border: none;
  color: var(--text-primary, #e0e0e0);
  font-size: 14px;
  line-height: 1.7;
  resize: none;
  outline: none;
  box-sizing: border-box;
  font-family: inherit;
}

.doc-editor-mono {
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
}

.doc-editor-textarea::placeholder {
  color: var(--text-muted, #666);
}

/* Footer */
.doc-editor-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-tertiary, rgba(255,255,255,0.02));
  border-top: 1px solid var(--border-color, rgba(255,255,255,0.06));
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
}
.doc-editor-footer::-webkit-scrollbar { display: none; }

@media (max-width: 500px) {
  .doc-editor-footer { gap: 4px; padding: 6px 8px; }
  .doc-editor-action-btn { padding: 4px 6px; font-size: 11px; }
  .doc-editor-word-count { font-size: 10px; }
}

.doc-editor-word-count {
  font-size: 11px;
  color: var(--text-muted, #888);
  white-space: nowrap;
}

.doc-editor-action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border-color, rgba(255,255,255,0.1));
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary, #aaa);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.doc-editor-action-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary, #e0e0e0);
  border-color: rgba(255,255,255,0.15);
}

/* ── Fullscreen overrides ── */
.segment-fullscreen .doc-editor-area,
.segment-fullscreen .doc-editor-textarea {
  max-height: none;
  min-height: 400px;
  flex: 1;
}

.segment-fullscreen .doc-editor-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
}
/* ── Spreadsheet Segment ── */
.sheet-wrapper {
  background: var(--bg-secondary, #1a1a2e);
  border: 1px solid var(--border-color, rgba(255,255,255,0.08));
  border-radius: 12px;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* Title bar */
.sheet-title-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-tertiary, rgba(255,255,255,0.03));
  border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.06));
}

.sheet-title-icon { font-size: 16px; flex-shrink: 0; }

.sheet-title-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary, #e0e0e0);
  font-size: 14px;
  font-weight: 600;
  padding: 2px 4px;
  border-radius: 4px;
  outline: none;
}

.sheet-title-input:focus { background: rgba(255,255,255,0.05); }
.sheet-title-input[readonly] { cursor: default; }

.sheet-status {
  font-size: 11px;
  color: var(--text-muted, #888);
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  white-space: nowrap;
  flex-shrink: 0;
}

.sheet-status-edited {
  color: #4ade80;
  background: rgba(74,222,128,0.1);
}

/* Toolbar */
.sheet-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--bg-tertiary, rgba(255,255,255,0.02));
  border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.06));
  flex-wrap: wrap;
}

.sheet-toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border-color, rgba(255,255,255,0.08));
  margin: 0 4px;
}

/* Formula bar */
.sheet-formula-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: rgba(255,255,255,0.015);
  border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.06));
}

.sheet-cell-ref {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: var(--text-muted, #888);
  min-width: 36px;
  text-align: center;
  padding: 2px 6px;
  background: rgba(255,255,255,0.04);
  border-radius: 3px;
}

.sheet-formula-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary, #e0e0e0);
  font-size: 13px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  padding: 2px 4px;
  outline: none;
}

.sheet-formula-input::placeholder {
  color: var(--text-muted, #555);
}

/* Table container */
.sheet-table-container {
  overflow: auto;
  max-height: 400px;
}

.sheet-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  table-layout: fixed;
}

/* Corner cell */
.sheet-corner {
  width: 36px;
  min-width: 36px;
  background: var(--bg-tertiary, rgba(255,255,255,0.04));
  border-right: 1px solid var(--border-color, rgba(255,255,255,0.08));
  border-bottom: 2px solid var(--border-color, rgba(255,255,255,0.1));
  position: sticky;
  left: 0;
  top: 0;
  z-index: 3;
}

/* Column headers */
.sheet-col-header {
  background: var(--bg-tertiary, rgba(255,255,255,0.04));
  color: var(--text-secondary, #aaa);
  font-weight: 600;
  font-size: 12px;
  padding: 6px 8px;
  text-align: center;
  border-right: 1px solid var(--border-color, rgba(255,255,255,0.06));
  border-bottom: 2px solid var(--border-color, rgba(255,255,255,0.1));
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  z-index: 2;
  min-width: 80px;
  transition: background 0.15s;
}

.sheet-col-header:hover {
  background: rgba(255,255,255,0.08);
}

.sheet-col-header.sheet-col-selected {
  background: rgba(124,58,237,0.15);
  color: var(--text-primary, #e0e0e0);
}

/* Row headers */
.sheet-row-header {
  background: var(--bg-tertiary, rgba(255,255,255,0.04));
  color: var(--text-muted, #888);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 6px;
  text-align: center;
  border-right: 1px solid var(--border-color, rgba(255,255,255,0.08));
  border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.04));
  position: sticky;
  left: 0;
  z-index: 1;
  width: 36px;
  min-width: 36px;
}

/* Cells */
.sheet-cell {
  padding: 4px 8px;
  border-right: 1px solid var(--border-color, rgba(255,255,255,0.04));
  border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.04));
  color: var(--text-primary, #e0e0e0);
  font-size: 13px;
  line-height: 1.4;
  outline: none;
  min-height: 24px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: cell;
}

.sheet-cell:focus {
  background: rgba(124,58,237,0.08);
  outline: 2px solid var(--accent-color, #7c3aed);
  outline-offset: -2px;
  z-index: 1;
  position: relative;
}

.sheet-cell:hover {
  background: rgba(255,255,255,0.02);
}

.sheet-cell-number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sheet-cell-formula {
  color: #60a5fa;
}

.sheet-cell.sheet-col-selected {
  background: rgba(124,58,237,0.04);
}

/* Footer */
.sheet-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-tertiary, rgba(255,255,255,0.02));
  border-top: 1px solid var(--border-color, rgba(255,255,255,0.06));
}

.sheet-cell-count {
  font-size: 11px;
  color: var(--text-muted, #888);
  white-space: nowrap;
}

.sheet-action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border-color, rgba(255,255,255,0.1));
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary, #aaa);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.sheet-action-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary, #e0e0e0);
  border-color: rgba(255,255,255,0.15);
}

/* Fullscreen overrides */
.segment-fullscreen .sheet-table-container,
.segment-is-fullscreen .sheet-table-container {
  max-height: none;
  flex: 1;
}

.segment-fullscreen .sheet-wrapper,
.segment-is-fullscreen .sheet-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
}
/* ── PDF Viewer Segment ── */
.pdf-viewer-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--card-bg, #1c1c1e);
  border-radius: 12px;
  overflow: hidden;
}
.pdf-viewer-title-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.pdf-viewer-icon { font-size: 18px; }
.pdf-viewer-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--ios-text, #f2f2f7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pdf-viewer-badge {
  font-size: 11px;
  font-weight: 600;
  color: #ff453a;
  background: rgba(255,69,58,0.12);
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.pdf-viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  gap: 8px;
  flex-wrap: wrap;
}
.pdf-viewer-page-nav,
.pdf-viewer-zoom,
.pdf-viewer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.pdf-btn {
  background: rgba(255,255,255,0.08);
  border: none;
  color: var(--ios-text, #f2f2f7);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
  white-space: nowrap;
}
.pdf-btn:hover { background: rgba(255,255,255,0.14); }
.pdf-btn:active { background: rgba(255,255,255,0.2); }
.pdf-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.pdf-edit-btn {
  background: rgba(10,132,255,0.15);
  color: #0a84ff;
  font-weight: 600;
}
.pdf-edit-btn:hover { background: rgba(10,132,255,0.25); }
.pdf-page-info {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--ios-text-secondary, #98989e);
}
.pdf-page-input {
  width: 40px;
  text-align: center;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px;
  color: var(--ios-text, #f2f2f7);
  font-size: 13px;
  padding: 2px 4px;
  -moz-appearance: textfield;
}
.pdf-page-input::-webkit-outer-spin-button,
.pdf-page-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.pdf-zoom-level {
  font-size: 13px;
  color: var(--ios-text-secondary, #98989e);
  min-width: 40px;
  text-align: center;
}
.pdf-viewer-canvas-container {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 16px;
  background: #2c2c2e;
}
.pdf-viewer-canvas {
  box-shadow: 0 2px 16px rgba(0,0,0,0.4);
  border-radius: 2px;
}
.pdf-viewer-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--ios-text-secondary, #98989e);
  font-size: 14px;
  padding: 40px;
}
.pdf-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: #0a84ff;
  border-radius: 50%;
  animation: pdf-spin 0.8s linear infinite;
}
.pdf-spinner-small {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: #0a84ff;
  border-radius: 50%;
  animation: pdf-spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 4px;
}
@keyframes pdf-spin { to { transform: rotate(360deg); } }
/* ── PDF Text Layer ── */
.pdf-page-container {
  position: relative;
  margin: 0 auto;
  overflow: hidden;
}

.pdf-text-layer {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.pdf-text-layer span {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: default;
  line-height: 1;
  transform-origin: 0% 0%;
}

/* Selection — visible even in view mode for copy/paste */
.pdf-text-layer span::selection {
  background: rgba(0, 100, 255, 0.3);
  color: transparent;
}

/* ── Edit Mode ── */
.pdf-text-layer.edit-mode {
  pointer-events: auto;
}

.pdf-text-layer.edit-mode span {
  cursor: text;
  border-radius: 2px;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

/* Hover shows the text area */
.pdf-text-layer.edit-mode span:hover {
  background: rgba(66, 133, 244, 0.08);
  box-shadow: 0 0 0 1px rgba(66, 133, 244, 0.2);
}

/* Focused — white background, visible text, editable */
.pdf-text-layer.edit-mode span:focus {
  color: #111;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.5);
  outline: none;
  z-index: 10;
  min-width: 20px;
}

/* Actively editing — blue tint */
.pdf-text-layer.edit-mode span.editing {
  color: #111;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.6);
}

/* Edited (committed change) — subtle yellow indicator */
.pdf-text-layer.edit-mode span.edited {
  background: rgba(255, 200, 50, 0.15);
  box-shadow: 0 0 0 1px rgba(255, 180, 0, 0.3);
}

.pdf-text-layer.edit-mode span.edited:hover {
  background: rgba(255, 200, 50, 0.25);
}

.pdf-text-layer.edit-mode span.edited:focus {
  color: #111;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(255, 180, 0, 0.6);
}

/* ── Edit Bar ── */
.pdf-edit-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(66, 133, 244, 0.1);
  border-bottom: 1px solid rgba(66, 133, 244, 0.2);
  font-size: 12px;
  color: #4285f4;
}

.pdf-edit-indicator {
  font-weight: 500;
}

.pdf-edit-count {
  font-size: 11px;
  opacity: 0.8;
}

/* Edit toggle active state */
.pdf-btn.pdf-edit-toggle.active {
  background: rgba(66, 133, 244, 0.15);
  color: #4285f4;
  border-color: rgba(66, 133, 244, 0.3);
}

/* Auto-edited spans: opaque to show changes over canvas */
.pdf-text-layer.edit-mode span.auto-edited {
  color: #111;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.5);
  z-index: 5;
}

.pdf-text-layer.edit-mode span.auto-edited:hover {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.7);
}
