/* ==========================================================
   SMILE.VIDEO PRO
   UI RESPONSIVE — DESKTOP / TABLET / MOBILE
   Paleta: grafito neutro + acento ámbar
========================================================== */

:root {
  --bg: #141517;
  --panel: #1a1b1f;
  --panel2: #232529;
  --panel3: #2b2d33;
  --border: #33363d;
  --purple: #a300f4d6;   /* acento principal (ámbar) */
  --purple2: #3902dfb7;  /* acento hover */
  --on-accent: #f6eee0; /* texto sobre el acento */
  --text: #ececee;
  --muted: #8b8f98;
  --red: #ff5a5f;
  --green: #4cc38a;

  --header-height: 56px;
  --radius: 9px;
  --touch-size: 40px;
}

/* ==========================================================
   RESET
========================================================== */

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  min-height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  border-radius: 7px;
  padding: 7px 11px;
  cursor: pointer;
  transition:
    border-color .15s,
    background .15s,
    transform .15s;
  -webkit-tap-highlight-color: transparent;
}

button:hover:not(:disabled) {
  border-color: var(--purple);
  background: var(--panel3);
}

button:active:not(:disabled) {
  transform: scale(.97);
}

button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

button.primary {
  background: var(--purple);
  border-color: var(--purple);
  color: var(--on-accent);
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: var(--purple2);
  border-color: var(--purple2);
}

button.danger:hover {
  border-color: var(--red);
  color: var(--red);
}

button.recording {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  animation: pulse 1.2s infinite;
}

input,
select,
textarea {
  background: #101113;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--purple);
}

input[type="range"] {
  padding: 0;
  accent-color: var(--purple);
  cursor: pointer;
}

input[type="color"] {
  height: 36px;
  padding: 3px;
}

input[type="checkbox"] {
  width: auto;
  accent-color: var(--purple);
}

img,
video,
canvas {
  max-width: 100%;
}

.slot {
  display: contents;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: .6; }
  100% { opacity: 1; }
}

/* ==========================================================
   CABECERA
========================================================== */

header {
  height: var(--header-height);
  width: 100%;
  position: relative;
  z-index: 30;
  background: #101113;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}

.brand {
  font-size: 19px;
  font-weight: 850;
  display: flex;
  gap: 10px;
  align-items: center;
  white-space: nowrap;
  min-width: 0;
}

.brand span {
  color: var(--purple);
}

.logo {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 10px;
  background: var(--purple);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  font-size: 19px;
  overflow: hidden;
}

.logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.header-actions {
  display: flex;
  gap: 7px;
  align-items: center;
  min-width: 0;
}

.header-actions button {
  white-space: nowrap;
}

.status {
  font-size: 11px;
  color: var(--green);
  margin-right: 8px;
  white-space: nowrap;
}

/* ==========================================================
   LAYOUT PRINCIPAL
========================================================== */

.app {
  width: 100%;
  height: calc(100vh - var(--header-height));
  height: calc(100dvh - var(--header-height));
  min-height: 0;

  display: grid;

  grid-template-columns:
    255px
    minmax(300px, 1fr)
    310px;

  grid-template-rows:
    minmax(240px, 1fr)
    335px;

  overflow: hidden;
}

.panel {
  background: var(--panel);
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--border);
  scrollbar-width: thin;
  scrollbar-color: #3c4048 transparent;
}

.panel::-webkit-scrollbar,
.timeline-scroll::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

.panel::-webkit-scrollbar-thumb,
.timeline-scroll::-webkit-scrollbar-thumb {
  background: #3c4048;
  border-radius: 10px;
}

.panel-title {
  padding: 14px 15px;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 1px;
}

/* ==========================================================
   BIBLIOTECA MULTIMEDIA
========================================================== */

.media-panel {
  grid-column: 1;
  grid-row: 1 / 3;
  min-height: 0;
}

.media-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 10px 12px;
}

