  :root {
    --primary: #ff5a1f;
    --primary-hover: #e04810;
    --primary-light: #fff4ec;
    --bg-main: #f8fafc;
    --surface: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #f1f5f9;
    --border-hover: #e2e8f0;
    --radius-lg: 14px;
    --radius-md: 10px;
    --shadow-sm: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -2px rgba(0,0,0,0.03);
    --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.06), 0 4px 6px -4px rgba(0,0,0,0.04);
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
  }

  .svg-icon { display: inline-block; vertical-align: middle; }

  /* Header Bar */
  header {
    background: var(--surface);
    border-bottom: 1px solid #e2e8f0;
    height: 64px;
    padding: 0 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 2px 0 rgba(0,0,0,0.02);
  }
  .brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 1.15rem;
    color: var(--text-main);
    letter-spacing: -0.3px;
  }
  .brand-dot {
    width: 10px;
    height: 10px;
    background: var(--primary);
    border-radius: 50%;
  }
  .header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
  }
  .balance-pill {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  /* Tab Navigation Bar */
  .tab-nav {
    background: var(--surface);
    border-bottom: 1px solid #e2e8f0;
    padding: 0 28px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    position: sticky;
    top: 64px;
    z-index: 90;
  }
  .tab-nav::-webkit-scrollbar { display: none; }
  
  .tab-btn {
    padding: 14px 18px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.15s ease;
  }
  .tab-btn:hover {
    color: var(--text-main);
  }
  .tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 700;
  }

  /* App Shell Container */
  main {
    max-width: 1360px;
    margin: 0 auto;
    padding: 28px 24px 60px;
  }

  /* Tab Panels */
  .tab-panel {
    display: flex;
    flex-direction: column;
    gap: 24px;
    animation: fadeIn 0.2s ease-out;
  }
  @keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
  }
  @keyframes spin {
    to { transform: rotate(360deg); }
  }
  @keyframes fadeInChart {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  /* Cards with float shadow */
  .card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid #f1f5f9;
    transition: box-shadow 0.2s, border-color 0.2s;
  }
  .card:hover {
    border-color: #e2e8f0;
    box-shadow: var(--shadow-md);
  }
  .card h2 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  /* Form Elements */
  label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
  }
  input[type="text"], input[type="tel"], input[type="password"], input[type="number"], input[type="url"], select, textarea {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    border: 1px solid #cbd5e1;
    background: #fff;
    color: var(--text-main);
    font-size: 0.9rem;
    margin-bottom: 14px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255, 90, 31, 0.12);
  }
  textarea { min-height: 80px; resize: vertical; }

  /* Tag Chips Input */
  .tags-input-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: var(--radius-md);
    border: 1px solid #cbd5e1;
    background: #fff;
    margin-bottom: 14px;
    min-height: 42px;
    cursor: text;
  }
  .tags-input-container:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255, 90, 31, 0.12);
  }
  .tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
  }
  .tag-chip .remove-tag {
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: bold;
    line-height: 1;
    color: var(--primary);
    margin-left: 2px;
  }
  .tag-chip .remove-tag:hover {
    color: var(--primary-hover);
  }

  /* Segment Selection Cards */
  .segment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 8px;
  }
  .segment-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
    background: var(--surface);
    border: 1.5px solid #e2e8f0;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .segment-card:hover {
    border-color: #cbd5e1;
    background: #fdfdfd;
  }
  .segment-card.selected {
    border-color: var(--primary);
    background: var(--primary-light);
  }
  .segment-card input[type="radio"] {
    margin-top: 3px;
    accent-color: var(--primary);
  }
  .seg-title {
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .seg-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
    line-height: 1.3;
  }
  .tags-filter-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
  }
  .tag-filter-chip {
    padding: 4px 10px;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    background: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
  }
  .tag-filter-chip.selected {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
  }

  /* Buttons */
  button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: #fff;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
  }
  button:hover { background: var(--primary-hover); }
  button:active { transform: scale(0.98); }
  button:disabled { opacity: 0.45; cursor: not-allowed; }
  button.secondary {
    background: #f1f5f9;
    color: var(--text-main);
    border: 1px solid #e2e8f0;
  }
  button.secondary:hover { background: #e2e8f0; }

  /* Grid Layouts */
  .kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }
  @media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }
  @media (max-width: 900px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

  .kpi-card {
    background: var(--surface);
    border: 1px solid #f1f5f9;
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    position: relative;
    transition: all 0.2s ease;
  }
  .kpi-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
  }
  .kpi-card.kpi-emerald::before,
  .kpi-card.kpi-orange::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .kpi-card.kpi-emerald::before {
    background: #10b981;
  }
  .kpi-card.kpi-emerald .kpi-icon {
    background: #ecfdf5;
    color: #10b981;
  }
  .kpi-card.kpi-orange::before {
    background: #f97316;
  }
  .kpi-card.kpi-orange .kpi-icon {
    background: #fff7ed;
    color: #f97316;
  }

  .kpi-body {
    padding-top: 30px;
  }

  .kpi-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: #f8fafc;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .kpi-chart-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 30px;
    height: 30px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .kpi-chart-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-light);
    transform: scale(1.08);
  }
  .kpi-num {
    font-size: 1.7rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.1;
    letter-spacing: -0.5px;
  }
  .kpi-growth {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 700;
    margin-left: 6px;
    vertical-align: middle;
  }
  .kpi-growth.positive {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
  }
  .kpi-growth.negative {
    background: #fff1f2;
    color: #be123c;
    border: 1px solid #fecdd3;
  }
  .kpi-growth.neutral {
    background: #f8fafc;
    color: #64748b;
    border: 1px solid #e2e8f0;
  }

  .kpi-num.loading {
    color: transparent;
    border-radius: 6px;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.3s infinite;
    min-width: 60px;
    display: inline-block;
  }
  @keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }
  @media (prefers-reduced-motion: reduce) {
    .kpi-num.loading { animation: none; }
  }

  .kpi-spark {
    width: 100%;
    height: 28px;
    margin-top: 6px;
    display: block;
  }
  .kpi-spark polyline {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .kpi-spark .spark-dot {
    stroke-width: 2;
  }
  .kpi-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 4px;
  }

  /* SMS Tab 2-Column Responsive Layout */
  .sms-tab-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(310px, 350px);
    gap: 24px;
    align-items: start;
  }
  .sms-left-col {
    display: flex;
    flex-direction: column;
    gap: 20px;
  }
  @media (max-width: 960px) {
    .sms-tab-layout {
      grid-template-columns: 1fr;
    }
  }

  /* CSS iPhone Mockup Floating Screen */
  .iphone-sticky-wrapper {
    position: sticky;
    top: 140px;
  }
  .iphone-mockup {
    width: 100%;
    max-width: 340px;
    margin: 0 auto;
    background: #ffffff;
    border-radius: 44px;
    padding: 12px;
    box-shadow: 0 20px 40px -15px rgba(15, 23, 42, 0.12), 0 0 0 10px #1e293b, 0 0 0 12px #e2e8f0;
    position: relative;
  }
  .iphone-top-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    height: 20px;
    position: absolute;
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
  }
  .iphone-camera {
    width: 12px;
    height: 12px;
    background: #0f172a;
    border-radius: 50%;
  }
  .iphone-speaker {
    width: 50px;
    height: 4px;
    background: #0f172a;
    border-radius: 4px;
  }
  .iphone-screen {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 34px;
    padding: 36px 14px 20px;
    min-height: 480px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
  }
  .iphone-header {
    text-align: center;
    padding-bottom: 10px;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 14px;
  }
  .iphone-time {
    font-size: 0.7rem;
    font-weight: 700;
    color: #64748b;
    display: block;
    margin-bottom: 6px;
  }
  .iphone-header-info {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .iphone-avatar {
    width: 36px;
    height: 36px;
    background: #e2e8f0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    margin-bottom: 4px;
  }
  .iphone-sender-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: #0f172a;
  }
  .iphone-subtext {
    font-size: 0.68rem;
    color: #94a3b8;
  }
  .iphone-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .iphone-chat-date {
    text-align: center;
    font-size: 0.65rem;
    color: #94a3b8;
    font-weight: 600;
    text-transform: uppercase;
  }
  .iphone-bubble.green-bubble {
    background: #22c55e;
    color: #ffffff;
    padding: 12px 14px;
    border-radius: 18px 18px 4px 18px;
    align-self: flex-end;
    max-width: 92%;
    box-shadow: 0 2px 4px rgba(34, 197, 94, 0.2);
    word-break: break-word;
  }
  .iphone-message-body {
    font-size: 0.84rem;
    line-height: 1.4;
    white-space: pre-wrap;
  }
  .iphone-bubble-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    font-size: 0.65rem;
    opacity: 0.85;
  }
  .iphone-banner-container {
    align-self: flex-end;
    max-width: 92%;
    margin-bottom: 4px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  }
  .iphone-banner-container img {
    width: 100%;
    max-height: 130px;
    object-fit: cover;
    display: block;
  }
  .iphone-footer-notice {
    font-size: 0.68rem;
    color: #64748b;
    text-align: center;
    margin-top: auto;
    padding-top: 10px;
  }

  /* Schedule Editor */
  .schedule-editor { display: flex; flex-direction: column; gap: 6px; }
  .sched-row { display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; font-size: 0.85rem; }
  .sched-row.closed-row { opacity: 0.5; }
  .sched-day { font-weight: 600; color: var(--text-main); font-size: 0.82rem; }
  .sched-times { display: flex; gap: 6px; align-items: center; color: var(--text-muted); }
  .sched-times input[type="time"] {
    width: auto; flex: 1; min-width: 0; padding: 7px 8px; font-size: 0.82rem; border: 1px solid #cbd5e1; border-radius: var(--radius-md); background: #fff; color: var(--text-main); margin-bottom: 0; outline: none; transition: border-color 0.15s, box-shadow 0.15s; font-family: inherit;
  }
  .sched-times input[type="time"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(255, 90, 31, 0.12); }
  .sched-times input[type="time"]:disabled { background: #f4f4f5; cursor: not-allowed; }
  .sched-toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; }
  .sched-toggle input { accent-color: var(--primary); cursor: pointer; width: 15px; height: 15px; }

  /* Chart Modal */
  .chart-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15,23,42,0.6); backdrop-filter: blur(4px); z-index: 9999; display: flex; align-items: center; justify-content: center; animation: fadeIn 0.2s ease-out; }
  .chart-modal.hidden { display: none !important; }
  .chart-modal-content { background: var(--surface); border-radius: var(--radius-lg); box-shadow: 0 20px 60px rgba(0,0,0,0.2); width: 90%; max-width: 700px; max-height: 80vh; overflow: hidden; animation: slideUp 0.3s ease-out; }
  @keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
  .chart-modal-header { padding: 20px 24px; border-bottom: 1px solid #e2e8f0; display: flex; justify-content: space-between; align-items: center; }
  .chart-modal-header h3 { font-size: 1.1rem; font-weight: 700; margin: 0; }
  .chart-modal-close { background: none; border: none; font-size: 1.8rem; color: var(--text-muted); cursor: pointer; line-height: 1; padding: 0; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 6px; transition: all 0.2s; }
  .chart-modal-close:hover { background: var(--bg-main); color: var(--text-main); }
  .chart-modal-body { padding: 24px; max-height: calc(80vh - 80px); overflow-y: auto; }
  .kpi-sub { font-size: 0.72rem; color: #10b981; font-weight: 700; margin-top: 2px; }

  .charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
  @media (max-width: 900px) { .charts-grid { grid-template-columns: 1fr; } }

  .grid-2col { display: grid; grid-template-columns: 380px 1fr; gap: 24px; }
  @media (max-width: 960px) { .grid-2col { grid-template-columns: 1fr; } }

  .grid-3col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 24px; align-items: start; }

  .settings-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr); gap: 24px; align-items: start; }
  .settings-side { display: flex; flex-direction: column; gap: 24px; }
  @media (max-width: 1100px) { .settings-layout { grid-template-columns: 1fr; } }

  /* Table styling */
  .table-container { overflow-x: auto; margin-top: 8px; }
  table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
  th { text-align: left; padding: 10px 12px; background: #f8fafc; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid #e2e8f0; }
  td { padding: 12px; border-bottom: 1px solid #e2e8f0; color: var(--text-main); vertical-align: middle; }
  tr:last-child td { border-bottom: none; }

  .selected-campaign-row { background: var(--primary-light) !important; border-left: 4px solid var(--primary); }
  .badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 0.73rem; font-weight: 700; }
  .badge-active { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
  .badge-inactive { background: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }
  .badge-amber { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
  .badge-orange { background: var(--primary-light); color: var(--primary); border: 1px solid var(--primary); }
  .badge-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

  #loginScreen { max-width: 400px; margin: 80px auto; padding: 32px; border-radius: 16px; box-shadow: var(--shadow-md); }
  .winner-box { background: var(--primary-light); border: 1px solid var(--primary); border-radius: var(--radius-md); padding: 16px; margin-top: 14px; font-size: 0.9rem; }

  .msg-box { margin-top: 8px; font-size: 0.85rem; font-weight: 600; }
  .msg-success { color: #16a34a; }
  .msg-error { color: #dc2626; }
  .hidden { display: none !important; }

  .chart-wrapper { width: 100%; height: 180px; position: relative; }
  .chart-wrapper svg { width: 100%; height: 100%; overflow: visible; }
  .empty-chart { height: 180px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 0.88rem; background: #f8fafc; border-radius: var(--radius-md); border: 1px dashed #cbd5e1; }
  .chart-point circle { transition: all 0.2s ease; cursor: pointer; }
  .chart-point:hover circle { r: 6; }
