/* Utilities */

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Editor  */

.editor {
	display: block;
	width: 100%;
	min-height: 62vh;
	padding: var(--space-4);
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	font-family: var(--font-sans);
	font-size: var(--text-base);
	line-height: var(--leading-normal);
	color: var(--color-text);
	background: var(--color-bg);
	resize: vertical;
	outline: none;
	transition: border-color var(--transition-fast);
}

.editor:focus {
	border-color: var(--color-text);
}

.editor::placeholder {
	color: var(--color-text-muted);
}

/* Primary Metrics */

.metrics-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 1px;
	background-color: var(--color-border);
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	overflow: hidden;
}

.metric-card {
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
	padding: var(--space-4);
	background: var(--color-bg);
}

.metric-value {
	font-size: var(--text-2xl);
	font-weight: var(--weight-bold);
	letter-spacing: -0.03em;
	line-height: 1;
	font-variant-numeric: tabular-nums;
}

.metric-label {
	font-size: var(--text-xs);
	color: var(--color-text-muted);
	text-transform: uppercase;
	letter-spacing: 0.06em;
}

/* Secondary Metrics */

.metrics-secondary {
	/* margin-top: var(--space-4); */
	/* border-top: 1px solid var(--color-border); */
	padding-top: var(--space-4);
}

.metrics-list {
	display: flex;
	flex-direction: column;
}

.metrics-list-item {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: var(--space-4);
	padding: var(--space-2) 0;
	border-bottom: 1px solid var(--color-border);
	font-size: var(--text-sm);
}

.metrics-list-item:last-child {
	border-bottom: none;
}

.metrics-list-item dt {
	color: var(--color-text-muted);
}

.metrics-list-item dd {
	font-weight: var(--weight-medium);
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
}

/* Toolbar */

.toolbar {
	margin-top: var(--space-4);
	border-top: 1px solid var(--color-border);
	padding-top: var(--space-4);
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
}

.toolbar-section {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
}

.toolbar-label {
	font-size: var(--text-xs);
	font-weight: var(--weight-medium);
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--color-text-muted);
}

.toolbar-group {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-2);
}

/* Buttons */

.btn {
	padding: var(--space-1) var(--space-2);
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	font-size: var(--text-sm);
	font-family: var(--font-sans);
	color: var(--color-text);
	background: var(--color-bg);
	cursor: pointer;
	white-space: nowrap;
	transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.editor-toolbar .btn {
	font-size: var(--text-xs);
}

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

.btn:focus-visible {
	outline: 2px solid var(--color-text);
	outline-offset: 2px;
}

.btn:disabled {
	opacity: 0.35;
	cursor: not-allowed;
}

.btn-undo {
	font-style: italic;
}

/* Keyword Section */

.keyword-section {
	margin-top: var(--space-4);
	border-top: 1px solid var(--color-border);
	padding-top: var(--space-4);
}

.keyword-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: var(--space-3);
}

.toggle-label {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	font-size: var(--text-xs);
	color: var(--color-text-muted);
	cursor: pointer;
	user-select: none;
}

.keyword-empty {
	font-size: var(--text-sm);
	color: var(--color-text-muted);
	padding: var(--space-3) 0;
}

.keyword-table {
	width: 100%;
	border-collapse: collapse;
	font-size: var(--text-sm);
}

.keyword-table th {
	text-align: left;
	font-size: var(--text-xs);
	font-weight: var(--weight-medium);
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--color-text-muted);
	padding: var(--space-2);
	border-bottom: 1px solid var(--color-border);
}

.keyword-table td {
	padding: var(--space-2);
	border-bottom: 1px solid var(--color-border);
	font-variant-numeric: tabular-nums;
}

.keyword-table tr:last-child td {
	border-bottom: none;
}

.keyword-table th:not(:first-child),
.keyword-table td:not(:first-child) {
	text-align: right;
}

.btn-show-more {
	margin-top: var(--space-3);
	width: 100%;
	text-align: center;
	color: var(--color-text-muted);
	font-size: var(--text-xs);
	border-color: transparent;
}

/* Cleanup Section */

.cleanup-section {
	margin-top: var(--space-4);
	border-top: 1px solid var(--color-border);
	padding-top: var(--space-4);
}

.cleanup-header {
	margin-bottom: var(--space-2);
}

.cleanup-desc {
	font-size: var(--text-sm);
	color: var(--color-text-muted);
	line-height: var(--leading-normal);
	margin-bottom: var(--space-3);
}

.cleanup-summary {
	margin-top: var(--space-3);
	display: flex;
	flex-direction: column;
}

.cleanup-summary-item {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	padding: var(--space-2) 0;
	border-bottom: 1px solid var(--color-border);
	font-size: var(--text-sm);
}

.cleanup-summary-item:last-child {
	border-bottom: none;
}

.cleanup-summary-label {
	color: var(--color-text-muted);
}

.cleanup-summary-count {
	font-weight: var(--weight-medium);
	font-variant-numeric: tabular-nums;
}

/*  */

.editor-section {
	position: sticky;
	top: var(--space-6);
}

/* Editor toolbar  */

.editor-actions-bar {
	display: flex;
	justify-content: flex-end;
	gap: var(--space-2);
	margin-top: var(--space-2);
}

