:root {
  --bg-app: #ffffff;
  --bg-secondary: #f2f2f7;
  --text-primary: #000000;
  --text-secondary: #8e8e93;
  --separator: #c6c6c8;
  --accent: #007aff;
  --danger: #ff3b30;
  --bubble-user: #007aff;
  --bubble-other: #e9e9eb;

  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-family);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  position: fixed;
}

.app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Navigation Screens */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-app);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: transform;
  z-index: 10;
}

.screen-active {
  transform: translateX(0);
  z-index: 20;
}

.screen-next {
  transform: translateX(100%);
  z-index: 30;
}

.screen-prev {
  transform: translateX(-25%);
  opacity: 0.9;
  z-index: 10;
}

/* Header - iOS Style */
.header {
  min-height: calc(44px + var(--safe-area-top));
  padding-top: var(--safe-area-top);
  padding-left: 16px;
  padding-right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.15);
  /* Hairline */
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
}

.header h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
}

/* Large Title Support (Optional, mimic iOS large title behavior logic if needed, but sticky header is safer) */
.header.large {
  justify-content: flex-start;
}

.btn-icon {
  background: none;
  border: none;
  padding: 8px 0;
  /* Wider touch target */
  color: var(--accent);
  font-size: 17px;
  font-weight: 400;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.btn-icon:active {
  opacity: 0.5;
}

.btn-icon svg {
  width: 24px;
  height: 24px;
}

/* Content */
.content {
  margin-top: calc(44px + var(--safe-area-top));
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-app);
}

/* List Items - Messenger Style */
.tickets-list {
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-area-bottom);
}

.ticket-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  background: white;
  position: relative;
  cursor: pointer;
}

.ticket-item:active {
  background: #e5e5ea;
}

/* Avatar */
.ticket-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF9500, #FF3B30);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 20px;
  margin-right: 12px;
  flex-shrink: 0;
}

.ticket-info {
  flex: 1;
  height: 50px;
  /* Match avatar */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-bottom: 6px;
  padding-top: 4px;
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.15);
  /* Separator */
  min-width: 0;
}

.ticket-item:last-child .ticket-info {
  border-bottom: none;
}

.ticket-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.ticket-title {
  font-weight: 600;
  font-size: 16px;
  color: black;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticket-time {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 400;
  margin-left: 8px;
  flex-shrink: 0;
}

.ticket-preview {
  font-size: 15px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

/* Chat Screen */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px;
  padding-top: calc(54px + var(--safe-area-top));
  padding-bottom: calc(60px + var(--safe-area-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: white;
}

.msg {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.35;
  position: relative;
  word-wrap: break-word;
}

.msg-text {
  white-space: pre-wrap;
}

.msg.user {
  background-color: var(--bubble-user);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.msg.other {
  background-color: var(--bubble-other);
  color: black;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg-time {
  font-size: 11px;
  opacity: 0.7;
  text-align: right;
  margin-top: 2px;
  display: block;
}

.msg.user .msg-time {
  color: rgba(255, 255, 255, 0.8);
}

.msg.note {
  align-self: center;
  color: var(--text-secondary);
  font-size: 13px;
  margin: 10px 0;
  background: #f2f2f7;
  padding: 4px 10px;
  border-radius: 10px;
}

.msg-attachments {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.msg-attachment-image {
  display: block;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: rgba(255, 255, 255, 0.18);
  max-width: 220px;
}

.msg-attachment-image img {
  display: block;
  width: 100%;
  height: auto;
}

.msg-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  border-radius: 10px;
  padding: 8px 10px;
  max-width: 240px;
  font-size: 12px;
}

.msg.user .msg-attachment-file {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.msg.other .msg-attachment-file {
  background: rgba(0, 0, 0, 0.06);
  color: #1c1c1e;
}

.msg-attachment-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-attachment-file-size {
  display: block;
  opacity: 0.72;
  font-size: 10px;
  margin-top: 2px;
}

/* Composer */
.composer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(249, 249, 249, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid rgba(0, 0, 0, 0.15);
  padding: 8px 16px;
  padding-bottom: calc(8px + var(--safe-area-bottom));
  display: flex;
  align-items: flex-end;
  gap: 10px;
  z-index: 50;
}

.composer-main {
  flex: 1;
  min-width: 0;
}

.composer textarea {
  width: 100%;
  background: white;
  border: 1px solid #c8c8cc;
  border-radius: 20px;
  padding: 8px 12px;
  color: black;
  font-family: inherit;
  font-size: 16px;
  resize: none;
  max-height: 100px;
  outline: none;
}

.draft-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.draft-attachments:empty {
  display: none;
}

.draft-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #dbe6ff;
  background: #eef4ff;
  color: #0b4db8;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  max-width: 100%;
}

.draft-item-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draft-item-remove {
  border: none;
  background: transparent;
  color: #0b4db8;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.btn-send {
  background: var(--accent);
  color: white;
  border: none;
  width: 34px;
  /* Small circle button */
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
  /* Align with text input */
  transition: opacity 0.2s;
}

.btn-send:disabled {
  background: var(--text-secondary);
  opacity: 0.5;
}

/* Modal / Bottom Sheet */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  display: none;
  align-items: flex-end;
}

.modal.active {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  position: relative;
  width: 100%;
  background: white;
  border-radius: 16px 16px 0 0;
  padding: 20px 16px;
  padding-bottom: calc(20px + var(--safe-area-bottom));
  animation: slideUp 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 2;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }

  to {
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

.btn-close-modal {
  background: #e5e5ea;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #8e8e93;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.new-ticket-form .form-group {
  margin-bottom: 16px;
}

.new-ticket-form label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
}

.new-ticket-form input,
.new-ticket-form textarea {
  width: 100%;
  background: #f2f2f7;
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 17px;
  font-family: inherit;
  outline: none;
}

.new-ticket-form button {
  width: 100%;
  background: var(--accent);
  color: white;
  font-size: 17px;
  font-weight: 600;
  padding: 14px;
  border-radius: 14px;
  border: none;
  margin-top: 10px;
}
