/* ========================================
   Base HTML elements and global styles
   ======================================== */

/* Import unified design tokens */
@import 'variables.css';

html,
body {
	height: 100%;
	margin: 0;
	font-family: var(--font-family);
	font-size: var(--font-size-base);
	line-height: 1.7;
	display: flex;
	flex-direction: column;
	background-color: var(--secondary-bg);
	color: var(--text-color);
	overflow: hidden;
}

/* Global scrollbar styles - make all scrollbars thinner */
::-webkit-scrollbar {
	width: 4px;
	height: 4px;
}

::-webkit-scrollbar-track {
	background: transparent;
}

::-webkit-scrollbar-thumb {
	background: var(--border-color);
	border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
	background: var(--text-muted-color);
}

/* Firefox scrollbar */
* {
	scrollbar-width: thin;
	scrollbar-color: var(--border-color) transparent;
}

/* Critical base styles */
.hidden {
	display: none !important;
}

/* Basic layout structure */
main {
	flex-grow: 1;
	display: flex;
	overflow: hidden;
}

.column-container {
	display: flex;
	flex-direction: column;
	background-color: var(--main-bg);
	position: relative;
	flex: 1 1 0;
	min-width: 50px; /* Reduced for 8 columns support */
	overflow: hidden;
	border-right: 1px solid var(--border-color);
}

.column-container:first-child {
	border-left: 1px solid var(--border-color);
}

/* Modern loading screen with analog texture */
.loading-screen {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: var(--gray-900);
	z-index: 10000;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	animation: loading-fade-in 0.3s ease-out;
}

/* Fade out animation for loading screen */
body.loaded .loading-screen {
	opacity: 0;
	transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1);
	pointer-events: none;
}

@keyframes loading-fade-in {
	0% { 
		opacity: 0;
		transform: scale(1.1);
	}
	100% { 
		opacity: 1;
		transform: scale(1);
	}
}

/* --- Layout & Resizers --- */
#main-content {
	position: relative;
	display: flex;
	flex-direction: row;
	align-items: stretch;
	gap: 0;
}
header,
footer {
	flex-shrink: 0;
	background-color: var(--main-bg);
	min-height: 40px;
	height: 60px;
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
	position: relative;
}

/* Header borders - top, left, right only (not bottom) */
header {
	border-top: 1px solid var(--border-color);
	border-left: 1px solid var(--border-color);
	border-right: 1px solid var(--border-color);
	border-top-left-radius: var(--radius-lg);
	border-top-right-radius: var(--radius-lg);
}

footer {
	height: 40px;
	/* Footer borders - left, right, bottom only (not top) */
	border-bottom: 1px solid var(--border-color);
	border-left: 1px solid var(--border-color);
	border-right: 1px solid var(--border-color);
	border-bottom-left-radius: var(--radius-lg);
	border-bottom-right-radius: var(--radius-lg);
}

/* Editor wrapper - fills container minus resizer (12px) */
header .editor-wrapper,
footer .editor-wrapper {
	position: relative;
	width: 100%;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	justify-content: center;
	/* Height will be: parent height - 12px (resizer), set by JavaScript */
}

/* Header/Footer contenteditable editors */
.header-editor,
.footer-editor {
	width: 100%;
	padding: 12px 16px;
	outline: none;
	border: none;
	background: transparent;
	color: var(--text-color);
	font-family: inherit;
	font-size: inherit;
	line-height: 1.5;
	overflow: hidden;
	white-space: pre-wrap;
	word-wrap: break-word;
}

/* Placeholder for contenteditable */
.header-editor:empty:before,
.footer-editor:empty:before {
	content: attr(data-placeholder);
	color: var(--text-muted-color);
	opacity: 0.6;
}

/* Board selector layout */
.board-selector {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
	padding: 0 12px;
	height: 100%;
	white-space: nowrap;
	position: relative;
}

.board-selector label {
	color: var(--text-muted-color);
	font-size: 0.85em;
	font-weight: 600;
}

/* Header resizer */
.header-resizer {
	position: absolute;
	bottom: 0;
	left: 0;
	right: 0;
	height: var(--resizer-height);
	cursor: ns-resize;
	border-bottom: var(--resizer-border-width) solid var(--resizer-color);
	transition: border-color 0.2s ease;
	z-index: 1000;
}

.header-resizer:hover {
	border-bottom-color: var(--resizer-hover-color);
}

/* Footer resizer */
.footer-resizer {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	height: var(--resizer-height);
	cursor: ns-resize;
	border-top: var(--resizer-border-width) solid var(--resizer-color);
	transition: border-color 0.2s ease;
	z-index: 1000;
}

.footer-resizer:hover {
	border-top-color: var(--resizer-hover-color);
}

