:root {
  --orange: #e8650a; --orange-light: #f07c2a; --orange-glow: rgba(232,101,10,0.35);
  --dark: #111114; --dark2: #18181d; --dark3: #1f1f26;
  --text: #e8e8f0; --text-muted: rgba(232,232,240,0.55);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: 'Inter', sans-serif; background: var(--dark); color: var(--text); }

/* Navbar */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 32px; height: 60px;
  background: rgba(17,17,20,.75); backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(255,255,255,.06);
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
}
.logo img { height: 36px; filter: brightness(0) invert(1); }
.user-menu { position: relative; }
.user-btn {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08);
  border-radius: 100px; padding: 6px 14px 6px 8px;
  cursor: pointer; transition: background .2s, border-color .2s;
}
.user-btn:hover { background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.14); }
.user-avatar-sm {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--orange), var(--orange-light));
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 800; color: #fff; flex-shrink: 0; overflow: hidden;
}
.user-avatar-sm img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.user-name { font-size: .82rem; font-weight: 600; color: var(--text); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chevron { font-size: .9rem; color: var(--text-muted); transition: transform .2s; }
.user-menu.open .user-chevron { transform: rotate(180deg); }
.user-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: rgba(24,24,29,.95); backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,.1); border-radius: 12px;
  padding: 6px; min-width: 180px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  display: none; animation: fade-up .15s ease both;
}
.user-menu.open .user-dropdown { display: block; }
.dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  font-size: .85rem; color: var(--text-muted);
  cursor: pointer; transition: background .15s, color .15s; text-decoration: none;
}
.dropdown-item:hover { background: rgba(255,255,255,.07); color: var(--text); }
.dropdown-item .material-icons { font-size: 1rem; }
.dropdown-item.danger:hover { background: rgba(244,67,54,.1); color: #ef9a9a; }
.dropdown-divider { height: 1px; background: rgba(255,255,255,.06); margin: 4px 0; }

/* Layout */
.app-wrap { overflow: hidden; width: 100vw; height: 100vh; height: 100dvh; position: relative; }
.app { display: flex; flex-direction: row; height: 100%; padding-top: 60px; }

/* Sidebar */
.sidebar {
  width: 300px; flex-shrink: 0;
  border-right: 1px solid rgba(255,255,255,.06);
  display: flex; flex-direction: column; background: var(--dark2);
}
.sidebar-header { padding: 20px 20px 14px; border-bottom: 1px solid rgba(255,255,255,.06); }
.sidebar-title { font-size: .72rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .8px; margin-bottom: 12px; }
.new-btn {
  width: 100%; background: linear-gradient(135deg, var(--orange), var(--orange-light));
  color: #fff; border: none; border-radius: 8px; padding: 10px;
  font-family: 'Inter', sans-serif; font-size: .85rem; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: opacity .2s; box-shadow: 0 3px 12px var(--orange-glow);
}
.new-btn:hover { opacity: .9; }
.new-btn .material-icons { font-size: 1rem; }
.tickets-list { flex: 1; overflow-y: auto; padding: 10px; }
.tickets-list::-webkit-scrollbar { width: 3px; }
.tickets-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 2px; }
.ticket-item {
  padding: 12px 14px; border-radius: 10px; cursor: pointer;
  transition: background .15s; margin-bottom: 4px; border: 1px solid transparent;
}
.ticket-item:hover { background: rgba(255,255,255,.04); }
.ticket-item.active { background: rgba(232,101,10,.08); border-color: rgba(232,101,10,.25); }
.ti-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.ti-num { font-size: .7rem; color: var(--text-muted); font-weight: 600; }
.ti-status { font-size: .65rem; font-weight: 700; padding: 2px 7px; border-radius: 100px; }
.s-open    { background: rgba(232,101,10,.15); color: var(--orange-light); }
.s-waiting { background: rgba(255,193,7,.12);  color: #ffc107; }
.s-answered{ background: rgba(76,175,80,.12);  color: #81c784; }
.s-closed  { background: rgba(255,255,255,.06); color: var(--text-muted); }
.ti-subj { font-size: .88rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 4px; }
.ti-date { font-size: .7rem; color: var(--text-muted); }
.tickets-empty { text-align: center; padding: 32px 16px; color: var(--text-muted); font-size: .82rem; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--dark); }
.main-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); gap: 12px; }
.main-empty .material-icons { font-size: 3.5rem; opacity: .2; }
.main-empty p { font-size: .9rem; }

