:root {
  --bg: #050a07;
  --panel: #0b130e;
  --panel-2: #121e17;
  --line: #1e2d24;
  --text: #ecf7f0;
  --muted: #86a092;
  --accent: #1ed760;
  --accent-hover: #4ae583;
  --green: #1ed760;
  --amber: #f0a83a;
  --red: #ff5c5c;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: #3a3a48; background: #22222d; }
.btn.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.danger:hover { color: var(--red); border-color: var(--red); }
.btn.sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.icon { width: 32px; padding: 0; }

.input, select.input, textarea.input {
  width: 100%; height: 36px; padding: 0 10px; border-radius: 6px;
  border: 1px solid var(--line); background: #070d09; outline: none;
}
textarea.input { height: auto; padding: 8px 10px; resize: none; }
.input:focus { border-color: var(--accent); }
label.field { display: block; font-size: 12px; color: var(--muted); }
label.field > span { display: block; margin-bottom: 5px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 11px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.in_review { color: #9d98ff; }
.badge.changes { color: var(--amber); }
.badge.approved { color: var(--green); }

.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; text-decoration: none; }
.logo i { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; }
.logo i::after { content: ""; border-left: 8px solid #fff; border-top: 5px solid transparent; border-bottom: 5px solid transparent; margin-left: 2px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: #1b2b21; border: 1px solid #3a3a48; padding: 9px 14px; border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: 90vw;
}

/* ---------- Dashboard ---------- */
.dash { max-width: 1040px; margin: 0 auto; padding: 0 20px 60px; }
.dash header { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.dash h1 { font-size: 22px; margin: 18px 0 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.new-form { display: grid; grid-template-columns: 1.2fr 1fr 2fr 110px auto; gap: 12px; align-items: end; }
.projects { display: grid; gap: 10px; margin-top: 18px; }
.project { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.project h3 { margin: 0 0 4px; font-size: 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.project .meta { color: var(--muted); font-size: 13px; }
.project .meta b { color: var(--text); font-weight: 600; }
.project .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.add-version { grid-column: 1 / -1; display: grid; grid-template-columns: 120px 1fr auto auto; gap: 8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.login { max-width: 340px; margin: 18vh auto 0; display: grid; gap: 14px; }
.login h2 { margin: 0; font-size: 18px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; }

/* ---------- Review ---------- */
.review { height: 100vh; height: 100dvh; display: grid; grid-template-rows: 52px 1fr; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
  border-bottom: 1px solid var(--line); background: var(--panel); min-width: 0;
}
.topbar .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar .client { color: var(--muted); white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar select.input { width: auto; height: 30px; }
.workspace { display: grid; grid-template-columns: 1fr 380px; min-height: 0; }

.viewer { display: grid; grid-template-rows: 1fr auto; min-width: 0; min-height: 0; background: #050507; }
.stage { position: relative; min-height: 0; overflow: hidden; display: grid; place-items: center; }
.stage video, .stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }
.stage video { object-fit: contain; }
.stage canvas { position: absolute; pointer-events: none; }
.stage.drawing canvas { pointer-events: auto; cursor: crosshair; touch-action: none; }
.stage .notice {
  position: relative; z-index: 3; max-width: 460px; text-align: center; padding: 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.stage .notice p { color: var(--muted); margin: 8px 0 14px; }
.spinner {
  position: absolute; z-index: 2; width: 44px; height: 44px; border-radius: 50%; pointer-events: none;
  border: 4px solid rgba(255,255,255,.25); border-top-color: #fff; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.draw-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4;
  background: rgba(11,19,14,.9); border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px; font-size: 12px;
}

.controls { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 14px 10px; user-select: none; }
.timeline { position: relative; height: 30px; cursor: pointer; touch-action: none; }
.timeline .track { position: absolute; left: 0; right: 0; top: 20px; height: 5px; border-radius: 3px; background: #1f2f25; overflow: hidden; }
.timeline .buffered, .timeline .played { position: absolute; top: 0; bottom: 0; left: 0; }
.timeline .buffered { background: #35503f; }
.timeline .played { background: var(--accent); }
.timeline .head { position: absolute; top: 16px; width: 3px; height: 13px; margin-left: -1px; border-radius: 2px; background: #fff; pointer-events: none; }
.timeline .marker {
  position: absolute; top: 0; width: 16px; height: 16px; margin-left: -8px; border-radius: 50% 50% 50% 2px;
  transform: rotate(-45deg); background: var(--amber); border: 2px solid var(--panel);
  cursor: pointer; padding: 0;
}
.timeline .marker.editor { background: var(--accent); }
.timeline .marker.resolved { background: #3f5247; }
.timeline .marker.active, .timeline .marker:hover { border-color: #fff; z-index: 2; }
.timeline .tip {
  position: absolute; top: -24px; transform: translateX(-50%); background: #000; border-radius: 4px;
  padding: 1px 6px; font-size: 11px; font-variant-numeric: tabular-nums; pointer-events: none;
}
.bar { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.bar .tc { font-variant-numeric: tabular-nums; font-size: 13px; }
.bar .tc span { color: var(--muted); }
.bar .spacer { flex: 1; }
.bar input[type=range] { width: 80px; accent-color: var(--accent); }
.bar select { background: transparent; border: 0; color: var(--muted); cursor: pointer; outline: none; }

.side { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; border-left: 1px solid var(--line); background: var(--panel); }
.side-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.side-head h2 { font-size: 14px; margin: 0; flex: 1; }
.side-head h2 small { color: var(--muted); font-weight: 400; }
.tabs { display: flex; gap: 2px; background: #070d09; border-radius: 6px; padding: 2px; }
.tabs button { border: 0; background: transparent; color: var(--muted); height: 24px; padding: 0 8px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.tabs button.on { background: var(--panel-2); color: var(--text); }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 34px; z-index: 20; min-width: 230px; padding: 6px;
  background: #142019; border: 1px solid #284033; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 5px; cursor: pointer; }
.menu button:hover { background: var(--accent); }
.menu button small { display: block; color: var(--muted); }
.menu button:hover small { color: #06240f; }

.comments { overflow-y: auto; padding: 6px; }
.comment { padding: 10px; border-radius: var(--radius); border: 1px solid transparent; cursor: pointer; }
.comment:hover { background: var(--panel-2); }
.comment.active { background: var(--panel-2); border-color: var(--accent); }
.comment.resolved > .c-main { opacity: .5; }
.c-head { display: flex; align-items: center; gap: 8px; }
.avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--amber); color: #111; display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; }
.avatar.editor { background: var(--accent); color: #04140a; }
.c-author { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-role { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: #6fe89c; border: 1px solid #1f6a3c; border-radius: 3px; padding: 0 4px; }
.c-date { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }
.c-body { margin: 6px 0 0 32px; white-space: pre-wrap; overflow-wrap: anywhere; }
.chip { display: inline-block; font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 600; color: #8af0b0; background: #10321f; border-radius: 4px; padding: 0 5px; margin-right: 6px; }
.c-tools { display: flex; align-items: center; gap: 2px; margin: 6px 0 0 26px; }
.c-tools button { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.c-tools button:hover { color: var(--text); background: #1b2b21; }
.c-tools .done.on { color: var(--green); }
.replies { margin: 6px 0 0 32px; padding-left: 10px; border-left: 2px solid var(--line); display: grid; gap: 8px; }
.reply .c-body { margin-left: 0; }
.reply-box { margin: 8px 0 0 32px; display: grid; gap: 6px; }
.reply-box .row { display: flex; gap: 6px; justify-content: flex-end; }
.none { color: var(--muted); text-align: center; padding: 40px 20px; }

.composer { border-top: 1px solid var(--line); padding: 10px 12px 12px; display: grid; gap: 8px; }
.composer .row { display: flex; align-items: center; gap: 8px; }
.composer .time { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; cursor: pointer; }
.composer .time input[type=text] {
  width: 84px; height: 24px; text-align: center; border-radius: 4px; border: 1px solid transparent;
  background: #10321f; color: #8af0b0; font-weight: 600; font-variant-numeric: tabular-nums; outline: none;
}
.composer .time input[type=text]:not([readonly]) { border-color: var(--amber); }
.composer .spacer { flex: 1; }
.swatches { display: flex; gap: 5px; }
.swatches button { width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatches button.on { border-color: #fff; }
.btn.on { border-color: var(--accent); color: #6fe89c; }

@media (max-width: 860px) {
  .new-form { grid-template-columns: 1fr; }
  .project { grid-template-columns: 1fr; }
  .project .actions { justify-content: flex-start; }
  .add-version { grid-template-columns: 1fr; }
  .review { height: auto; min-height: 100dvh; }
  .workspace { grid-template-columns: 1fr; }
  .stage { aspect-ratio: 16 / 9; }
  .side { border-left: 0; border-top: 1px solid var(--line); min-height: 60vh; }
  .topbar .client, .topbar .hide-sm { display: none; }
}

/* ---------- Green theme ---------- */
body {
  background:
    radial-gradient(ellipse 90% 55% at 50% -10%, rgba(30, 215, 96, .22), transparent 70%),
    radial-gradient(ellipse 60% 40% at 85% 110%, rgba(30, 215, 96, .10), transparent 70%),
    var(--bg);
  background-attachment: fixed;
}
.btn.primary { color: #04140a; box-shadow: 0 0 18px rgba(30, 215, 96, .28); }
.btn.primary:hover { box-shadow: 0 0 24px rgba(30, 215, 96, .45); }
.btn:hover { border-color: #2f4a3a; background: #17261d; }
.btn.ghost:hover { background: var(--panel-2); border-color: transparent; }
.badge.in_review { color: #6fe89c; }
.logo i { box-shadow: 0 0 14px rgba(30, 215, 96, .5); }
.logo i::after { border-left-color: #04140a; }
.card, .topbar, .side, .controls {
  background: rgba(11, 19, 14, .82); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.card { border-radius: 14px; }
.timeline .played { box-shadow: 0 0 10px rgba(30, 215, 96, .6); }
.comment.active { box-shadow: 0 0 0 1px rgba(30, 215, 96, .25), 0 0 22px rgba(30, 215, 96, .12); }
.menu button:hover { color: #04140a; }
.input:focus { box-shadow: 0 0 0 3px rgba(30, 215, 96, .15); }
.spinner { border-top-color: var(--accent); }
::selection { background: rgba(30, 215, 96, .35); }

/* ---------- Phone layout ---------- */
.hide-sm { }
@media (max-width: 860px) {
  .hide-sm { display: none !important; }
  /* iOS phóng to trang khi chạm vào ô nhập có chữ nhỏ hơn 16px */
  .input, textarea.input, select.input, .composer .time input[type=text] { font-size: 16px; }

  /* cả trang vừa khít màn hình: video và ô nhập note đứng yên, chỉ danh sách note cuộn */
  .review { height: 100vh; height: 100dvh; min-height: 0; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); overflow: hidden; }
  .topbar { min-width: 0; }
  .topbar .btn.sm { padding: 0 8px; flex: none; }
  .topbar .spacer { flex: 1 1 0; min-width: 0; }
  .topbar .title { flex: 0 1 auto; }
  .topbar { height: 46px; gap: 8px; padding: 0 10px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .topbar .badge { display: none; }
  .topbar .btn.sm { height: 30px; }
  .workspace { display: flex; flex-direction: column; min-height: 0; }
  .viewer { display: block; flex: none; }
  .stage { width: 100%; aspect-ratio: var(--ar, 16 / 9); max-height: 40vh; max-height: 40dvh; }

  .controls { padding: 4px 10px 6px; }
  .timeline { height: 40px; }
  .timeline .track { top: 29px; }
  .timeline .head { top: 25px; }
  .timeline .marker { width: 22px; height: 22px; margin-left: -11px; top: 2px; }
  .bar { gap: 4px; margin-top: 2px; }
  .bar .btn.icon { width: 30px; height: 36px; }
  .bar #play { width: 38px; }
  .bar #mute { display: none; }
  .bar .spacer { min-width: 0; }
  .bar .tc { font-size: 12px; white-space: nowrap; }

  .side { flex: 1; min-height: 0; min-width: 0; display: flex; flex-direction: column; border-left: 0; border-top: 1px solid var(--line); }
  .composer { order: 0; border-top: 0; border-bottom: 1px solid var(--line); padding: 8px 10px; gap: 6px; }
  .composer textarea { min-height: 44px; }
  .composer .btn.sm { height: 34px; padding: 0 12px; font-size: 14px; }
  .composer .time input[type=text] { width: 96px; height: 34px; font-size: 14px; }
  .composer .time input[type=checkbox] { width: 20px; height: 20px; }
  .swatches button { width: 26px; height: 26px; }
  .side-head { order: 1; padding: 8px 10px; }
  .tabs button { height: 30px; padding: 0 10px; font-size: 13px; }
  .comments { order: 2; flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .c-tools button { padding: 6px 10px; font-size: 13px; }
  .menu { right: 0; max-width: calc(100vw - 20px); }
  .toast { bottom: max(24px, env(safe-area-inset-bottom)); }
}

.big-play {
  position: absolute; z-index: 2; width: 64px; height: 64px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(30, 215, 96, .92); color: #04140a; font-size: 24px; padding-left: 5px;
  box-shadow: 0 0 28px rgba(30, 215, 96, .5);
}
.big-play:hover { background: var(--accent-hover); }
.draw-hint.prep { top: auto; bottom: 12px; color: var(--muted); pointer-events: none; }

/* hàng công cụ của ô nhập: khi bật vẽ thì tự xuống dòng, nút Send luôn nằm trong khung */
.composer { grid-template-columns: minmax(0, 1fr); }
.composer .row { flex-wrap: wrap; row-gap: 8px; }
.composer .row .spacer { display: none; }
.composer #send { margin-left: auto; }
@media (max-width: 860px) {
  .draw-hint:not(.prep) { display: none; }
}
