/* ============================================================
   CQP LINE Broadcast Tool — Styles
   Colors: navy #024190 | teal #007BB9 | yellow #FFDF00 | orange #FE5F01
   ============================================================ */

:root {
  --navy:        #024190;
  --navy-dark:   #012d64;
  --teal:        #007BB9;
  --yellow:      #FFDF00;
  --orange:      #FE5F01;
  --white:       #ffffff;
  --bg:          #f0f4f8;
  --bg-card:     #ffffff;
  --border:      #dde3ec;
  --text:        #1a202c;
  --text-muted:  #6b7280;
  --success:     #10b981;
  --danger:      #ef4444;
  --radius:      10px;
  --shadow:      0 2px 12px rgba(2,65,144,0.08);
  --sidebar-w:   220px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Sarabun', sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

h1, h2, h3, h4 { font-family: 'Baloo 2', sans-serif; font-weight: 700; }

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Login ─────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy-dark) 0%, var(--navy) 100%);
}

.login-box {
  background: var(--white);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.25);
}

.login-logo {
  text-align: center;
  margin-bottom: 36px;
}
.login-logo-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}
.login-logo h1 {
  font-size: 1.6rem;
  color: var(--navy);
}
.login-logo p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Layout ─────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand .brand-icon { font-size: 1.5rem; }
.sidebar-brand h2 {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.3;
  margin-top: 6px;
}
.sidebar-brand p { font-size: 0.75rem; color: rgba(255,255,255,0.55); margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 12px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-weight: 500;
  font-size: 0.9rem;
}
.nav-item:hover {
  background: rgba(255,255,255,0.07);
  color: var(--white);
}
.nav-item.active {
  background: rgba(255,223,0,0.12);
  color: var(--yellow);
  border-left-color: var(--yellow);
}
.nav-item .nav-icon { font-size: 1.1rem; width: 22px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h2 { font-size: 1.15rem; color: var(--navy); }

.page {
  padding: 28px;
  flex: 1;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--navy);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--yellow);
  display: inline-block;
}

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--navy);
  margin-bottom: 6px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'Sarabun', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: #fafbfc;
  transition: border-color 0.2s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--teal);
  background: var(--white);
}
.form-group textarea { resize: vertical; min-height: 90px; }
.form-group .hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { opacity: 0.88; transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--navy);  color: var(--white); }
.btn-yellow  { background: var(--yellow); color: var(--navy-dark); }
.btn-orange  { background: var(--orange); color: var(--white); }
.btn-teal    { background: var(--teal);   color: var(--white); }
.btn-outline { background: transparent; color: var(--navy); border: 1.5px solid var(--navy); }
.btn-danger  { background: var(--danger); color: var(--white); }
.btn-sm      { padding: 5px 12px; font-size: 0.8rem; }
.btn-block   { width: 100%; justify-content: center; }

/* ── Segments ──────────────────────────────────────────────── */
.segment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.segment-opt {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.segment-opt:hover { border-color: var(--teal); background: #f0f8ff; }
.segment-opt.selected { border-color: var(--navy); background: rgba(2,65,144,0.06); }
.segment-opt .seg-icon { font-size: 1.6rem; margin-bottom: 6px; }
.segment-opt .seg-label { font-weight: 600; font-size: 0.88rem; color: var(--navy); }
.segment-opt .seg-desc  { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

.count-badge {
  display: inline-block;
  background: var(--yellow);
  color: var(--navy-dark);
  padding: 4px 14px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.9rem;
  margin-left: 10px;
}

/* ── Message type tabs ─────────────────────────────────────── */
.msg-type-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.msg-tab {
  padding: 8px 16px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--white);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: all 0.2s;
}
.msg-tab:hover { border-color: var(--teal); color: var(--teal); }
.msg-tab.active { border-color: var(--navy); color: var(--navy); background: rgba(2,65,144,0.07); }

/* ── Compose layout ────────────────────────────────────────── */
.compose-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  align-items: start;
}

/* ── Phone preview ─────────────────────────────────────────── */
.phone-wrap {
  position: sticky;
  top: 80px;
}
.phone-frame {
  width: 270px;
  min-height: 480px;
  background: #ededed;
  border-radius: 28px;
  border: 8px solid #222;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  margin: 0 auto;
}
.phone-bar {
  background: var(--navy);
  height: 44px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 8px;
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
}
.phone-bar .bar-back { font-size: 1rem; }
.phone-body {
  background: #c8e4ff;
  min-height: 436px;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.phone-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: rgba(0,0,0,0.35);
  font-size: 0.85rem;
  min-height: 400px;
}
.phone-empty .empty-icon { font-size: 2.5rem; }

/* LINE message bubbles */
.line-msg { display: flex; gap: 8px; align-items: flex-end; }
.line-bubble {
  background: white;
  border-radius: 16px 16px 16px 4px;
  padding: 10px 14px;
  max-width: 80%;
  font-size: 0.82rem;
  line-height: 1.5;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  word-break: break-word;
  white-space: pre-wrap;
}
.line-img-bubble {
  border-radius: 12px;
  overflow: hidden;
  max-width: 80%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.line-img-bubble img {
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  display: block;
}
.line-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  font-size: 0.78rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.12);
  max-width: 90%;
}
.line-card-img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  background: #dde;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}
.line-card-img img { width: 100%; height: 100%; object-fit: cover; }
.line-card-body { padding: 8px 10px; }
.line-card-body strong { font-size: 0.82rem; display: block; }
.line-card-body p { font-size: 0.72rem; color: #666; margin-top: 2px; }
.line-card-btn {
  display: block;
  background: var(--navy);
  color: white;
  text-align: center;
  padding: 7px;
  font-size: 0.78rem;
  font-weight: 700;
  margin-top: 6px;
  border-radius: 6px;
}
.line-flex-label {
  background: rgba(2,65,144,0.1);
  color: var(--navy);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  text-align: center;
  max-width: 90%;
}
.carousel-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  max-width: 100%;
  scroll-snap-type: x mandatory;
}
.carousel-scroll .line-card { min-width: 140px; scroll-snap-align: start; }
.preview-action-btn {
  display: block;
  background: var(--orange);
  color: white;
  text-align: center;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  max-width: 90%;
}

