@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --bg-dark: #fcfcfc;
  --bg-card: #ffffff;
  --bg-input: #f8f9fa;
  --border-light: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(0, 0, 0, 0.15);
  --text-primary: #111111;
  --text-secondary: #555555;

  --accent-blue: #6592e6;
  --accent-blue-hover: #4e7ad1;
  --accent-glow: rgba(101, 146, 230, 0.2);

  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  zoom: 1.25;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-primary);
  background-image:
    radial-gradient(circle at 15% 50%, rgba(101, 146, 230, 0.05), transparent 40%),
    radial-gradient(circle at 85% 30%, rgba(139, 92, 246, 0.05), transparent 40%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent-blue);
  text-decoration: none;
  transition: all 0.2s ease;
}

a:hover {
  text-decoration: underline;
}

/* Navigation */
.tk-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
}

.tk-nav .inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  padding: 16px 24px;
  gap: 16px;
}

.tk-brand {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.tk-brand img {
  height: 32px;
  object-fit: contain;
}

.tk-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-blue);
  box-shadow: 0 0 12px var(--accent-glow);
}

.tk-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Layout */
.tk-wrap {
  max-width: 1600px;
  margin: 0 auto;
  padding: 32px 24px;
}

.tk-center {
  min-height: 80vh;
  /* Dopasowane z powrotem do 100vh pod zoom 1.25x z body */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.tk-panel {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
}

/* Sidebar overlay */
.tk-sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 900;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.tk-sidebar-overlay.active {
  display: block;
  opacity: 1;
}

/* Hamburger */
.tk-hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  padding: 8px;
  border-radius: 8px;
  margin-right: 8px;
}

.tk-hamburger:hover {
  background: rgba(0, 0, 0, 0.05);
}

@media (max-width: 900px) {
  body {
    zoom: 1;
    /* Reset global zoom on mobile */
    font-size: 15px;
  }

  .tk-panel {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .tk-wrap {
    padding: 16px 12px;
  }

  .tk-hamburger {
    display: none !important;
  }

  .tk-nav .tk-badge,
  .tk-nav .tk-btn {
    display: none !important;
  }

  .tk-brand {
    font-size: 1rem;
  }

  .tk-brand img {
    height: 24px;
  }

  .tk-nav .inner {
    padding: 12px 16px;
    gap: 8px;
  }

  /* Horizontal Mobile Navigation Bar */
  .tk-card.tk-side {
    padding: 10px;
    height: auto;
    background: var(--bg-card);
    position: static;
    width: 100%;
    max-height: none;
    z-index: 10;
    border-radius: 12px;
    border: 1px solid var(--border-light);
    margin: 0 0 16px 0;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  }

  .tk-card.tk-side::-webkit-scrollbar {
    height: 4px;
  }

  .tk-card.tk-side.open {
    transform: none;
  }

  .tk-side a {
    flex-shrink: 0;
    margin-right: 8px;
    margin-bottom: 0;
    padding: 8px 12px;
    font-size: 0.95rem;
    white-space: nowrap;
  }

  .tk-side a:last-child {
    margin-right: 0;
  }

  /* Single column stats override */
  .tk-grid {
    grid-template-columns: 1fr !important;
  }

  /* Chat messages adjustments */
  .tk-msg {
    max-width: 100%;
    width: 100%;
    padding: 10px 14px;
    box-sizing: border-box;
  }

  /* Adjust margins and prevent horizontal overflow */
  body {
    overflow-x: hidden;
  }

  .tk-wrap {
    padding: 10px 8px;
    overflow-x: hidden;
    width: 100%;
    box-sizing: border-box;
  }

  /* Elements Padding */
  .tk-card.pad {
    padding: 16px 12px;
  }

  .tk-label {
    margin: 12px 0 6px;
    font-size: 0.95rem;
  }

  .tk-input {
    padding: 12px 14px;
    font-size: 1rem;
    /* Prevent iOS zoom */
  }

  /* Toolbars and forms breaking layouts */
  .ql-toolbar.ql-snow {
    padding: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: flex-start;
  }

  .ql-formats {
    margin-right: 0 !important;
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
  }

  .ql-picker-label {
    padding: 0 4px !important;
  }

  .ql-container.ql-snow {
    margin-bottom: 12px;
    font-size: 1rem;
    /* Prevent iOS zoom */
  }

  .ql-editor {
    padding: 8px 10px;
  }

  /* Ticket Header fixes */
  img[alt="Logo"] {
    height: 48px !important;
    width: 48px !important;
  }

  .tk-title {
    font-size: 1.35rem;
  }

  /* Responsive action buttons inside ticket view */
  form[action=""] .tk-btn,
  form[method="post"] .tk-btn {
    width: 100%;
    justify-content: center;
    margin-bottom: 8px;
  }

  form[action=""] .tk-input,
  form[method="post"] .tk-input {
    width: 100%;
    max-width: 100% !important;
    margin-bottom: 8px;
  }

  /* Buttons container flex adjustments */
  div[style*="display:flex; flex-wrap:wrap; gap:12px; align-items:center;"] {
    flex-direction: column;
    align-items: stretch !important;
  }

  form[method="post"][style*="display:flex;gap:8px;align-items:center;"] {
    flex-direction: column;
    align-items: stretch !important;
  }

  .tk-msg-row {
    width: 100%;
    margin-bottom: 8px;
    box-sizing: border-box;
  }

  .tk-msg-body {
    overflow-x: auto;
    max-width: 100%;
    word-break: break-all !important;
    overflow-wrap: break-word !important;
  }

  /* Make sure long URLs or pre/code blocks scroll horizontally instead of expanding page */
  .tk-msg-body pre,
  .tk-msg-body code,
  .ql-editor pre {
    white-space: pre-wrap !important;
    word-break: break-all !important;
    overflow-x: auto;
    max-width: 100%;
  }

  /* Ticket list item layout on mobile */
  .tk-ticket-list-item>div {
    flex-direction: column !important;
    align-items: flex-start !important;
  }

  .tk-ticket-list-item img {
    height: 64px !important;
    width: 64px !important;
    margin-bottom: 12px;
  }

  .tk-ticket-list-item .tk-badge {
    align-self: flex-start;
    margin-top: 12px;
  }
}

/* Cards & Containers */
.tk-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.05);
  /* Lighter shadow for light theme */
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.tk-card.pad {
  padding: 40px;
}

