@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@700;800&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --navy: #37474f;
  --navy-deep: #263238;
  --navy-light: #46565f;
  --bg: #f6f4f1;
  --surface: #ffffff;
  --border: #e5e0d8;
  --text: #263238;
  --muted: #6b7280;
  --accent: #8b0000;
  --accent-bright: #ad1f1f;
  --accent-dark: #5c0000;
  --success-bg: #e7f5ec;
  --success-text: #1e7a43;
  --error-bg: #fdeaea;
  --error-text: #b3261e;
  --font-display: 'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
}

.shell { display: flex; flex-direction: column; min-height: 100vh; }

.sidebar {
  width: 100%;
  flex-shrink: 0;
  background: var(--navy);
  color: #c7cdd6;
  display: flex;
  justify-content: center;
  padding: 0 20px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.sidebar-inner {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  width: 100%;
  max-width: 1100px;
  padding: 10px 0;
  gap: 6px 14px;
}

.brand { order: 1; padding: 0; border-bottom: none; flex: 0 0 auto; display: flex; align-items: center; gap: 10px; }
.brand-logo-wrap {
  display: inline-block;
  background: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  line-height: 0;
}
.brand-logo { width: 84px; height: auto; display: block; }
.brand-caption { display: none; margin-left: 10px; font-size: 11px; font-weight: 600; color: #bcbec0; letter-spacing: 0.08em; text-transform: uppercase; }
.brand.center { display: block; text-align: center; border-bottom: none; padding: 0 0 20px; }
.brand.center .brand-logo { width: 190px; margin: 0 auto; }
.brand.center .brand-caption { text-align: center; color: var(--accent); display: block; margin-left: 0; margin-top: 10px; }

.sidebar nav { order: 3; flex: 1 0 100%; display: flex; flex-direction: row; flex-wrap: nowrap; padding: 4px 0 0; gap: 4px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.sidebar nav a {
  color: #c7cdd6;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  white-space: nowrap;
}
.sidebar nav a:hover { background: var(--navy-light); }
.sidebar nav a.active { background: linear-gradient(135deg, var(--accent-bright) 0%, var(--accent) 100%); color: #fff; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08); }

.nav-toggle {
  display: none;
  order: 4;
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
}
.nav-toggle span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; }

.sidebar-footer { order: 2; margin-left: auto; padding: 0; border-bottom: none; flex: 0 0 auto; display: flex; align-items: center; gap: 12px; }
.who { display: none; font-size: 12px; color: #bcbec0; margin-bottom: 0; }
.who strong { color: #fff; }
.account-links { display: flex; align-items: center; gap: 10px; }
.logout-link { color: #f4a6a6; font-size: 13px; text-decoration: none; margin-right: 10px; }
.logout-link:hover { text-decoration: underline; }
.logout-link.active-link { color: #fff; font-weight: 600; }

/* Reserve space for the fixed bar so content never starts underneath it.
   Matches the two-row bar's real height, measured, not guessed. */
.content { flex: 1; padding: 32px 40px; max-width: 1100px; margin: 96px auto 0; width: 100%; }

@media (min-width: 640px) {
  .brand-caption { display: block; }
  .who { display: block; }
}

h1 { font-family: var(--font-display); font-size: 27px; font-weight: 800; letter-spacing: -0.01em; margin: 0 0 20px; color: var(--navy-deep); }

.wa-inbox-layout { display: flex; gap: 16px; align-items: flex-start; }
.wa-conversation-list { width: 280px; flex-shrink: 0; max-height: 70vh; overflow-y: auto; }
.wa-conversation-item { display: block; padding: 10px 12px; border-radius: 8px; text-decoration: none; color: inherit; margin-bottom: 4px; }
.wa-conversation-item:hover { background: var(--bg); }
.wa-conversation-item.active { background: var(--bg); box-shadow: inset 3px 0 0 var(--accent); }
.wa-conversation-name { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.wa-conversation-preview { font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-thread { flex: 1; display: flex; flex-direction: column; min-height: 60vh; }
.wa-thread-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 12px; }
.wa-thread-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.wa-bubble { max-width: 70%; padding: 10px 14px; border-radius: 12px; font-size: 14px; }
.wa-bubble-inbound { background: var(--bg); align-self: flex-start; }
.wa-bubble-outbound { background: linear-gradient(135deg, var(--accent-bright) 0%, var(--accent) 100%); color: #fff; align-self: flex-end; }
.wa-bubble-outbound .muted { color: rgba(255,255,255,0.75); }
.wa-bubble-outbound .link-plain { color: #fff; text-decoration: underline; }
.wa-bubble-meta { font-size: 11px; margin-top: 4px; display: flex; gap: 10px; align-items: center; }
.wa-bubble-media-img { max-width: 100%; border-radius: 8px; display: block; margin-bottom: 4px; }
.wa-bubble-media-video { max-width: 100%; border-radius: 8px; display: block; margin-bottom: 4px; }
.wa-bubble-media-audio { width: 100%; margin-bottom: 4px; }
.wa-bubble-media-doc { display: inline-block; color: inherit; text-decoration: underline; font-size: 14px; }

.wa-reply-form { display: flex; gap: 10px; margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.wa-reply-form textarea { flex: 1; resize: none; }

@media (max-width: 720px) {
  .wa-inbox-layout { flex-direction: column; }
  .wa-conversation-list { width: 100%; max-height: 200px; }
}

.timer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}
.timer-row:last-child { border-bottom: none; }
.timer-row-info { display: flex; flex-direction: column; gap: 4px; }
.timer-elapsed { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--navy); }
.timer-row-actions { display: flex; gap: 10px; align-items: center; }
.btn-stop { background: linear-gradient(135deg, #c2453b 0%, var(--error-text) 100%); box-shadow: 0 2px 6px rgba(179,38,30,0.22); }
.btn-pause { background: linear-gradient(135deg, #d99a2b 0%, #b8791a 100%); box-shadow: 0 2px 6px rgba(184,121,26,0.22); }
.btn-pause:hover { filter: brightness(1.06); }
.timer-row-paused { background: #fdf8ef; margin: 0 -12px; padding: 14px 12px; border-radius: 8px; }
.btn-stop:hover { filter: brightness(1.06); box-shadow: 0 4px 12px rgba(179,38,30,0.3); }

.type-toggle { display: flex; gap: 16px; margin-bottom: 14px; }
.type-toggle label { display: flex; align-items: center; gap: 6px; font-weight: 500; cursor: pointer; }

.quick-client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.quick-client-btn {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 16px 12px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}
.quick-client-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
h2 { font-family: var(--font-display); font-size: 19px; font-weight: 700; letter-spacing: -0.005em; margin: 0 0 16px; color: var(--navy-deep); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(38,52,56,0.04), 0 4px 14px rgba(38,52,56,0.04);
}
.panel-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.panel-header-row h2 { margin: 0; }

.az-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.az-jump a, .az-jump-disabled {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}
.az-jump a { color: var(--accent); background: var(--bg); }
.az-jump a:hover { color: #fff; background: var(--accent); }
.az-jump-disabled { color: var(--border); }

.az-group-row {
  scroll-margin-top: 112px;
}
.az-group-row td {
  background: var(--bg);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 13px;
  color: var(--muted);
  padding: 6px 12px;
  border-bottom: none;
}

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }

html { scroll-behavior: smooth; }

.section-jump {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.section-jump a {
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--surface);
  border: 1.5px solid var(--navy);
  color: var(--navy);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.section-jump a:hover { background: var(--navy); color: #fff; transform: translateY(-1px); }
.section-jump a:active { transform: translateY(0); }

.back-to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s, background 0.15s ease;
  z-index: 999;
}
.back-to-top.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.back-to-top:hover { background: var(--accent); }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}
.stat-value { font-family: var(--font-display); font-size: 28px; font-weight: 800; color: var(--navy-deep); }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
.muted { color: var(--muted); }

.badge { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; }
.badge-active { background: var(--success-bg); color: var(--success-text); }
.badge-inactive, .badge-cancelled { background: var(--error-bg); color: var(--error-text); }
.badge-renewed { background: #eaeef5; color: #3c4a63; }
.badge-expired { background: #f2ede4; color: #8a6d3b; }

.badge-status-open { background: var(--error-bg); color: var(--error-text); }
.badge-status-in_progress { background: #fdf1de; color: #c98a1e; }
.badge-status-resolved { background: var(--success-bg); color: var(--success-text); }
.badge-status-closed { background: #eaeef5; color: #3c4a63; }

.badge-priority-low { background: #eaeef5; color: #3c4a63; }
.badge-priority-normal { background: #eef3f8; color: #35597a; }
.badge-priority-high { background: #fdf1de; color: #c98a1e; }
.badge-priority-urgent { background: var(--error-bg); color: var(--error-text); }
.badge-internal { background: #f2ede4; color: #8a6d3b; }

.tab-row { display: flex; gap: 4px; }
.tab { padding: 7px 14px; border-radius: 6px; font-size: 13px; color: var(--muted); text-decoration: none; }
.tab:hover { background: var(--bg); }
.tab-active { background: var(--navy); color: #fff; }

.kv-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.kv-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 12px 6px 0; vertical-align: top; width: 140px; }
.kv-table td { padding: 6px 0; }

.thread { display: flex; flex-direction: column; gap: 12px; }
.thread-msg { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; background: var(--bg); }
.thread-msg.admin { background: #f4f8fb; }
.thread-msg.client { background: #fff; }
.thread-msg.internal { background: #fbf6ec; border-color: #e9d9b0; }
.thread-msg-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; font-size: 13px; }
.thread-msg-body { font-size: 14px; white-space: pre-wrap; }

.checkbox-row { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.checkbox-row label { display: flex; align-items: center; gap: 6px; margin: 0; }

textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

.grid-form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 20px; }
.grid-form .full-width { grid-column: 1 / -1; }
.grid-form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field-hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.grid-form input, .grid-form select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
.grid-form input:disabled { background: var(--bg); color: var(--muted); }
.form-actions { grid-column: 1 / -1; }

button {
  background: linear-gradient(135deg, var(--accent-bright) 0%, var(--accent) 100%);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(139,0,0,0.22);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
button:hover { filter: brightness(1.06); box-shadow: 0 4px 12px rgba(139,0,0,0.3); transform: translateY(-1px); }
button:active { transform: translateY(0); box-shadow: 0 2px 4px rgba(139,0,0,0.22); }
button:disabled { background: #cfd3d8; color: #8a8f96; cursor: not-allowed; box-shadow: none; transform: none; filter: none; }

.danger-zone { border-color: #e8b4ae; background: #fff8f7; }
.danger-zone h2 { color: var(--error-text); }
.danger-zone label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.danger-zone input[type="text"] { width: 100%; max-width: 320px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; margin-bottom: 12px; }
.btn-danger { background: var(--error-text); }
.btn-danger:hover { background: #8f1c15; }
.btn-danger:disabled { background: #e8b4ae; color: #fff; cursor: not-allowed; }

.row-actions { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.row-actions form { display: inline; margin: 0; }
.link-danger { background: none; border: none; padding: 0; color: var(--error-text); font-size: 13px; text-decoration: none; cursor: pointer; font-family: inherit; }
.link-danger:hover { text-decoration: underline; background: none; }
.link-plain { background: none; border: none; padding: 0; color: var(--accent); font-size: 13px; text-decoration: none; cursor: pointer; font-family: inherit; margin-right: 12px; }
.link-plain:hover { text-decoration: underline; background: none; }

.preset-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -4px; }
.chip-btn {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
.chip-btn:hover { background: var(--border); }

.usage-list { display: flex; flex-direction: column; gap: 14px; }
.usage-row-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: 14px; }
.usage-row-top a { color: var(--text); font-weight: 500; text-decoration: none; }
.usage-row-top a:hover { color: var(--accent); }
.usage-row-top .muted { font-size: 13px; }
.credit-bar-track { background: var(--bg); border: 1px solid var(--border); border-radius: 999px; height: 10px; overflow: hidden; }
.credit-bar-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.2s ease; }
.credit-bar-fill.warning { background: #c98a1e; }
.credit-bar-fill.danger { background: var(--error-text); }

.search-form { display: flex; gap: 8px; }
.search-form input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }

.flash { padding: 10px 14px; border-radius: 6px; font-size: 14px; margin-bottom: 16px; }
.flash.success { background: var(--success-bg); color: var(--success-text); }
.flash.error { background: var(--error-bg); color: var(--error-text); }

.login-body { background: var(--navy); min-height: 100vh; display: flex; align-items: center; justify-content: center; margin: 0; padding: 20px; }
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 36px;
  width: 340px;
  max-width: 100%;
}
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 4px; }
.login-card input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.login-card button { width: 100%; margin-top: 20px; padding: 11px; }

@media (max-width: 720px) {
  .content { padding: 16px; margin: 72px auto 0; }
  h1 { font-size: 22px; }

  .az-group-row { scroll-margin-top: 88px; }

  .nav-toggle { display: flex; }

  .sidebar nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    flex-wrap: nowrap;
    background: var(--navy);
    padding: 6px 0;
    box-shadow: 0 8px 16px rgba(0,0,0,0.15);
    overflow-x: visible;
    max-height: calc(100vh - 60px);
    overflow-y: auto;
  }
  .sidebar-inner.nav-open nav { display: flex; }
  .sidebar nav a { padding: 14px 20px; border-radius: 0; }

  .stat-row, .grid-form { grid-template-columns: 1fr; }
  .stat-row { gap: 10px; }
  .panel { padding: 16px; }

  .panel-header-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .search-form { width: 100%; }
  .search-form input { flex: 1; min-width: 0; }

  .tab-row { overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .section-jump { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .section-jump a { white-space: nowrap; }

  .quick-client-grid { grid-template-columns: repeat(2, 1fr); }
  .quick-client-btn { padding: 18px 10px; font-size: 16px; }
  .timer-elapsed { font-size: 26px; }
  .btn-stop { padding: 12px 22px; font-size: 16px; }
  .back-to-top { bottom: 16px; right: 16px; width: 42px; height: 42px; font-size: 18px; }
  .tab { display: inline-block; }

  /* Wide data tables scroll horizontally instead of squashing columns */
  .panel table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

  /* Ticket details: stack label/value instead of a cramped 2-column table */
  .kv-table, .kv-table tbody, .kv-table tr { display: block; width: 100%; }
  .kv-table th, .kv-table td { display: block; width: 100%; padding: 2px 0; white-space: normal; }
  .kv-table th { padding-top: 10px; }

  .thread-msg-head { flex-wrap: wrap; row-gap: 4px; }
}

@media (max-width: 420px) {
  .login-card { padding: 24px; }
  .stat-value { font-size: 22px; }
}
