/**
 * Tax & Labor Hub — Estilos do Admin
 * Variáveis CSS controlam Light/Dark Mode + paleta personalizada.
 * Os valores padrão abaixo são sobrescritos em tempo real via JS
 * (tlh-theme.js) a partir das cores salvas em wp_options.
 */

:root {
	--th-primary: #1A365D;
	--th-secondary: #2B6CB0;
	--th-bg-panel: #F7FAFC;
	--th-bg-card: #FFFFFF;
	--th-text-color: #2D3748;
	--th-border-color: #E2E8F0;
	--th-danger: #C53030;
	--th-success: #2F855A;
}

[data-tlh-theme="dark"] {
	--th-primary: #2B6CB0;
	--th-secondary: #4A9EFF;
	--th-bg-panel: #1A202C;
	--th-bg-card: #2D3748;
	--th-text-color: #EDF2F7;
	--th-border-color: #4A5568;
	--th-danger: #FC8181;
	--th-success: #68D391;
}

.tlh-app * {
	box-sizing: border-box;
}

.tlh-app {
	background: var(--th-bg-panel);
	color: var(--th-text-color);
	transition: background-color 0.2s ease, color 0.2s ease;
	padding: 0;
	font-size: 14px;
	box-shadow: 0 0 0 1px var(--th-border-color);
}

/* Dentro do wp-admin: ocupa a área de conteúdo, descontando admin bar + header do plugin. */
.tlh-app--admin {
	min-height: calc(100vh - 40px);
	margin: 0 -20px;
}

/* No frontend (shortcode): altura fixa em vh, já que não há admin bar
   nem outras referências de layout do wp-admin para descontar. */
.tlh-app--frontend {
	min-height: 80vh;
	margin: 20px 0;
	border-radius: 6px;
	overflow: hidden;
}

.tlh-frontend-login-notice {
	text-align: center;
	padding: 40px 20px;
	background: var(--th-bg-card, #fff);
	border: 1px solid var(--th-border-color, #E2E8F0);
	border-radius: 6px;
}

/* --------------------------------------------------------------------- */
/* Cabeçalho                                                              */
/* --------------------------------------------------------------------- */

.tlh-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 12px 20px;
	background: var(--th-bg-card);
	border-bottom: 1px solid var(--th-border-color);
	flex-wrap: wrap;
}

.tlh-header__left,
.tlh-header__center,
.tlh-header__right {
	display: flex;
	align-items: center;
	gap: 10px;
}

.tlh-header__center {
	flex: 1;
	justify-content: center;
	flex-wrap: wrap;
}

.tlh-header__title {
	font-size: 18px;
	margin: 0;
	color: var(--th-primary);
}

.tlh-context-selector select,
.tlh-global-search,
.tlh-header__center select {
	background: var(--th-bg-panel);
	color: var(--th-text-color);
	border: 1px solid var(--th-border-color);
	border-radius: 4px;
	padding: 6px 10px;
}

.tlh-global-search {
	min-width: 240px;
}

.tlh-theme-toggle {
	background: var(--th-primary);
	color: #fff;
	border: none;
	border-radius: 4px;
	padding: 6px 10px;
	cursor: pointer;
}

/* --------------------------------------------------------------------- */
/* Layout de 3 colunas                                                    */
/* --------------------------------------------------------------------- */

.tlh-columns {
	display: grid;
	grid-template-columns: 280px minmax(0, 1fr) 320px;
	gap: 1px;
	background: var(--th-border-color);
}

/* Admin: descontar admin bar (40px) + cabeçalho do plugin (58px) da viewport. */
.tlh-app--admin .tlh-columns {
	height: calc(100vh - 40px - 58px);
}

/* Frontend: a altura já vem do container pai (.tlh-app--frontend { min-height: 80vh }). */
.tlh-app--frontend .tlh-columns {
	height: calc(80vh - 58px);
}

.tlh-col {
	background: var(--th-bg-panel);
	overflow-y: auto;
	padding: 16px;
}

.tlh-col--tree {
	background: var(--th-bg-card);
}

.tlh-col--ia {
	background: var(--th-bg-card);
}

.tlh-col__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 12px;
}

.tlh-col__header h2 {
	margin: 0;
	font-size: 14px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--th-secondary);
}

.tlh-btn-icon {
	background: var(--th-primary);
	color: #fff;
	border: none;
	border-radius: 4px;
	width: 26px;
	height: 26px;
	cursor: pointer;
	font-size: 16px;
	line-height: 1;
}

/* --------------------------------------------------------------------- */
/* Treeview                                                                */
/* --------------------------------------------------------------------- */

.tlh-treeview ul {
	list-style: none;
	margin: 0;
	padding-left: 14px;
}

.tlh-treeview > ul {
	padding-left: 0;
}

.tlh-tree-node {
	padding: 6px 8px;
	border-radius: 4px;
	cursor: pointer;
	display: flex;
	align-items: center;
	gap: 6px;
}