/* Typography */
.tk-title {
  margin: 0 0 8px;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.tk-sub {
  margin: 0 0 16px;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Sidebar */
.tk-side {
  padding: 16px;
  height: fit-content;
}

.tk-side a {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-radius: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  margin-bottom: 4px;
}

.tk-side a:last-child {
  margin-bottom: 0;
}

.tk-side a:hover {
  background: var(--bg-input);
  color: var(--text-primary);
  text-decoration: none;
}

/* Forms & Inputs */
.tk-label {
  display: block;
  margin: 16px 0 8px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}

.tk-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: all 0.2s ease;
  outline: none;
}

.tk-input:hover {
  border-color: var(--border-hover);
}

.tk-input:focus {
  border-color: var(--accent-blue);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(101, 146, 230, 0.15);
}

/* Buttons */
.tk-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 10px;
  padding: 12px 20px;
  border: 1px solid var(--border-light);
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.tk-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: var(--border-hover);
  text-decoration: none;
}

.tk-btn:active {
  transform: scale(0.98);
}

.tk-btn.primary {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(101, 146, 230, 0.25);
}

.tk-btn.primary:hover {
  background: var(--accent-blue-hover);
  border-color: var(--accent-blue-hover);
  box-shadow: 0 6px 16px rgba(101, 146, 230, 0.35);
  color: #ffffff;
}

.tk-btn.full {
  width: 100%;
}

/* Badges & Alerts */
.tk-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 12px;
  border: 1px solid var(--border-light);
  border-radius: 99px;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.03);
}

.tk-badge.open {
  background: var(--success-bg);
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.3);
}

.tk-badge.closed {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.tk-alert {
  background: var(--danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #c53030;
  border-radius: 12px;
  padding: 16px;
  margin: 16px 0;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 12px;
}

.tk-alert::before {
  content: "⚠️";
  font-size: 1.1rem;
}

/* Specific Utilities */
.tk-grid {
  display: grid;
  gap: 24px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

/* Chat Bubbles */
.tk-chat {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tk-msg-row {
  display: flex;
  width: 100%;
}

.tk-msg-row.admin-msg {
  justify-content: flex-end;
}

.tk-msg-row.client-msg {
  justify-content: flex-start;
}

.tk-msg {
  max-width: 80%;
  padding: 16px 20px;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
  line-height: 1.5;
  font-size: 0.95rem;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.tk-msg.admin-msg {
  background: var(--accent-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.tk-msg.client-msg {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
}

.tk-msg-meta {
  font-size: 0.8rem;
  margin-bottom: 8px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
}

.tk-msg.admin-msg .tk-msg-meta {
  color: rgba(255, 255, 255, 0.9);
}

.tk-msg.client-msg .tk-msg-meta {
  color: var(--text-secondary);
}

.tk-msg.client-msg .tk-msg-meta b {
  color: var(--text-primary);
}

select.tk-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6 9L12 15L18 9' stroke='%23555555' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}

/* Messages styling */
.tk-card.pad {
  transition: border-color 0.2s ease;
}

.tk-card.pad:hover {
  border-color: var(--border-hover);
}

/* Scrollbar styling for webkit */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* File Manager Tokens */
.tk-file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.tk-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.02);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.9rem;
}

/* Global Editor Overrides for long strings */
.ql-editor,
.ql-editor * {
  word-wrap: break-word !important;
  overflow-wrap: anywhere !important;
  word-break: break-all !important;
  white-space: pre-wrap !important;
}

.tk-file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.tk-file-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

.tk-file-size {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.tk-file-remove {
  background: rgba(239, 68, 68, 0.1);
  color: #c53030;
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: bold;
  font-size: 14px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.tk-file-remove:hover {
  background: #ef4444;
  color: white;
}

/* Login Split Screen specific styles */
.tk-login-split {
  display: flex;
  flex-direction: row;
  max-width: 900px;
  width: 100%;
  min-height: 500px;
}

.tk-login-left {
  flex: 1;
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.tk-login-right {
  flex: 1;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  border-left: 1px solid var(--border-light);
}

.tk-login-logo {
  max-width: 80%;
  max-height: 80%;
  object-fit: contain;
}

@media (max-width: 768px) {
  .tk-login-split {
    flex-direction: column;
  }

  .tk-login-right {
    min-height: 200px;
    border-left: none;
    border-top: 1px solid var(--border-light);
    order: -1;
    /* Display logo on top on mobile */
  }

  .tk-login-left {
    padding: 32px 24px;
  }
}