/* Active resizer state */
.header-resizer.active {
	border-bottom-color: var(--resizer-active-color);
}

.footer-resizer.active {
	border-top-color: var(--resizer-active-color);
}

/* Body state during resizing */
body.resizing-vertical {
	cursor: ns-resize !important;
	user-select: none;
}

/* Column Resizers */
.column-resizer {
	position: absolute;
	top: 0;
	bottom: 0;
	width: 12px;
	margin-left: -6px;
	cursor: col-resize;
	background: transparent;
	transition: background-color 0.2s;
	z-index: 100;
	left: 100%;
}

/* Center line in resizer */
.column-resizer::before {
	content: '';
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	width: 1px;
	height: 30px;
	background: var(--border-color);
	border-radius: 0.5px;
	transition: all 0.2s;
}

.column-resizer:hover {
	background: transparent;
}

.column-resizer:hover::before {
	background: var(--text-muted-color);
	height: 50px;
	width: 1px;
}

.column-resizer.active {
	background: transparent;
}

.column-resizer.active::before {
	background: var(--text-color);
	height: 100%;
	width: 1px;
}

body.resizing-horizontal {
	cursor: col-resize !important;
	user-select: none;
}

body.resizing-horizontal * {
	cursor: col-resize !important;
}

/* Column headers and footers wrappers */
.column-header-wrapper,
.column-footer-wrapper {
	display: none; /* Hidden by default */
	min-height: 60px; /* グローバルヘッダーと同じ最小高さ */
	max-height: 150px;
	width: 100%;
	position: relative;
	pointer-events: auto; /* クリック可能に（修正：エディタークリック問題対応） */
}

.column-header-wrapper.show,
.column-footer-wrapper.show {
	display: flex !important;
	/* 縦中央配置 */
	flex-direction: column;
	justify-content: center;
	align-items: flex-start; /* 子要素を横方向は左寄せ、縦方向の伸びを防ぐ */
	overflow: hidden; /* はみ出し防止 */
}

/* Column header/footer contenteditable editors */
.column-header,
.column-footer {
	width: 100%;
	padding: 8px;
	outline: none;
	border: none;
	background: transparent;
	color: var(--text-color);
	font-size: 14px;
	line-height: 1.5;
	overflow: hidden;
	white-space: pre-wrap;
	word-wrap: break-word;
	pointer-events: auto; /* クリック可能に（修正：エディタークリック問題対応） */
}

/* Placeholder for column contenteditable */
.column-header:empty:before,
.column-footer:empty:before {
	content: attr(data-placeholder);
	color: var(--text-muted-color);
	opacity: 0.6;
}

/* Column header/footer resizers - 定義は editor.css に移動 */

body.resizing-vertical * {
	cursor: ns-resize !important;
	user-select: none;
}

/* Gutter styles */
.gutter {
	background-color: var(--resizer-color);
	background-repeat: no-repeat;
	background-position: 50%;
	border-left: 1px solid var(--border-color);
	border-right: 1px solid var(--border-color);
	transition: background-color 0.2s ease;
}

.gutter.gutter-horizontal {
	cursor: col-resize;
	min-width: 2px;
	width: 2px;
}

.gutter.gutter-horizontal:hover {
	background-color: var(--resizer-hover-color);
	transform: scaleX(2);
}

/* Board select */
#boardSelect {
	background-color: var(--secondary-bg);
	border: 1px solid var(--border-color);
	color: var(--text-color);
	padding: 4px 8px;
	border-radius: var(--radius-sm);
	font-size: 0.85em;
	cursor: pointer;
	transition: all 0.2s ease;
}

#boardSelect:hover {
	background-color: var(--main-bg);
	box-shadow: var(--shadow-md);
}

/* Theme toggle */
.theme-toggle {
	background: none;
	border: none;
	color: var(--text-muted-color);
	cursor: pointer;
	font-size: 18px;
	padding: 4px;
	border-radius: var(--radius-sm);
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
	justify-content: center;
}

.theme-toggle:hover {
	background: var(--secondary-bg);
	color: var(--text-color);
	transform: scale(1.1);
}

/* Dark mode specific */
body.dark-mode {
	background-color: var(--secondary-bg);
}

body.dark-mode .theme-toggle:hover {
	background: var(--secondary-bg);
}

/* Split.js styles */
.split {
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;
	overflow-y: auto;
	overflow-x: hidden;
}

.split, .gutter.gutter-horizontal {
	float: left;
	height: 100%;
}

/* Container layout */
#container {
	display: flex;
	height: 100%;
	width: 100%;
	overflow: hidden;
}

/* Main content area */
.editor-content {
	flex-grow: 1;
	overflow-y: auto;
	position: relative;
}