.media-actions button {
  flex: 1 1 45%;
  font-size: 11px;
  min-width: 0;
}

.media-actions button.full-btn {
  flex: 1 1 100%;
}

.media-list {
  padding: 0 10px;
}

.media-item {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--panel2);
  border: 1px solid transparent;
  padding: 8px;
  border-radius: 8px;
  margin-bottom: 7px;
  cursor: pointer;
  min-width: 0;
}

.media-item:hover,
.media-item.selected {
  border-color: var(--purple);
  background: var(--panel3);
}

.thumb {
  width: 52px;
  height: 38px;
  object-fit: cover;
  border-radius: 5px;
  background: #0e0f11;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.media-info {
  min-width: 0;
  flex: 1;
}

.media-name {
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-meta {
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
}

.media-dl-btn {
  padding: 4px 7px;
  font-size: 11px;
  border-radius: 5px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  flex-shrink: 0;
}

.media-dl-btn:hover {
  color: var(--green);
  border-color: var(--green);
}

.empty {
  text-align: center;
  padding: 20px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

/* ==========================================================
   VISTA PREVIA
========================================================== */

.preview-area {
  grid-column: 2;
  grid-row: 1;

  background: #0e0f11;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  padding: 12px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.preview-top {
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 8px;
}

.slot-row {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.canvas-wrap {
  width: min(100%, 900px);
  max-height: calc(100% - 68px);
  aspect-ratio: 16 / 9;

  background: #000;
  border: 1px solid #2c2f36;
  border-radius: 4px;

  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;

  overflow: hidden;
}

#preview {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  object-fit: contain;
}

.preview-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 10px;
  max-width: 100%;
}

.preview-controls button {
  min-width: 36px;
}

.time-label {
  font-size: 11px;
  color: var(--muted);
  min-width: 125px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ==========================================================
   INSPECTOR / PROPIEDADES
========================================================== */

.properties {
  grid-column: 3;
  grid-row: 1 / 3;

  border-left: 1px solid var(--border);
  border-right: 0;
}

.section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.section h3 {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .8px;
  text-transform: uppercase;
}

.field {
  margin: 8px 0;
  min-width: 0;
}

.field label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 5px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.section button.full {
  width: 100%;
  margin-top: 6px;
}

.btn-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.btn-row button {
  flex: 1;
  min-width: 0;
  font-size: 11px;
}

/* ==========================================================
   TIMELINE
========================================================== */

.timeline {
  grid-column: 2;
  grid-row: 2;

  min-width: 0;
  min-height: 0;

  display: flex;
  flex-direction: column;

  background: #17181b;
  border-top: 1px solid var(--border);
  overflow: hidden;
}

.timeline-toolbar {
  min-height: 44px;
  height: 44px;
  flex-shrink: 0;

  display: flex;
  align-items: center;
  gap: 6px;

  padding: 0 9px;
  border-bottom: 1px solid var(--border);

  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.timeline-toolbar::-webkit-scrollbar {
  display: none;
}

.timeline-toolbar button {
  font-size: 10px;
  white-space: nowrap;
  padding: 5px 9px;
  flex-shrink: 0;
}

.dur {
  margin-left: auto;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.timeline-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  position: relative;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
}

.timeline-ruler {
  height: 26px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: #1d1f23;
  border-bottom: 1px solid var(--border);
  min-width: 900px;
  cursor: pointer;
}

.ruler-inner {
  height: 100%;
  position: relative;
}

.ruler-mark {
  position: absolute;
  top: 0;
  height: 100%;
  border-left: 1px solid #3a3d45;
  padding: 5px;
  font-size: 9px;
  color: var(--muted);
  pointer-events: none;
}

.track {
  height: 48px;
  min-width: 900px;
  display: flex;
  border-bottom: 1px solid #2a2c32;
}

.track-label {
  position: sticky;
  left: 0;
  z-index: 4;

  width: 105px;
  flex-shrink: 0;

  background: #1d1f23;
  border-right: 1px solid var(--border);

  display: flex;
  align-items: center;
  padding-left: 10px;

  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.track-content {
  position: relative;
  flex: none;
  height: 48px;
}

.clip {
  position: absolute;
  top: 4px;
  height: 39px;
  min-width: 14px;

  border-radius: 5px;
  padding: 4px 8px;

  overflow: hidden;
  font-size: 10px;
  white-space: nowrap;

  cursor: grab;
  user-select: none;
  touch-action: pan-y;

  border: 1px solid #ffffff2e;

  display: flex;
  align-items: center;
}

/* clips: tonos apagados con luminosidad parecida entre sí */
.clip.video {
  background: #3f5f8f;
}

.clip.image {
  background: #2f7468;
}

.clip.audio {
  background: #8a6330;
}

.clip.text {
  background: #85485f;
}

.clip.selected {
  outline: 2px solid var(--purple);
  z-index: 3;
  box-shadow: 0 2px 10px #00000080;
}

.clip-label {
  position: relative;
  z-index: 2;
  pointer-events: none;
  text-shadow: 0 1px 3px #000000bb;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clip-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 9px;
  cursor: ew-resize;
  z-index: 4;
  touch-action: none;
}

.clip-handle:hover {
  background: #ffffff44;
}

.clip-handle.left {
  left: 0;
}

.clip-handle.right {
  right: 0;
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--red);
  z-index: 7;
  pointer-events: none;
}

.playhead:before {
  content: "";
  position: absolute;
  top: 0;
  left: -5px;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--red);
}

/* ==========================================================
   AVISOS Y VENTANAS
========================================================== */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);

  background: var(--panel3);
  border: 1px solid var(--border);

  padding: 10px 16px;
  border-radius: 8px;

  font-size: 12px;
  display: none;
  z-index: 300;

  max-width: calc(100vw - 30px);
  text-align: center;
}