/* Ticket header */
.ticket-header {
  padding: 18px 28px; border-bottom: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-shrink: 0;
}
.th-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.th-info { min-width: 0; }
.th-title { font-size: 1rem; font-weight: 700; color: #fff; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.th-meta { font-size: .78rem; color: var(--text-muted); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.th-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn-close-t {
  background: rgba(244,67,54,.08); border: 1px solid rgba(244,67,54,.25);
  color: #ef9a9a; border-radius: 7px; padding: 7px 14px;
  font-family: 'Inter', sans-serif; font-size: .78rem; font-weight: 600;
  cursor: pointer; transition: background .2s; display: flex; align-items: center; gap: 5px;
}
.btn-close-t:hover { background: rgba(244,67,54,.16); }
.btn-close-t .material-icons { font-size: .9rem; }

/* Back button (mobile only) */
.btn-back {
  display: none; align-items: center;
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 4px; flex-shrink: 0; border-radius: 6px;
  transition: color .2s;
}
.btn-back:hover { color: var(--text); }
.btn-back .material-icons { font-size: 1.4rem; }

/* Messages */
.messages-area { flex: 1; overflow-y: auto; padding: 24px 28px; display: flex; flex-direction: column; gap: 14px; }
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 2px; }
.msg { display: flex; flex-direction: column; max-width: 72%; }
.msg.user  { align-self: flex-end; align-items: flex-end; }
.msg.admin { align-self: flex-start; align-items: flex-start; }
.msg-who { font-size: .7rem; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.msg-bubble { padding: 10px 15px; border-radius: 14px; font-size: .88rem; line-height: 1.65; word-break: break-word; margin-bottom: 3px; }
.msg-bubble:last-of-type { margin-bottom: 0; }
.msg.user  .msg-bubble { background: linear-gradient(135deg, var(--orange), var(--orange-light)); color: #fff; border-radius: 14px 14px 3px 14px; }
.msg.admin .msg-bubble { background: var(--dark3); color: var(--text); border: 1px solid rgba(255,255,255,.07); border-radius: 14px 14px 14px 3px; }
.msg-time { font-size: .68rem; color: var(--text-muted); margin-top: 4px; }

/* Closed bar */
.closed-bar {
  margin: 0 28px 16px; background: rgba(255,255,255,.03); border: 1px solid rgba(255,255,255,.07);
  border-radius: 8px; padding: 10px 16px; font-size: .82rem; color: var(--text-muted);
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.closed-bar .material-icons { font-size: 1rem; }

/* Reply */
.reply-area { padding: 12px 28px 16px; border-top: 1px solid rgba(255,255,255,.06); flex-shrink: 0; }
.reply-wrap {
  display: flex; gap: 8px; align-items: center;
  background: var(--dark3); border: 1.5px solid rgba(255,255,255,.07);
  border-radius: 12px; padding: 6px 6px 6px 14px; transition: border-color .2s;
}
.reply-wrap:focus-within { border-color: var(--orange); }
.reply-ta {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-family: 'Inter', sans-serif; font-size: .88rem;
  resize: none; height: 36px; max-height: 120px; line-height: 1.5;
  padding: 7px 0; overflow-y: hidden;
}
.reply-ta::placeholder { color: rgba(232,232,240,.25); }
.reply-ta:disabled { opacity: .5; }
.reply-send-btn {
  background: linear-gradient(135deg, var(--orange), var(--orange-light));
  color: #fff; border: none; border-radius: 7px; width: 32px; height: 32px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: opacity .2s;
}
.reply-send-btn:disabled { opacity: .4; cursor: not-allowed; }
.reply-send-btn .material-icons { font-size: .95rem; }
.reply-hint { font-size: .7rem; color: var(--text-muted); margin-top: 5px; }

/* Modals */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: rgba(24,24,29,.95); backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,.1); border-radius: 16px;
  padding: 32px; width: 100%; max-width: 500px;
  box-shadow: 0 24px 64px rgba(0,0,0,.5); animation: modal-in .2s ease both;
}
.modal-box.modal-sm { max-width: 400px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.modal-title { font-size: 1.1rem; font-weight: 800; color: #fff; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; border-radius: 6px; transition: color .2s, background .2s; }
.modal-close:hover { color: var(--text); background: rgba(255,255,255,.07); }
.modal-close .material-icons { font-size: 1.3rem; display: block; }
.modal-desc { font-size: .88rem; color: var(--text-muted); line-height: 1.65; margin-bottom: 24px; }
.modal-actions { display: flex; gap: 10px; }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 8px; }
.form-input {
  width: 100%; background: rgba(255,255,255,.04); border: 1.5px solid rgba(255,255,255,.08);
  border-radius: 9px; padding: 11px 14px; color: var(--text);
  font-family: 'Inter', sans-serif; font-size: .9rem; outline: none;
  transition: border-color .2s, background .2s;
}
.form-input:focus { border-color: var(--orange); background: rgba(255,255,255,.06); }
.form-textarea { resize: none; min-height: 100px; line-height: 1.6; }
.form-input::placeholder { color: rgba(232,232,240,.2); }
.modal-alert { border-radius: 8px; padding: 10px 14px; font-size: .82rem; margin-bottom: 16px; display: none; align-items: center; gap: 8px; }
.modal-alert.show { display: flex; }
.modal-alert-err { background: rgba(244,67,54,.1); border: 1px solid rgba(244,67,54,.3); color: #ef9a9a; }
.modal-alert .material-icons { font-size: .95rem; flex-shrink: 0; }
.modal-submit {
  flex: 1; background: linear-gradient(135deg, var(--orange), var(--orange-light));
  color: #fff; border: none; border-radius: 9px; padding: 13px;
  font-family: 'Inter', sans-serif; font-size: .92rem; font-weight: 700;
  cursor: pointer; transition: opacity .2s; box-shadow: 0 4px 16px var(--orange-glow);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.modal-submit.full { width: 100%; }
.modal-submit:disabled { opacity: .5; cursor: not-allowed; }
.modal-submit .spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: none; }
.modal-submit.loading .spinner { display: block; }
.modal-submit.loading .btn-text { display: none; }
.btn-cancel-modal {
  flex: 1; background: rgba(255,255,255,.05); border: 1.5px solid rgba(255,255,255,.08);
  color: var(--text-muted); border-radius: 9px; padding: 13px;
  font-family: 'Inter', sans-serif; font-size: .92rem; cursor: pointer; transition: background .2s;
}
.btn-cancel-modal:hover { background: rgba(255,255,255,.09); color: var(--text); }
.btn-danger-modal {
  flex: 1; background: linear-gradient(135deg, #c62828, #e53935);
  color: #fff; border: none; border-radius: 9px; padding: 13px;
  font-family: 'Inter', sans-serif; font-size: .92rem; font-weight: 700;
  cursor: pointer; transition: opacity .2s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-danger-modal:disabled { opacity: .5; cursor: not-allowed; }

/* Loading */
.app-loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--dark); z-index: 300; }
.app-loading .material-icons { font-size: 2.5rem; color: var(--orange); animation: spin .7s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes modal-in { from { opacity: 0; transform: scale(.96) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* ── Mobile ── */
@media (max-width: 600px) {
  .navbar { padding: 0 16px; height: 52px; }
  .logo img { height: 28px; }
  .user-name { display: none; }
  .user-btn { padding: 5px 10px 5px 6px; gap: 6px; }

  .app {
    padding-top: 52px;
    flex-direction: row;
    width: 200%;
    height: 100%;
    transition: transform .28s cubic-bezier(.4,0,.2,1);
  }
  .app.show-ticket { transform: translateX(-50%); }

  .sidebar {
    width: 50%; flex-shrink: 0; min-height: 0;
    border-right: none;
    display: flex; flex-direction: column;
  }
  .sidebar-header { padding: 14px 16px 12px; }
  .new-btn { padding: 11px; font-size: .88rem; }
  .tickets-list { padding: 8px 10px; flex: 1; }
  .ticket-item { padding: 11px 12px; }

  .main {
    width: 50%; flex-shrink: 0; min-height: 0;
    display: flex; flex-direction: column;
  }

  .btn-back { display: flex; }

  .ticket-header { padding: 10px 14px; }
  .th-title { font-size: .9rem; }
  .th-meta { font-size: .72rem; gap: 6px; }
  .btn-close-t { padding: 5px 10px; font-size: .72rem; }
  .btn-close-t .material-icons { font-size: .8rem; }

  .messages-area { padding: 12px 14px; gap: 10px; }
  .msg { max-width: 88%; }
  .msg-bubble { font-size: .84rem; padding: 8px 12px; }

  .reply-area { padding: 8px 12px 12px; }
  .reply-wrap { padding: 5px 5px 5px 12px; }
  .reply-ta { font-size: .85rem; height: 32px; }
  .reply-send-btn { width: 30px; height: 30px; }
  .reply-hint { display: none; }

  .closed-bar { margin: 0 14px 12px; font-size: .78rem; }

  .modal-box { padding: 24px 18px; border-radius: 14px; }
  .modal-title { font-size: 1rem; }
  .form-input { padding: 10px 12px; font-size: .88rem; }
  .modal-submit, .btn-cancel-modal, .btn-danger-modal { padding: 12px; font-size: .88rem; }
}