/* Header and footer content areas */
.header-content,
.footer-content {
	position: relative;
	flex-grow: 1;
	overflow: hidden;
}

/* Utility classes */
.show {
	display: block !important;
}

/* Premium badge */
.premium-badge {
	font-size: 0.7em;
	background: var(--gradient-hero);
	color: white;
	padding: 2px 6px;
	border-radius: var(--radius-md);
	margin-left: 4px;
	vertical-align: middle;
	font-weight: 500;
}

/* ========================================
   Craft Card UI - Craft Docs風レイアウト
   ======================================== */

/* Craft風背景ラッパー */
.craft-card-wrapper {
	position: relative;
	width: 100%;
	height: 100vh;
	background: var(--gray-200);
	padding: 16px;
	overflow: hidden;
	display: flex;
	justify-content: center;
	align-items: flex-start;
	box-sizing: border-box;
}

/* Sheet Name Label - displays current board name in top-left corner */
.sheet-name-label {
	position: absolute;
	top: 0;
	left: 15px;
	height: 28px;
	line-height: 28px;
	font-size: 12px;
	font-weight: 500;
	color: var(--gray-500);
	letter-spacing: 0.02em;
	z-index: 1;
	pointer-events: auto;
	cursor: pointer;
	opacity: 0;
	transition: opacity 0.2s ease, background-color 0.15s ease;
	padding: 0 6px;
	border-radius: 4px;
}


/* When sheet name is visible, show the label */
.craft-card-wrapper.has-sheet-name .sheet-name-label {
	opacity: 1;
}

/* Inline edit input for sheet name */
.sheet-name-inline-edit {
	width: 200px;
	padding: 2px 6px;
	font-size: 12px;
	font-weight: 500;
	font-family: inherit;
	border: none;
	border-radius: 4px;
	background: transparent;
	color: var(--gray-700);
	outline: none;
	box-sizing: border-box;
}

/* User Name Label - displays username in top-right corner (only when logged in) */
.user-name-label {
	position: absolute;
	top: 0;
	right: 15px;
	height: 28px;
	line-height: 28px;
	font-size: 12px;
	font-weight: 500;
	color: var(--gray-500);
	letter-spacing: 0.02em;
	z-index: 1;
	pointer-events: none;
	user-select: none;
	opacity: 0;
	transition: opacity 0.2s ease;
}

/* When user is logged in and has name, show the label */
.craft-card-wrapper.has-user-name .user-name-label {
	opacity: 1;
}

/* Adjust card position when sheet name is visible */
.craft-card-wrapper.has-sheet-name {
	padding-top: 28px;
}

.craft-card-wrapper.has-sheet-name .craft-card {
	height: calc(100vh - 44px); /* 32px base - 16px top padding removed + 28px label area */
}

/* メインカード - 埋め込み型（inset shadow） */
.craft-card {
	width: calc(100% - 0px);
	max-width: calc(100vw - 32px);
	height: calc(100vh - 32px);
	background: var(--bg-primary);
	border-radius: var(--radius-lg);
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06),
	            inset 0 0 0 1px rgba(0, 0, 0, 0.04);
	overflow: hidden;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
}

/* カード内コンテンツ */
.craft-card-content {
	flex: 1;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	position: relative;
}

/* ミニメニューとタイマーをカード内に制限 */
/* mini-menu.cssのfixed指定を上書き、位置はJSで制御 */
.craft-card-content .mini-menu-dock {
	position: absolute !important;
	top: unset !important;
	bottom: unset !important;
	left: unset !important;
	right: unset !important;
}

/* タイマーはposition: fixedのまま、JSで境界制御 */

/* AIチャットモーダルとトグルをカード内に制限 */
.craft-card-content .ai-chat-modal {
	position: absolute !important;
	bottom: 20px !important;
	right: 20px !important;
	top: auto !important;
	left: auto !important;
	max-height: calc(100% - 40px) !important;
}

.craft-card-content .ai-chat-toggle {
	position: absolute !important;
	bottom: 20px !important;
	right: 20px !important;
	top: auto !important;
	left: auto !important;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
	.craft-card-wrapper {
		padding: 8px;
	}

	.craft-card {
		border-radius: var(--radius-md);
		height: calc(100vh - 16px);
	}
}

/* ダークモード対応 */
body.dark-mode .craft-card-wrapper {
	background: var(--gray-900);
}

body.dark-mode .sheet-name-label,
body.dark-mode .user-name-label {
	color: var(--gray-600);
}

body.dark-mode .sheet-name-inline-edit {
	background: transparent;
	color: var(--gray-200);
}

body.dark-mode .craft-card {
	background: var(--gray-800);
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2),
	            inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}