.modal-overlay {
  position: fixed;
  inset: 0;

  background: rgba(8, 8, 10, .85);

  display: none;
  align-items: center;
  justify-content: center;

  z-index: 250;
  backdrop-filter: blur(4px);
  padding: 15px;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;

  padding: 22px;
  width: min(450px, 92vw);
  max-height: 90vh;
  overflow-y: auto;

  box-shadow: 0 15px 40px #000000aa;
}

.modal-box h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.modal-box p {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* ==========================================================
   TABLETS
========================================================== */

@media (max-width: 1100px) and (min-width: 701px) {

  .app {
    grid-template-columns: 205px minmax(0, 1fr);
    grid-template-rows:
      minmax(300px, 1fr)
      320px
      auto;
  }

  .media-panel {
    grid-column: 1;
    grid-row: 1 / 4;
  }

  .preview-area {
    grid-column: 2;
    grid-row: 1;
  }

  .timeline {
    grid-column: 2;
    grid-row: 2;
  }

  .properties {
    grid-column: 2;
    grid-row: 3;

    border-left: 0;
    border-top: 1px solid var(--border);

    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
  }

  .properties > .panel-title {
    grid-column: 1 / -1;
  }

  .properties > .section {
    min-width: 0;
  }

  .canvas-wrap {
    max-width: 100%;
  }
}

/* ==========================================================
   MÓVILES GRANDES Y TABLETS PEQUEÑAS
========================================================== */

@media (max-width: 700px) {

  body {
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  header {
    height: 52px;
    padding: 0 10px;
    gap: 6px;
  }

  .brand {
    font-size: 16px;
    gap: 7px;
  }

  .logo {
    width: 29px;
    height: 29px;
    border-radius: 8px;
  }

  .header-actions {
    gap: 5px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .header-actions::-webkit-scrollbar {
    display: none;
  }

  .header-actions button {
    min-height: 34px;
    padding: 6px 9px;
    font-size: 11px;
    flex-shrink: 0;
  }

  .status {
    display: none;
  }

  .app {
    display: grid;

    width: 100%;
    height: auto;
    min-height: calc(100vh - 52px);
    min-height: calc(100dvh - 52px);

    grid-template-columns: minmax(0, 1fr);

    grid-template-rows:
      auto
      minmax(220px, 42svh)
      minmax(250px, 34svh)
      auto;

    grid-template-areas:
      "media"
      "preview"
      "timeline"
      "properties";

    overflow: visible;
  }

  .media-panel {
    grid-area: media;

    width: 100%;
    max-height: 155px;
    min-height: 0;

    overflow: hidden;

    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .media-panel .panel-title {
    padding: 9px 12px;
    font-size: 10px;
  }

  .media-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 0 10px 8px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .media-actions::-webkit-scrollbar {
    display: none;
  }

  .media-actions button {
    flex: 0 0 auto;
    min-height: 34px;
    font-size: 10px;
    white-space: nowrap;
  }

  .media-actions button.full-btn {
    flex: 0 0 auto;
  }

  .media-list {
    display: flex;
    gap: 8px;

    padding: 0 10px 9px;

    overflow-x: auto;
    overflow-y: hidden;

    scrollbar-width: thin;
    scrollbar-color: #3c4048 transparent;
  }

  .media-item {
    flex: 0 0 155px;
    min-width: 155px;
    max-width: 155px;

    height: 54px;
    margin: 0;
    padding: 6px;
    gap: 7px;
  }

  .thumb {
    width: 48px;
    height: 38px;
  }

  .media-name {
    font-size: 10px;
  }

  .media-meta {
    font-size: 9px;
  }

  .media-dl-btn {
    font-size: 10px;
    padding: 4px 6px;
  }

  .empty {
    min-width: 190px;
    padding: 8px;
    font-size: 10px;
  }

  /* PREVIEW */

  .preview-area {
    grid-area: preview;

    width: 100%;
    height: auto;
    min-height: 220px;

    padding: 9px;

    justify-content: center;
    overflow: hidden;
  }

  .preview-top {
    font-size: 10px;
    margin-bottom: 7px;
  }

  .canvas-wrap {
    width: 100%;
    max-width: 100%;
    max-height: calc(42svh - 65px);
    aspect-ratio: 16 / 9;
    flex-shrink: 1;
  }

  #preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .preview-controls {
    width: 100%;
    gap: 7px;
    margin-top: 8px;
  }

  .preview-controls button {
    min-width: 38px;
    min-height: 38px;
    padding: 6px 10px;
  }

  .time-label {
    min-width: 100px;
    font-size: 10px;
  }

  /* TIMELINE */

  .timeline {
    grid-area: timeline;

    width: 100%;
    height: auto;
    min-height: 250px;

    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }

  .timeline-toolbar {
    height: 46px;
    min-height: 46px;
    padding: 0 8px;
    gap: 5px;
  }

  .timeline-toolbar button {
    min-height: 34px;
    font-size: 10px;
    padding: 5px 8px;
  }

  .dur {
    font-size: 9px;
  }

  .timeline-scroll {
    min-height: 200px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .timeline-ruler {
    min-width: 900px;
  }

  .track {
    min-width: 900px;
    height: 48px;
  }

  .track-label {
    width: 85px;
    padding-left: 7px;
    font-size: 9px;
  }

  .track-content {
    height: 48px;
  }

  .clip {
    height: 39px;
    min-width: 18px;
    font-size: 10px;
    padding: 4px 7px;
  }

  .clip-handle {
    width: 12px;
  }

  /* PROPIEDADES */

  .properties {
    grid-area: properties;

    width: 100%;
    min-height: 0;

    border-left: 0;
    border-right: 0;
    border-top: 1px solid var(--border);

    overflow: visible;
  }

  .properties > .panel-title {
    padding: 13px 14px;
  }

  .section {
    padding: 13px;
  }

  .section h3 {
    font-size: 11px;
  }

  .field {
    margin: 10px 0;
  }

  .field label {
    font-size: 11px;
  }

  .field input,
  .field select,
  .field textarea {
    min-height: 38px;
  }

  .section button {
    min-height: 38px;
  }

  /* VENTANAS */

  .modal-overlay {
    padding: 12px;
    align-items: center;
  }

  .modal-box {
    width: 100%;
    max-width: 450px;
    padding: 18px;
    max-height: 88dvh;
    overflow-y: auto;
  }

  .toast {
    bottom: 15px;
    width: max-content;
    max-width: calc(100vw - 30px);
  }
}

/* ==========================================================
   MÓVILES PEQUEÑOS
========================================================== */

@media (max-width: 420px) {

  header {
    padding: 0 7px;
  }

  .brand {
    font-size: 14px;
    gap: 5px;
  }

  .logo {
    width: 26px;
    height: 26px;
  }

  .header-actions button {
    font-size: 10px;
    padding: 5px 7px;
  }

  .app {
    grid-template-rows:
      auto
      minmax(190px, 38svh)
      minmax(230px, 34svh)
      auto;
  }

  .media-panel {
    max-height: 145px;
  }

  .media-item {
    flex-basis: 140px;
    min-width: 140px;
    max-width: 140px;
  }

  .preview-area {
    padding: 7px;
  }

  .canvas-wrap {
    max-height: calc(38svh - 65px);
  }

  .preview-controls {
    gap: 5px;
  }

  .preview-controls button {
    min-width: 35px;
    min-height: 36px;
    padding: 5px 8px;
  }

  .time-label {
    min-width: 85px;
    font-size: 9px;
  }

  .timeline-toolbar {
    padding: 0 6px;
  }

  .timeline-toolbar button {
    padding: 5px 7px;
    font-size: 9px;
  }

  .track-label {
    width: 75px;
    font-size: 8px;
  }

  .section {
    padding: 11px;
  }

  .field-row {
    gap: 6px;
  }

  .btn-row {
    gap: 5px;
  }
}

/* ==========================================================
   MÓVILES EN HORIZONTAL
========================================================== */

@media (max-width: 900px) and (orientation: landscape) {

  @media (max-height: 550px) {

    body {
      overflow: auto;
    }

    .app {
      grid-template-columns: minmax(0, 1fr);
      grid-template-rows:
        auto
        minmax(180px, 65vh)
        260px
        auto;

      grid-template-areas:
        "media"
        "preview"
        "timeline"
        "properties";

      height: auto;
    }

    .media-panel {
      max-height: 110px;
    }

    .preview-area {
      min-height: 180px;
    }

    .canvas-wrap {
      max-height: 55vh;
    }

    .timeline {
      min-height: 250px;
    }
  }
}

/* ==========================================================
   ACCESIBILIDAD Y DISPOSITIVOS TÁCTILES
========================================================== */

@media (hover: none) and (pointer: coarse) {

  button {
    min-height: var(--touch-size);
  }

  .clip-handle {
    width: 14px;
  }

  .timeline-scroll,
  .media-list,
  .media-actions {
    -webkit-overflow-scrolling: touch;
  }

  button:hover:not(:disabled) {
    background: var(--panel2);
    border-color: var(--border);
  }
}

/* ==========================================================
   PANTALLAS MUY GRANDES
========================================================== */

@media (min-width: 1600px) {

  .app {
    grid-template-columns:
      290px
      minmax(0, 1fr)
      350px;
  }

  .preview-area {
    padding: 20px;
  }

  .canvas-wrap {
    max-width: 1150px;
  }

  .timeline {
    min-height: 335px;
  }
}

/* ==========================================================
   REDUCIR ANIMACIONES SI EL SISTEMA LO SOLICITA
========================================================== */

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}