.tlh-tree-node:hover {
	background: var(--th-bg-panel);
}

.tlh-tree-node.is-active {
	background: var(--th-secondary);
	color: #fff;
}

.tlh-tree-node__toggle {
	width: 14px;
	text-align: center;
	opacity: 0.6;
}

.tlh-loading,
.tlh-ia-placeholder {
	opacity: 0.6;
	font-style: italic;
}

/* --------------------------------------------------------------------- */
/* Editor central                                                         */
/* --------------------------------------------------------------------- */

.tlh-empty-state {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	text-align: center;
	opacity: 0.6;
	padding: 40px;
}

.tlh-editor-form label {
	display: block;
	margin-bottom: 14px;
	font-weight: 600;
}

.tlh-editor-form label span {
	display: block;
	margin-bottom: 4px;
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	color: var(--th-secondary);
	font-weight: 600;
}

.tlh-editor-form input[type="text"],
.tlh-editor-form input[type="date"],
.tlh-editor-form input[type="search"],
.tlh-editor-form select,
.tlh-editor-form textarea {
	width: 100%;
	background: var(--th-bg-card);
	color: var(--th-text-color);
	border: 1px solid var(--th-border-color);
	border-radius: 4px;
	padding: 8px 10px;
	font-weight: normal;
}

.tlh-form-row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 12px;
}

.tlh-editor-section {
	border-top: 1px solid var(--th-border-color);
	padding-top: 14px;
	margin-top: 14px;
}

.tlh-editor-section h3 {
	margin: 0 0 8px;
	font-size: 13px;
	color: var(--th-secondary);
}

.tlh-linked-list {
	list-style: none;
	margin: 0 0 10px;
	padding: 0;
}

.tlh-linked-list li {
	display: flex;
	align-items: center;
	justify-content: space-between;
	background: var(--th-bg-panel);
	border: 1px solid var(--th-border-color);
	border-radius: 4px;
	padding: 6px 10px;
	margin-bottom: 6px;
	font-size: 13px;
	gap: 8px;
}

.tlh-linked-list li a {
	color: var(--th-text-color);
	text-decoration: none;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	flex: 1;
}

.tlh-linked-list li a:hover {
	color: var(--th-secondary);
	text-decoration: underline;
}

.tlh-linked-list__open {
	background: none;
	border: none;
	color: var(--th-text-color);
	text-align: left;
	cursor: pointer;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	flex: 1;
	padding: 0;
	font-size: 13px;
}

.tlh-linked-list__open:hover {
	color: var(--th-secondary);
	text-decoration: underline;
}

.tlh-linked-list li button {
	background: none;
	border: none;
	color: var(--th-danger);
	cursor: pointer;
}

.tlh-editor-actions {
	display: flex;
	gap: 10px;
	margin-top: 20px;
	padding-top: 16px;
	border-top: 1px solid var(--th-border-color);
}

.tlh-editor-actions-inline {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
}

/* --------------------------------------------------------------------- */
/* Coluna de IA                                                            */
/* --------------------------------------------------------------------- */

.tlh-ia-provider,
.tlh-ia-prompt-label {
	display: block;
	margin-bottom: 12px;
}

.tlh-ia-provider select {
	width: 100%;
	padding: 6px;
	background: var(--th-bg-panel);
	color: var(--th-text-color);
	border: 1px solid var(--th-border-color);
	border-radius: 4px;
}

.tlh-ia-quick-actions {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-bottom: 14px;
}

.tlh-ia-prompt-label textarea {
	width: 100%;
	background: var(--th-bg-panel);
	color: var(--th-text-color);
	border: 1px solid var(--th-border-color);
	border-radius: 4px;
	padding: 8px;
}

.tlh-ia-diagnostics {
	margin-top: 16px;
	padding: 12px;
	background: var(--th-bg-panel);
	border: 1px dashed var(--th-border-color);
	border-radius: 4px;
	min-height: 100px;
	font-size: 13px;
	white-space: pre-wrap;
}

/* --------------------------------------------------------------------- */
/* Tela de Backup                                                         */
/* --------------------------------------------------------------------- */

.tlh-backup-columns {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
	gap: 16px;
	margin-top: 20px;
}

.tlh-backup-card {
	background: #fff;
	border: 1px solid #ccd0d4;
	border-radius: 4px;
	padding: 16px 20px;
}

.tlh-settings-section-title {
	margin-top: 28px;
	padding-bottom: 8px;
	border-bottom: 1px solid #ccd0d4;
}

.tlh-settings-wrap textarea.code {
	font-family: Consolas, Monaco, monospace;
	font-size: 13px;
}

.tlh-ia-providers-table .tlh-ia-model-input {
	margin-top: 6px;
	max-width: 320px;
}

.tlh-ia-providers-table .tlh-ia-test-btn {
	margin-top: 8px;
}

