/* MarketOS — Dashboard UI */

:root {
  --bg: #000000;
  --sidebar-bg: #0a0a0a;
  --surface: #111111;
  --surface-2: #1c1c1e;
  --surface-3: #2c2c2e;
  --card-bg: #0d0d0d;
  --text: #f5f5f7;
  --text-muted: #86868b;
  --text-dim: #555555;
  --text-faint: #444444;
  --text-ghost: #333333;
  --text-copy: #cccccc;
  --accent: #7C3AED;
  --accent-dark: #6d28d9;
  --accent-soft: #a78bfa;
  --border: rgba(255, 255, 255, 0.06);
  --border-input: rgba(255, 255, 255, 0.07);
  --border-light: rgba(255, 255, 255, 0.08);
  --green: #34c759;
  --red: #ff3b30;
  --yellow: #ffd60a;
  --sidebar-width: 380px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", system-ui, sans-serif;
  --ease: 0.2s ease;
  --ease-fast: 0.15s ease;
  --mobile-header-height: 52px;
  --bottom-nav-height: 60px;
  --mobile-generate-height: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body.drawer-open {
  overflow: hidden;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* ─── Layout ─── */

.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ─── */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform var(--ease);
  z-index: 200;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 24px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  flex-shrink: 0;
}

.logo {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin: 0 0 14px;
  color: var(--text);
  line-height: 1.2;
}

.logo-os {
  color: var(--accent);
}

.sidebar-divider,
.panel-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* Segmented controls */
.segmented-control {
  display: flex;
  background: var(--surface);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.segment {
  flex: 1;
  cursor: pointer;
  min-width: 0;
}

.segment input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.segment-label {
  display: block;
  text-align: center;
  padding: 7px 4px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-dim);
  transition: background var(--ease-fast), color var(--ease-fast);
  user-select: none;
  white-space: nowrap;
}

.segment input:checked + .segment-label {
  background: var(--surface-2);
  color: var(--text);
}

.market-control .segment-label {
  font-size: 11px;
  padding: 6px 2px;
}

.variant-control {
  width: 100%;
}

.variant-control .segment-label {
  font-size: 13px;
  padding: 8px;
}

/* ─── Sidebar form ─── */

.sidebar-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

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

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.sidebar-form input[type="text"],
.sidebar-form input[type="url"],
.sidebar-form textarea,
.select-field {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  transition: border-color var(--ease), box-shadow var(--ease);
  appearance: none;
  -webkit-appearance: none;
}

.form-row-2 .select-field {
  font-size: 13px;
  padding: 9px 12px;
}

.sidebar-form input::placeholder,
.sidebar-form textarea::placeholder {
  color: var(--text-dim);
  opacity: 0.7;
}

.sidebar-form input:focus,
.sidebar-form textarea:focus,
.select-field:focus {
  outline: none;
  border-color: rgba(124, 58, 237, 0.5);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.08);
}

.sidebar-form textarea {
  height: 80px;
  resize: none;
  line-height: 1.45;
}

.char-count {
  font-size: 11px;
  color: var(--text-ghost);
  text-align: right;
  margin-top: 4px;
}

.select-field {
  cursor: pointer;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 3.5L5 6.5L8 3.5' stroke='%23444' stroke-width='1.2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-color: var(--surface);
}

/* Platform pills */
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill-row {
  flex-wrap: nowrap;
}

.pill-toggle {
  cursor: pointer;
  flex: 1;
  min-width: 0;
}

.pill-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.pill-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 8px;
  border-radius: 20px;
  font-size: 11px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  color: var(--text-dim);
  transition: all var(--ease-fast);
  user-select: none;
  white-space: nowrap;
}

.pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pill-instagram .pill-dot { background: #E1306C; }
.pill-tiktok .pill-dot { background: #ffffff; }
.pill-twitter .pill-dot { background: #1DA1F2; }
.pill-facebook .pill-dot { background: #1877F2; }

.pill-instagram input:checked + .pill-label {
  border-color: #E1306C;
  background: rgba(225, 48, 108, 0.08);
  color: #E1306C;
}

.pill-tiktok input:checked + .pill-label {
  border-color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
}

.pill-twitter input:checked + .pill-label {
  border-color: #1DA1F2;
  background: rgba(29, 161, 242, 0.08);
  color: #1DA1F2;
}

.pill-facebook input:checked + .pill-label {
  border-color: #1877F2;
  background: rgba(24, 119, 242, 0.08);
  color: #1877F2;
}

/* Generate button */
.btn-generar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: auto;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  color: #ffffff;
  background: linear-gradient(135deg, #7C3AED, #6d28d9);
  cursor: pointer;
  transition: filter var(--ease-fast), transform var(--ease-fast), opacity var(--ease-fast);
}

.btn-generar:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-generar:active:not(:disabled) {
  transform: translateY(0);
}

.btn-generar:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.btn-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-loading.hidden,
.btn-text.hidden {
  display: none;
}

.btn-spinner {
  animation: spin 0.8s linear infinite;
}

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

/* Recent section */
.recent-section {
  flex-shrink: 0;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.recent-title {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-ghost);
  margin: 0 0 8px;
}

.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.recent-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

.recent-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}

.recent-dot.instagram { background: #E1306C; }
.recent-dot.tiktok { background: #ffffff; }
.recent-dot.twitter { background: #1DA1F2; }
.recent-dot.facebook { background: #1877F2; }

.recent-empty {
  font-size: 12px;
  color: var(--text-ghost);
  padding: 4px 0;
}

.link-btn {
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 12px;
  color: var(--accent-soft);
  cursor: pointer;
  padding: 6px 0 0;
  transition: color var(--ease-fast);
}

.link-btn:hover {
  color: var(--accent);
}

/* ─── Main panel ─── */

.main-panel {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 0;
  flex-shrink: 0;
}

.panel-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin: 0;
  color: var(--text);
  transition: color var(--ease);
}

.panel-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.panel-divider {
  margin: 16px 24px 0;
  flex-shrink: 0;
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: transparent;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--ease), color var(--ease), background var(--ease);
}

.btn-outline:hover {
  border-color: rgba(255, 255, 255, 0.15);
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.btn-outline.active {
  border-color: rgba(124, 58, 237, 0.4);
  color: var(--accent-soft);
  background: rgba(124, 58, 237, 0.08);
}

.btn-outline svg {
  flex-shrink: 0;
}

.control-badge {
  display: inline-block;
  min-width: 16px;
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(124, 58, 237, 0.25);
  color: var(--accent-soft);
  border-radius: 8px;
  line-height: 1.3;
}

.control-badge.hidden {
  display: none;
}

.filter-select {
  max-width: 120px;
  font-size: 12px;
  padding: 7px 28px 7px 10px;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  position: relative;
}

.panel-view {
  transition: opacity var(--ease);
}

.panel-view.hidden {
  display: none;
}

/* ─── Empty state ─── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 120px);
  text-align: center;
  transition: opacity var(--ease);
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  margin-bottom: 20px;
}

.empty-text {
  font-size: 16px;
  color: var(--text-ghost);
  margin: 0 0 6px;
}

.empty-subtext {
  font-size: 13px;
  color: #2a2a2a;
  margin: 0;
}

/* ─── Skeleton ─── */

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.skeleton-grid.hidden {
  display: none;
}

.skeleton-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, #111 0%, #1a1a1a 50%, #111 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}

.skeleton-line.w60 { width: 60%; }
.skeleton-line.w80 { width: 80%; }

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

/* ─── Card grid ─── */

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 700px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .skeleton-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  transition: border-color var(--ease);
  animation: card-fade-in 0.3s ease;
}

@keyframes card-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.1);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.platform-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  border-radius: 6px;
  line-height: 1.3;
}

.platform-badge .badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.platform-badge.instagram {
  background: rgba(225, 48, 108, 0.12);
  color: #E1306C;
}
.platform-badge.instagram .badge-dot { background: #E1306C; }

.platform-badge.tiktok {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}
.platform-badge.tiktok .badge-dot { background: #ffffff; }

.platform-badge.twitter {
  background: rgba(29, 161, 242, 0.12);
  color: #1DA1F2;
}
.platform-badge.twitter .badge-dot { background: #1DA1F2; }

.platform-badge.facebook {
  background: rgba(24, 119, 242, 0.12);
  color: #1877F2;
}
.platform-badge.facebook .badge-dot { background: #1877F2; }

.score-badge {
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  padding: 2px 8px;
}

.score-badge.score-high {
  background: rgba(52, 199, 89, 0.12);
  color: var(--green);
}

.score-badge.score-mid {
  background: rgba(255, 214, 10, 0.12);
  color: var(--yellow);
}

.score-badge.score-low {
  background: rgba(255, 59, 48, 0.12);
  color: var(--red);
}

.card-body {
  margin-bottom: 14px;
}

.card-copy-text {
  font-size: 14px;
  color: var(--text-copy);
  line-height: 1.6;
  margin: 0;
  white-space: pre-wrap;
}

.card-copy-text.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ver-mas {
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 12px;
  color: var(--accent-soft);
  cursor: pointer;
  padding: 4px 0 0;
  transition: color var(--ease-fast);
}

.ver-mas:hover {
  color: var(--accent);
}

.hashtag-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 10px;
}

.hashtag-pill {
  background: var(--surface);
  color: #666666;
  font-size: 11px;
  border-radius: 4px;
  padding: 2px 6px;
}

.card-cta {
  margin-top: 10px;
  font-size: 12px;
  color: var(--accent);
}

.card-meta-line {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-faint);
}

.card-meta-line.visual {
  font-style: italic;
}

.card-footer {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.card-actions .btn {
  flex: 1;
  min-width: 0;
}

.card-publish-x {
  margin-top: 8px;
  width: 100%;
}

.btn-publish-x {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: rgba(29, 161, 242, 0.12);
  color: #1DA1F2;
  border: 1px solid rgba(29, 161, 242, 0.3);
  transition: background var(--ease-fast);
}

.btn-publish-x:hover:not(:disabled) {
  background: rgba(29, 161, 242, 0.2);
}

.btn-publish-x:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Buttons in cards */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 7px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--ease-fast), border-color var(--ease-fast);
  line-height: 1.2;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-success {
  background: rgba(52, 199, 89, 0.12);
  color: var(--green);
  border-color: rgba(52, 199, 89, 0.2);
}

.btn-success:hover {
  background: rgba(52, 199, 89, 0.18);
}

.btn-danger {
  background: rgba(255, 59, 48, 0.12);
  color: var(--red);
  border-color: rgba(255, 59, 48, 0.2);
}

.btn-danger:hover {
  background: rgba(255, 59, 48, 0.18);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
  border-color: rgba(255, 255, 255, 0.1);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text-muted);
}

.card-actions [data-action="copy"] {
  background: rgba(124, 58, 237, 0.12);
  color: var(--accent-soft);
  border-color: rgba(124, 58, 237, 0.2);
}

.card-actions [data-action="copy"]:hover {
  background: rgba(124, 58, 237, 0.2);
}

.card-actions [data-action="regenerate"] {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
  border-color: rgba(255, 255, 255, 0.1);
}

.calendar-item-actions .btn-publish-x {
  width: 100%;
  min-height: 44px;
}

.variant-control {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.variant-control .segment-label {
  min-width: 36px;
}

.calendar-item-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

/* ─── Calendar view ─── */

.calendar-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.calendar-day {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.calendar-day-title {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-faint);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.calendar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  transition: opacity var(--ease);
}

.calendar-item:last-child {
  border-bottom: none;
}

.calendar-item-preview {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.calendar-bullet {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 6px;
}

.calendar-bullet.instagram { background: #E1306C; }
.calendar-bullet.tiktok { background: #ffffff; }
.calendar-bullet.twitter { background: #1DA1F2; }
.calendar-bullet.facebook { background: #1877F2; }

.calendar-item-text {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.calendar-item .btn-success {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid rgba(52, 199, 89, 0.3);
}

.calendar-item .btn-success:hover {
  background: rgba(52, 199, 89, 0.1);
}

.view-empty {
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
  padding: 48px 20px;
}

.view-empty.hidden {
  display: none;
}

/* ─── History ─── */

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.stat-chip {
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-dim);
}

.stat-chip strong {
  font-weight: 600;
}

.stat-chip.instagram strong { color: #E1306C; }
.stat-chip.tiktok strong { color: #ffffff; }
.stat-chip.twitter strong { color: #1DA1F2; }
.stat-chip.facebook strong { color: #1877F2; }

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

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

.history-table th,
.history-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.history-table th {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--surface);
}

.history-table tbody tr:last-child td {
  border-bottom: none;
}

.history-table tbody tr {
  transition: background var(--ease);
}

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

.history-copy {
  max-width: 280px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-table .btn-ghost {
  font-size: 12px;
  padding: 5px 10px;
  color: var(--accent-soft);
  background: rgba(124, 58, 237, 0.1);
  border-color: rgba(124, 58, 237, 0.2);
}

/* ─── Modal ─── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  background: var(--surface);
  border-radius: 16px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  animation: modal-in 0.25s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.97) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

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

.modal-close {
  background: rgba(255, 255, 255, 0.06);
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--ease-fast), color var(--ease-fast);
  flex-shrink: 0;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.modal-body {
  overflow-y: auto;
  flex: 1;
  font-size: 14px;
  line-height: 1.55;
}

.modal-body .detail-block {
  margin-bottom: 16px;
}

.modal-body .detail-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.modal-body .detail-value {
  color: var(--text-copy);
  white-space: pre-wrap;
}

.modal-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-modal-copy,
.btn-modal-x {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: filter var(--ease-fast);
}

.btn-modal-copy {
  color: #fff;
  background: linear-gradient(135deg, #7C3AED, #6d28d9);
}

.btn-modal-copy:hover {
  filter: brightness(1.1);
}

.btn-modal-x {
  color: #fff;
  background: linear-gradient(135deg, #1DA1F2, #0d8bd9);
}

.btn-modal-x:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-modal-x:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-modal-x.hidden {
  display: none;
}

#modal-title {
  display: none;
}

/* ─── Toast (inside main panel) ─── */

.toast {
  position: absolute;
  bottom: 24px;
  right: 24px;
  left: auto;
  max-width: calc(100% - 48px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
  z-index: 50;
  animation: toast-in 0.2s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  animation: none;
}

.toast-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.toast.success .toast-dot { background: var(--green); }
.toast.error .toast-dot { background: var(--red); }
.toast.info .toast-dot,
.toast .toast-dot { background: var(--accent); }

/* ─── Mobile header (hidden on desktop) ─── */

.mobile-header {
  display: none;
}

.mobile-generate-bar,
.bottom-nav {
  display: none;
}

.drawer-handle {
  display: none;
}

.market-control-mobile {
  display: none;
}

/* ─── Hamburger & overlay ─── */

.hamburger {
  display: flex;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 10px;
  background: transparent;
  border: none;
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: #ffffff;
  border-radius: 1px;
  transition: transform var(--ease);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 200;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity var(--ease);
}

.sidebar-overlay.visible {
  display: block;
  opacity: 1;
}

/* ─── Responsive: Mobile (iPhone) ─── */

@media (max-width: 768px) {
  :root {
    --mobile-chrome-bottom: calc(var(--bottom-nav-height) + var(--mobile-generate-height) + var(--safe-bottom));
  }

  .mobile-header {
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--mobile-header-height);
    padding: 0 12px 0 4px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .logo-mobile {
    font-size: 16px;
    margin: 0;
    flex-shrink: 0;
    white-space: nowrap;
  }

  .logo-desktop {
    display: block;
  }

  .market-control-desktop {
    display: flex;
  }

  .market-control-mobile {
    display: flex;
    flex: 1;
    min-width: 0;
    max-width: none;
  }

  .market-control-mobile .segment-label {
    font-size: 10px;
    padding: 8px 2px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-generate-bar,
  .bottom-nav {
    display: block;
  }

  .app-layout {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }

  /* Sidebar → bottom sheet drawer */
  .sidebar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 85vh;
    height: 85dvh;
    max-height: 85vh;
    max-height: 85dvh;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 250;
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
  }

  .sidebar.open {
    transform: translateY(0);
  }

  .drawer-handle {
    display: block;
    width: 36px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    margin: 10px auto 4px;
    flex-shrink: 0;
  }

  .sidebar-inner {
    padding: 8px 16px 24px;
    height: calc(100% - 20px);
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-header .market-control-desktop,
  .sidebar-header .logo-desktop {
    display: none;
  }

  .sidebar-header .sidebar-divider {
    margin-top: 8px;
  }

  .sidebar-form .btn-generar {
    display: flex;
    min-height: 48px;
    font-size: 16px;
    margin-top: 8px;
  }

  body.drawer-open .mobile-generate-bar {
    opacity: 0;
    pointer-events: none;
  }

  .recent-section {
    margin-top: 12px;
    padding-top: 12px;
  }

  /* Main panel full width */
  .main-panel {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .panel-header {
    padding: 12px 16px 0;
    flex-wrap: wrap;
    gap: 10px;
  }

  .panel-title {
    font-size: 17px;
  }

  .panel-divider {
    margin: 12px 16px 0;
  }

  .panel-body {
    padding: 14px 14px 8px;
    flex: 1;
    min-height: 0;
    padding-bottom: 8px;
  }

  .panel-controls {
    flex-wrap: wrap;
    gap: 6px;
  }

  .btn-outline {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 12px;
  }

  .btn-outline span:not(.control-badge) {
    display: none;
  }

  /* Inputs: 16px prevents iOS zoom */
  .sidebar-form input[type="text"],
  .sidebar-form input[type="url"],
  .sidebar-form textarea,
  .select-field {
    font-size: 16px;
    min-height: 44px;
    padding: 12px 14px;
  }

  .sidebar-form textarea {
    min-height: 88px;
  }

  .segment-label {
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .pill-label {
    min-height: 40px;
    padding: 8px 10px;
  }

  .pill-row {
    flex-wrap: wrap;
  }

  .pill-toggle {
    flex: 1 1 calc(50% - 3px);
  }

  .form-row-2 {
    grid-template-columns: 1fr;
  }

  /* Cards */
  .card-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card {
    padding: 14px;
    border-radius: 12px;
  }

  .card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .card-actions .btn {
    min-height: 44px;
    width: 100%;
  }

  .card-actions .btn-label {
    display: inline;
    font-size: 11px;
  }

  .card-publish-x {
    margin-top: 10px;
    display: block;
  }

  .btn-publish-x {
    min-height: 44px;
    font-size: 14px;
    width: 100%;
    display: flex;
  }

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

  .empty-state {
    min-height: 40vh;
  }

  .empty-icon {
    width: 96px;
    height: 96px;
  }

  /* Sticky generate bar */
  .mobile-generate-bar {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
    left: 0;
    right: 0;
    z-index: 90;
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.92);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .btn-generar-sticky {
    margin-top: 0;
    min-height: 44px;
    padding: 12px 16px;
    font-size: 16px;
  }

  .btn-loading-mobile.hidden,
  .btn-text-mobile.hidden {
    display: none;
  }

  .btn-loading-mobile {
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }

  /* Bottom navigation */
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: #0a0a0a;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--bottom-nav-height);
    padding: 6px 4px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-family: var(--font);
    cursor: pointer;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    transition: color var(--ease-fast);
  }

  .bottom-nav-item.active {
    color: var(--text);
  }

  .bottom-nav-item.active .bottom-nav-icon {
    transform: scale(1.05);
  }

  .bottom-nav-icon {
    font-size: 20px;
    line-height: 1;
    transition: transform var(--ease-fast);
  }

  .bottom-nav-label {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.02em;
    line-height: 1.2;
  }

  .bottom-nav-badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 22px);
    min-width: 16px;
    padding: 2px 5px;
    font-size: 9px;
    font-weight: 700;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    line-height: 1.2;
  }

  .bottom-nav-badge.hidden {
    display: none;
  }

  /* Toast above mobile chrome */
  .toast {
    bottom: calc(var(--mobile-chrome-bottom) + 12px);
    right: 14px;
    left: 14px;
    max-width: none;
  }

  .calendar-item {
    flex-direction: column;
    align-items: stretch;
  }

  .calendar-item-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .calendar-item-actions .btn {
    min-height: 44px;
    flex: 1;
  }

  .modal {
    padding: 12px;
    padding-bottom: calc(var(--mobile-chrome-bottom) + 12px);
  }

  .modal-card {
    padding: 20px;
  }

  .btn-modal-copy,
  .btn-modal-x {
    min-height: 48px;
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .history-table th:nth-child(1),
  .history-table td:nth-child(1) {
    font-size: 11px;
  }

  .panel-controls .filter-select {
    max-width: 100%;
    flex: 1;
  }
}