.editor-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--space-2);
	margin-bottom: var(--space-2);
}

.editor-toolbar .btn-undo {
	margin-left: auto;
}

.toolbar-divider {
	width: 1px;
	height: 1.25rem;
	background: var(--color-border);
	flex-shrink: 0;
}

/* Tab Strip */

.tab-strip {
	display: flex;
	align-items: stretch;
	overflow-x: auto;
	scrollbar-width: none;
	/* border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-3); */
}

.tab-strip::-webkit-scrollbar {
	display: none;
}

.tab-item {
	display: flex;
	align-items: center;
	border-bottom: 2px solid transparent;
	margin-bottom: -1px;
	flex-shrink: 0;
}

.tab-item.active {
	border-bottom-color: var(--color-text);
}

.tab-name {
	padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
	font-size: var(--text-sm);
	color: var(--color-text-muted);
	white-space: nowrap;
	background: none;
	border: none;
	cursor: pointer;
	transition: color var(--transition-fast);
}

.tab-item.active .tab-name {
	color: var(--color-text);
	font-weight: var(--weight-medium);
}

.tab-name:hover {
	color: var(--color-text);
}

.tab-close {
	padding: 2px var(--space-2) 2px var(--space-1);
	font-size: var(--text-base);
	line-height: 1;
	color: var(--color-text-muted);
	background: none;
	border: none;
	border-radius: var(--radius);
	cursor: pointer;
	opacity: 0;
	transition: opacity var(--transition-fast), background-color var(--transition-fast);
}

.tab-item:hover .tab-close,
.tab-item.active .tab-close {
	opacity: 1;
}

.tab-close:hover {
	background: var(--color-surface-hover);
	color: var(--color-text);
}

.tab-add {
	margin-left: auto;
	padding: var(--space-1) var(--space-3);
	font-size: var(--text-xl);
	line-height: 1;
	color: var(--color-text-muted);
	background: none;
	border: none;
	cursor: pointer;
	flex-shrink: 0;
	transition: color var(--transition-fast);
}

.tab-add:hover {
	color: var(--color-text);
}

/* Toolbar button icons  */

.btn-icon {
	display: inline-block;
	margin-right: 0.3em;
	font-size: 0.8em;
	opacity: 0.5;
	font-style: normal;
}

/* text-only: hide icons */
body.toolbar-text .btn-icon {
	display: none;
}

/* icon-only: hide labels visually but keep for screen readers */
body.toolbar-icon .btn-label {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

body.toolbar-icon .btn-icon {
	margin-right: 0;
	opacity: 1;
	font-size: 1em;
}

/* Settings header button  */

.btn-settings {
	flex-shrink: 0;
	white-space: nowrap;
}

/* Modal */

.modal-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.4);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 100;
	padding: var(--space-4);
}

.modal-overlay[hidden] {
	display: none;
}

.modal-panel {
	background: var(--color-bg);
	border: 1px solid var(--color-border);
	border-radius: var(--radius-lg);
	width: 100%;
	max-width: 420px;
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.modal-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: var(--space-5) var(--space-6);
	border-bottom: 1px solid var(--color-border);
}

.modal-title {
	font-size: var(--text-lg);
	font-weight: var(--weight-bold);
	letter-spacing: -0.02em;
}

.modal-close {
	width: 2rem;
	height: 2rem;
	display: flex;
	align-items: center;
	justify-content: center;
	background: none;
	border: none;
	border-radius: var(--radius);
	font-size: var(--text-xl);
	color: var(--color-text-muted);
	cursor: pointer;
	line-height: 1;
	transition: background-color var(--transition-fast), color var(--transition-fast);
}

.modal-close:hover {
	background: var(--color-surface-hover);
	color: var(--color-text);
}

.modal-close:focus-visible {
	outline: 2px solid var(--color-text);
	outline-offset: 2px;
}

.modal-body {
	padding: var(--space-5) var(--space-6);
	display: flex;
	flex-direction: column;
	gap: var(--space-5);
}

.modal-footer {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: var(--space-4) var(--space-6);
	border-top: 1px solid var(--color-border);
	gap: var(--space-3);
}

/* Settings form */

.settings-group {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
}

.settings-label {
	font-size: var(--text-sm);
	font-weight: var(--weight-medium);
}

.settings-unit {
	font-weight: var(--weight-normal);
	color: var(--color-text-muted);
	font-size: var(--text-xs);
}

.settings-input {
	width: 100%;
	max-width: 140px;
	padding: var(--space-2) var(--space-3);
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	font-size: var(--text-sm);
	font-family: var(--font-sans);
	color: var(--color-text);
	background: var(--color-bg);
	outline: none;
	transition: border-color var(--transition-fast);
}

.settings-input:focus {
	border-color: var(--color-text);
}

.settings-radio-group {
	display: flex;
	gap: var(--space-4);
	flex-wrap: wrap;
}

.settings-radio-label {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	font-size: var(--text-sm);
	cursor: pointer;
}

.settings-checkbox-label {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	font-size: var(--text-sm);
	cursor: pointer;
}

/* Danger button */

.btn-danger {
	color: #c0392b;
	border-color: #e8c4c0;
}

.btn-danger:hover {
	background: #fdf0ef;
	border-color: #c0392b;
}