.tlh-ia-test-result {
	display: inline-block;
	margin-left: 10px;
	font-size: 13px;
	font-weight: 600;
}

.tlh-ia-test-result.is-success {
	color: #2F855A;
}

.tlh-ia-test-result.is-error {
	color: #C53030;
}

/* --------------------------------------------------------------------- */
/* Responsivo                                                             */
/* --------------------------------------------------------------------- */

@media (max-width: 1100px) {
	.tlh-columns {
		grid-template-columns: 1fr;
		height: auto;
	}

	.tlh-col {
		max-height: 480px;
	}
}

/* --------------------------------------------------------------------- */
/* Modais (busca/seleção e mídia)                                         */
/* --------------------------------------------------------------------- */

.tlh-modal-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.55);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 100000;
	padding: 20px;
}

.tlh-modal {
	background: var(--th-bg-card, #fff);
	color: var(--th-text-color, #2D3748);
	border-radius: 6px;
	padding: 20px;
	width: 100%;
	max-width: 480px;
	max-height: 80vh;
	overflow-y: auto;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.tlh-modal h3 {
	margin-top: 0;
}

.tlh-modal-search {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid var(--th-border-color, #E2E8F0);
	border-radius: 4px;
	background: var(--th-bg-panel, #F7FAFC);
	color: var(--th-text-color, #2D3748);
	margin-bottom: 10px;
}

.tlh-modal-results {
	list-style: none;
	margin: 0;
	padding: 0;
	max-height: 260px;
	overflow-y: auto;
	border: 1px solid var(--th-border-color, #E2E8F0);
	border-radius: 4px;
}

.tlh-modal-result {
	padding: 8px 10px;
	cursor: pointer;
	border-bottom: 1px solid var(--th-border-color, #E2E8F0);
	font-size: 13px;
}

.tlh-modal-result:last-child {
	border-bottom: none;
}

.tlh-modal-result:hover {
	background: var(--th-bg-panel, #F7FAFC);
}

.tlh-modal-empty {
	padding: 10px;
	opacity: 0.6;
	font-style: italic;
	font-size: 13px;
}

.tlh-modal-actions {
	margin-top: 14px;
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

/* Modal de mídia --------------------------------------------------------- */

.tlh-modal--media {
	max-width: 520px;
}

.tlh-modal--novo-assunto .tlh-modal-field {
	display: block;
	margin-bottom: 12px;
	font-weight: 600;
}

.tlh-modal--novo-assunto .tlh-modal-field span {
	display: block;
	margin-bottom: 4px;
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	color: var(--th-secondary, #2B6CB0);
}

.tlh-modal--novo-assunto .tlh-modal-field input,
.tlh-modal--novo-assunto .tlh-modal-field select {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid var(--th-border-color, #E2E8F0);
	border-radius: 4px;
	background: var(--th-bg-panel, #F7FAFC);
	color: var(--th-text-color, #2D3748);
	font-weight: normal;
}

.tlh-media-tabs {
	display: flex;
	gap: 4px;
	margin-bottom: 14px;
	border-bottom: 1px solid var(--th-border-color, #E2E8F0);
}

.tlh-media-tab {
	background: none;
	border: none;
	padding: 8px 12px;
	cursor: pointer;
	font-size: 13px;
	border-bottom: 2px solid transparent;
	color: inherit;
	opacity: 0.7;
}

.tlh-media-tab.is-active {
	opacity: 1;
	border-bottom-color: var(--th-secondary, #2B6CB0);
	font-weight: 600;
}

.tlh-media-panel input[type="file"],
.tlh-media-panel input[type="url"] {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid var(--th-border-color, #E2E8F0);
	border-radius: 4px;
	background: var(--th-bg-panel, #F7FAFC);
	color: var(--th-text-color, #2D3748);
	margin-bottom: 8px;
}

.tlh-media-panel .description {
	font-size: 12px;
	opacity: 0.7;
	margin: 4px 0 0;
}

.tlh-paste-zone {
	border: 2px dashed var(--th-border-color, #E2E8F0);
	border-radius: 6px;
	padding: 30px 16px;
	text-align: center;
	cursor: text;
	font-size: 13px;
	opacity: 0.8;
}

.tlh-paste-zone:focus {
	outline: none;
	border-color: var(--th-secondary, #2B6CB0);
	opacity: 1;
}

.tlh-media-queue {
	list-style: none;
	margin: 14px 0 0;
	padding: 0;
	max-height: 160px;
	overflow-y: auto;
}

.tlh-media-queue__item {
	font-size: 12px;
	padding: 5px 8px;
	border-radius: 4px;
	margin-bottom: 4px;
	background: var(--th-bg-panel, #F7FAFC);
}

.tlh-media-queue__item.is-done {
	color: var(--th-success, #2F855A);
}

.tlh-media-queue__item.is-error {
	color: var(--th-danger, #C53030);
}

.tlh-media-queue__item.is-pending {
	opacity: 0.7;
	font-style: italic;
}