/* ── Carousel builder ──────────────────────────────────────── */
.carousel-card-item {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
  position: relative;
  background: #fafbfc;
}
.carousel-card-item .card-num {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}
.carousel-card-item .remove-card {
  position: absolute;
  top: 12px; right: 12px;
  background: none; border: none; cursor: pointer;
  color: var(--danger); font-size: 1.1rem;
}
.card-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── Button list builder ───────────────────────────────────── */
.btn-list-item {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.btn-list-item .remove-btn-item {
  background: none; border: none;
  cursor: pointer; color: var(--danger); font-size: 1.1rem;
  padding: 8px;
}

/* ── History table ─────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.data-table th {
  background: var(--navy);
  color: var(--white);
  padding: 10px 14px;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.data-table th:first-child { border-radius: 8px 0 0 8px; }
.data-table th:last-child  { border-radius: 0 8px 8px 0; }
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:hover td { background: #f7f9fc; }
.data-table tr:last-child td { border-bottom: none; }

/* ── Tags ──────────────────────────────────────────────────── */
.tag-badge {
  display: inline-block;
  background: rgba(0,123,185,0.12);
  color: var(--teal);
  border: 1px solid rgba(0,123,185,0.25);
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  margin: 2px;
}

/* ── User avatar ───────────────────────────────────────────── */
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--navy);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: white;
  flex-shrink: 0;
  vertical-align: middle;
}
.user-cell { display: flex; align-items: center; gap: 10px; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: var(--white);
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.25);
}
.modal-title {
  font-size: 1.05rem;
  color: var(--navy);
  margin-bottom: 20px;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
}

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  margin-bottom: 12px;
}
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #93c5fd; }

/* ── Toast ─────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--navy-dark);
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
  z-index: 9999;
  display: none;
  max-width: 340px;
}
#toast.show { display: block; animation: slideIn 0.3s ease; }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Misc ─────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); font-size: 0.85rem; }
.step-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  background: var(--navy);
  color: white;
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: 700;
  margin-right: 8px;
  flex-shrink: 0;
}
.step-header {
  display: flex;
  align-items: center;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--navy);
  margin-bottom: 16px;
}
.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.flex-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pagination { display: flex; gap: 6px; align-items: center; margin-top: 16px; }
.page-btn {
  min-width: 34px; height: 34px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  transition: all 0.2s;
}
.page-btn:hover, .page-btn.active { background: var(--navy); color: white; border-color: var(--navy); }
.stat-pill {
  background: rgba(2,65,144,0.07);
  color: var(--navy);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

@media (max-width: 900px) {
  .sidebar { width: 60px; }
  .sidebar-brand h2, .sidebar-brand p, .nav-item span { display: none; }
  .main-content { margin-left: 60px; }
  .compose-layout { grid-template-columns: 1fr; }
  .phone-wrap { display: none; }
  .card-grid-2 { grid-template-columns: 1fr; }
  .segment-grid { grid-template-columns: repeat(2, 1fr); }
}
