*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg-app: #f3f5f8;
  --bg-pane: #ffffff;
  --border-color: #dce2ec;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-bg: #eef2ff;
  --secondary-text: #1e40af;
  --danger-text: #dc2626;
  --code-bg: #0f172a;
  --code-header: #1e293b;
  --code-text: #e2e8f0;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
  --font-mono: "Fira Code", "JetBrains Mono", Consolas, "Courier New", monospace;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-sans);
  color: var(--text-main);
  background-color: var(--bg-app);
}

/* Вертикальне розділення на дві рівні області */
.app-container {
  display: flex;
  flex-direction: row;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.pane {
  flex: 1 1 50%;
  width: 50%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.left-pane {
  background: var(--bg-pane);
  border-right: 2px solid var(--border-color);
}

.right-pane {
  background: var(--code-bg);
  color: var(--code-text);
}

/* Шапки панелей */
.pane-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  background: #f8fafc;
}

.right-header {
  background: var(--code-header);
  border-bottom: 1px solid #334155;
}

.title-group h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.title-group .subtitle {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Кнопки */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  user-select: none;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary-bg);
  color: var(--secondary-text);
  border-color: #c7d2fe;
}

.btn-secondary:hover {
  background: #e0e7ff;
}

.btn-ghost {
  background: #ffffff;
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-ghost:hover {
  background: #f1f5f9;
}

.btn-danger-ghost {
  background: #ffffff;
  color: var(--danger-text);
  border-color: #fecaca;
}

.btn-danger-ghost:hover {
  background: #fef2f2;
}

.btn-copy {
  background: #334155;
  color: #f8fafc;
  border-color: #475569;
}

.btn-copy:hover {
  background: #475569;
}

/* Панель відповідності службових слів */
.legend-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.78rem;
}

.badge {
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.badge-loc {
  background: #dbeafe;
  color: #1e40af;
}

.badge-shl {
  background: #fef3c7;
  color: #92400e;
}

.badge-oth {
  background: #e2e8f0;
  color: #334155;
}

.status-msg {
  margin-left: auto;
  font-weight: 600;
  color: #059669;
}

.status-msg.error {
  color: var(--danger-text);
}

/* Таблиця 3 колонки та 7 рядків */
.table-wrapper {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: left;
  padding: 10px 8px;
  border-bottom: 2px solid var(--border-color);
}

tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.12s ease;
}

tbody tr:hover {
  background-color: #f8fafc;
}

tbody td {
  padding: 8px;
  vertical-align: top;
}

.col-num {
  width: 34px;
  text-align: center !important;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  padding-top: 14px;
}

.col-type {
  width: 26%;
}

.col-date {
  width: 32%;
}

.col-comment {
  width: auto;
}

/* Поля форми в таблиці */
select.event-select,
input.event-date,
textarea.event-comment {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--text-main);
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 7px 9px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select.event-select:focus,
input.event-date:focus,
textarea.event-comment:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

select.event-select.type-1 {
  border-left: 4px solid #2563eb;
  font-weight: 600;
}

select.event-select.type-2 {
  border-left: 4px solid #d97706;
  font-weight: 600;
}

select.event-select.type-3 {
  border-left: 4px solid #64748b;
  font-weight: 600;
}

textarea.event-comment {
  min-height: 54px;
  resize: vertical;
  line-height: 1.35;
}

/* Вкладки правої панелі */
.tabs {
  display: flex;
  gap: 6px;
}

.tab-btn {
  padding: 7px 13px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #94a3b8;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.tab-btn:hover {
  color: #f8fafc;
  background: rgba(255, 255, 255, 0.06);
}

.tab-btn.active {
  color: #ffffff;
  background: #2563eb;
}

.counter-pill {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: #334155;
  color: #93c5fd;
}

/* Блок виводу коду */
.code-container {
  flex: 1 1 auto;
  overflow: auto;
  padding: 18px;
}

.code-block {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--code-text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Підсвічування синтаксису */
.tok-key {
  color: #7dd3fc;
}

.tok-str {
  color: #86efac;
}

.tok-num {
  color: #fca5a5;
  font-weight: 600;
}

.tok-punct {
  color: #94a3b8;
}

.tok-php-tag {
  color: #f472b6;
  font-weight: 700;
}

.tok-php-kw {
  color: #c084fc;
  font-weight: 600;
}

.tok-php-var {
  color: #38bdf8;
}

.tok-php-fn {
  color: #fde047;
}

.tok-php-com {
  color: #64748b;
  font-style: italic;
}

/* Адаптивність для вузьких екранів */
@media (max-width: 960px) {
  .app-container {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .pane {
    width: 100%;
    height: auto;
    min-height: 50vh;
  }

  .left-pane {
    border-right: none;
    border-bottom: 2px solid var(--border-color);
  }
}
