:root {
  --blue: #1a56db; --blue-dark: #1240a8; --bg: #f4f6fa; --card: #fff;
  --text: #1f2937; --muted: #6b7280; --border: #e5e7eb;
  --green: #16a34a; --yellow: #d97706; --red: #dc2626; --purple: #7c3aed;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }

/* Top bar */
#topbar { display: flex; align-items: center; gap: 20px; background: var(--card); padding: 10px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.brand { font-weight: 700; font-size: 18px; color: var(--blue); cursor: pointer; }
#topbar nav { display: flex; gap: 8px; flex: 1; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.role-chip { background: #eef2ff; color: var(--blue); border-radius: 10px; padding: 2px 8px; font-size: 11px; text-transform: capitalize; }

/* Buttons */
button { font-family: inherit; font-size: 14px; border: 1px solid var(--border); background: var(--card); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
button:hover { background: #f9fafb; }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--blue-dark); }
button.ghost { background: transparent; }
.link-btn { border: none; background: none; color: var(--blue); padding: 4px; }
.link-btn:hover { text-decoration: underline; background: none; }
button:disabled { opacity: .5; cursor: not-allowed; }

main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 60px; }

/* Auth */
.auth-wrap { max-width: 400px; margin: 8vh auto; background: var(--card); padding: 32px; border-radius: 14px; border: 1px solid var(--border); box-shadow: 0 4px 20px rgba(0,0,0,.05); }
.auth-wrap h1 { color: var(--blue); margin: 0 0 4px; }
.auth-wrap p { color: var(--muted); margin-top: 0; }

/* Forms */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 12px; color: var(--text); }
input, select, textarea { width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; font-size: 14px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--blue); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.req { color: var(--red); }
.hint { display: block; font-weight: 400; color: var(--muted); margin-top: 3px; }
.form-error { color: var(--red); font-size: 13px; min-height: 18px; margin: 6px 0; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat.s-open .num { color: var(--red); }
.stat.s-progress .num { color: var(--yellow); }
.stat.s-resolved .num { color: var(--green); }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.filters select, .filters input { width: auto; margin-top: 0; }
.filters input[type=search] { flex: 1; min-width: 160px; }
.tab { border-radius: 20px; padding: 6px 14px; font-size: 13px; }
.tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Ticket cards */
.ticket-list { display: flex; flex-direction: column; gap: 10px; }
.ticket-card { display: flex; gap: 14px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; cursor: pointer; transition: box-shadow .12s; align-items: flex-start; }
.ticket-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,.08); }
.ticket-main { flex: 1; min-width: 0; }
.ticket-title { font-weight: 600; font-size: 15px; }
.ticket-title .tid { color: var(--muted); font-weight: 400; }
.ticket-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--muted); margin-top: 6px; align-items: center; }
.ticket-side { text-align: right; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

/* Badges */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 10px; white-space: nowrap; }
.st-open { background: #fee2e2; color: var(--red); }
.st-in_progress { background: #fef3c7; color: var(--yellow); }
.st-resolved { background: #dcfce7; color: var(--green); }
.st-closed { background: #e5e7eb; color: var(--muted); }
.pr-low { background: #f3f4f6; color: var(--muted); }
.pr-medium { background: #dbeafe; color: var(--blue); }
.pr-high { background: #ffedd5; color: #ea580c; }
.pr-critical { background: #fee2e2; color: var(--red); }
.age { font-size: 12px; font-weight: 600; }
.age-ok { color: var(--green); } .age-warn { color: var(--yellow); } .age-late { color: var(--red); }
.proj-chip { background: #f3e8ff; color: var(--purple); border-radius: 10px; padding: 2px 8px; font-size: 11.5px; font-weight: 600; }

/* Detail */
.detail-card, .panel { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.detail-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.detail-desc { white-space: pre-wrap; margin: 14px 0; line-height: 1.55; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 10px; font-size: 13.5px; }
.kv .k { color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.controls label { margin: 0; }
.controls select { width: auto; }

/* Comments */
.comment { border-top: 1px solid var(--border); padding: 12px 0; }
.comment-head { font-size: 13px; margin-bottom: 4px; }
.comment-head b { color: var(--text); }
.comment-head .when { color: var(--muted); }
.comment-body { white-space: pre-wrap; font-size: 14px; line-height: 1.5; }

/* Attachments */
.attach-zone { border: 2px dashed var(--border); border-radius: 10px; padding: 14px; text-align: center; margin-bottom: 14px; background: #fafbfc; }
.attach-zone.dragover { border-color: var(--blue); background: #eff6ff; }
.attach-hint { font-size: 13px; color: var(--muted); }
.file-link { display: inline; color: var(--blue); cursor: pointer; text-decoration: underline; font-weight: 400; }
.previews { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; justify-content: center; }
.preview { position: relative; }
.preview img { height: 64px; border-radius: 6px; border: 1px solid var(--border); display: block; }
.preview .file-chip { display: inline-block; background: #eef2ff; border-radius: 6px; padding: 8px 10px; font-size: 12px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview .rm { position: absolute; top: -7px; right: -7px; background: var(--red); color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 11px; line-height: 1; padding: 0; }
.attach-thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.attach-thumbs img { height: 110px; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }
.attach-file { display: inline-flex; align-items: center; gap: 6px; background: #f3f4f6; border-radius: 8px; padding: 8px 12px; font-size: 13px; text-decoration: none; color: var(--blue); }

/* Modal */
#modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 100; overflow-y: auto; }
.modal { background: var(--card); border-radius: 14px; padding: 24px 26px; width: 100%; max-width: 560px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* Toast */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 20px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 200; }
#toast.show { opacity: 1; }

/* Lightbox */
#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 300; cursor: zoom-out; }
#lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }

/* Admin tables */
table.admin { width: 100%; border-collapse: collapse; font-size: 14px; }
table.admin th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px; border-bottom: 1px solid var(--border); }
table.admin td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
table.admin select { width: auto; margin: 0; }
.add-row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.add-row input, .add-row select { width: auto; margin: 0; flex: 1; min-width: 140px; }

/* Voice dictation */
.mic-wrap { position: relative; }
.mic-wrap textarea { padding-right: 44px; }
.mic-btn { position: absolute; right: 8px; bottom: 8px; border-radius: 50%; width: 34px; height: 34px; padding: 0; font-size: 16px; line-height: 1; background: #fff; }
.mic-btn.recording { background: var(--red); border-color: var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,.45); } 50% { box-shadow: 0 0 0 8px rgba(220,38,38,0); } }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }
h1.page { font-size: 22px; margin: 4px 0 18px; }
.back { margin-bottom: 12px; }

@media (max-width: 640px) {
  #topbar { flex-wrap: wrap; }
  .row2 { grid-template-columns: 1fr; }
  .ticket-card { flex-direction: column; }
  .ticket-side { flex-direction: row; align-items: center; }
}
