/* --- Google Fonts & Variables --- */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&family=JetBrains+Mono:wght@500&display=swap');

:root {
	--color-surface: #ffffff;
	--color-background: #f8f9fa;
	--color-on-surface: #202124;
	--color-on-surface-variant: #5f6368;
	--color-outline: #e0e0e0;
	--font-main: 'Noto Sans SC', sans-serif;
	--font-code: 'JetBrains Mono', monospace;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --color-primary: #8B5CF6; /* Logo Violet */
    --color-primary-dark: #7c4ee0; /* Darker violet */
    
    /* New color palette from design */
    --color-card-1: #E0F2FE; /* light-blue-100 */
    --color-card-2: #FFEDD5; /* orange-100 */
    --color-card-3: #E5E0FF; /* violet-100 */
    --color-card-4: #D1FAE5; /* green-100 */
    --color-card-5: #F3F4F6; /* gray-100 */
    --color-card-6: #FCE7F3; /* pink-100 */
    --color-card-7: #D6FEFB; /* cyan-100 */
    --color-card-8: #FEF9C3; /* yellow-100 */
    --color-card-9: #D1FAE5; /* green-100, reused */
}

/* --- Base & Layout --- */
body {
	font-family: var(--font-main);
	background-color: var(--color-background);
	color: var(--color-on-surface);
	margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-top: 64px; /* Add padding to prevent content from hiding behind fixed header */
    box-sizing: border-box; /* Ensure padding is included in height calculation */
}

/* Re-enable and style the header bar */
.top-nav {
    display: flex;
    justify-content: center;
    width: 100%;
    height: 64px;
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--color-outline);
    box-shadow: var(--shadow-sm);
    z-index: 1000;
    position: fixed; /* Fix header to the top */
    top: 0;
    left: 0;
}

.nav-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1280px; /* Increased width */
    padding: 0 2rem;
}

.nav-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
}

.logo {
    width: 32px; /* Adjusted size for header */
    height: 32px;
}

.logo-text {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--color-on-surface);
}

main {
    padding: 2rem;
    flex-grow: 1;
    width: 100%;
    max-width: 1280px; /* Increased width */
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
    /* Re-add vertical centering for the content inside main */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* --- Search Bar Styles --- */
.search-container {
    position: relative;
    max-width: 720px; /* Make search bar smaller */
    margin: 0 auto 3rem auto; /* Center it and add more bottom margin */
}

.search-icon {
    position: absolute;
    top: 50%;
    left: 16px;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--color-on-surface-variant);
    opacity: 0.6;
}

#tool-search {
    width: 100%;
    padding: 12px 12px 12px 48px; /* Adjust padding */
    font-size: 1em; /* Adjust font size */
    font-family: var(--font-main);
    color: var(--color-on-surface);
    background-color: var(--color-surface);
    border: 1px solid var(--color-outline);
    border-radius: 12px;
    box-sizing: border-box;
    transition: all 0.2s;
}

#tool-search:focus {
    border-color: #8B5CF6; /* Use logo color for focus */
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
    outline: none;
}


#content-area {
    /* This rule is now redundant as its properties are merged into main */
}


#tool-content {
    max-width: 100%; /* Override previous max-width */
    margin: 0 auto;
    /* display: flex; */ /* This was causing the single-column layout issue */
    /* flex-direction: column; */ /* This was forcing everything into a column */
    /* gap: 1.5rem; */
}

footer {
	text-align: center;
	padding: 1.5rem;
	color: #5f6368;
	font-size: 0.85em;
    border-top: 1px solid var(--color-outline);
    background-color: var(--color-surface);
    flex-shrink: 0;
}

footer a {
    color: var(--color-on-surface-variant);
    text-decoration: none;
}

footer a:hover {
    color: var(--color-on-surface);
}

footer .icp-info {
    margin-top: 0.5rem;
    font-size: 0.9em;
}

/* --- Slogan & Page Headers --- */
/* These rules are no longer needed as the header is now global */
.page-header, .page-logo, .slogan {
    /* These can be removed or repurposed if needed elsewhere */
}

.tool-group-header {
    font-size: 1.25em;
    font-weight: 500;
    margin-top: 0; /* Adjusted for grid layout */
    margin-bottom: 0; /* Adjusted for grid layout */
    color: var(--color-on-surface);
    grid-column: 1 / -1; /* Make header span all columns */
    margin-top: 1.5rem; /* Add space between groups */
}

.tool-group-header:first-of-type {
    margin-top: 0;
}

/* --- V2: Two-Column Tool Page Styles --- */
.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 2em;
    margin: 0 0 0.5rem 0;
}

.page-header p {
    font-size: 1.1em;
    color: var(--color-on-surface-variant);
    margin: 0;
}

.tool-container-v2 {
    display: grid;
    /* Adjusted column ratio for better balance */
    grid-template-columns: 3fr 2fr;
    gap: 1.5rem;
    align-items: flex-start;
}

.action-zone {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.context-zone .tool-section { /* Reuse tool-section for consistency */
    position: sticky;
    top: 80px; /* 64px header + 16px margin */
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.panel-header h2 {
    font-size: 1.1em;
    font-weight: 500;
    margin: 0;
    color: var(--color-on-surface-variant);
}

.button-group {
    display: flex;
    gap: 0.5rem;
}

.button-group button, .panel-header > button {
    padding: 4px 12px;
    font-size: 0.85em;
    font-family: var(--font-main);
    font-weight: 500;
    color: #fff;
    background-color: var(--color-primary);
    border: 1px solid var(--color-primary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.button-group button:hover, .panel-header > button:hover {
    background-color: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}

.button-group button.primary-action {
    background-color: var(--color-primary);
    color: #fff;
}

.button-group button.primary-action:hover {
    background-color: #7c4ee0; /* Darker violet on hover */
}

.panel-footer {
    text-align: right;
    font-size: 0.85em;
    color: var(--color-on-surface-variant);
    margin-top: 0.75rem; /* Use margin to create space from textarea above */
    padding: 0; /* Remove padding */
}

.context-zone h3 {
    font-size: 1.2em;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}
.context-zone h3:first-child {
    margin-top: 0;
}

.context-zone pre {
    background-color: var(--color-background);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--color-outline);
    white-space: pre-wrap;
    word-break: break-all;
}

.context-zone code {
    font-family: var(--font-code);
}

.context-zone a {
    display: block;
    margin-top: 0.5rem;
    color: #8B5CF6;
    text-decoration: none;
}
.context-zone a:hover {
    text-decoration: underline;
}

/* --- ASCII Table Styles --- */
.ascii-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

.ascii-table th,
.ascii-table td {
    border: 1px solid var(--color-outline);
    padding: 0.5rem;
    text-align: center;
    font-family: var(--font-code);
}

.ascii-table th {
    background-color: var(--color-background);
    font-weight: 500;
}

.ascii-table td:nth-child(3n),
.ascii-table td:nth-child(3n-2) {
    width: 15%; /* Dec and Char columns */
}
.ascii-table td:nth-child(3n-1) {
    width: 18%; /* Hex column */
}


/* Style for definition list in results */
.result-dl {
    display: grid;
    grid-template-columns: 100px 1fr;
    gap: 1rem;
    margin: 0;
}
.result-dl dt {
    font-weight: 500;
    color: var(--color-on-surface-variant);
}
.result-dl dd {
    margin: 0;
    font-weight: 500;
    word-break: break-all;
}


/* Responsive: stack columns on smaller screens */
@media (max-width: 900px) {
    .tool-container-v2 {
        grid-template-columns: 1fr;
    }
    .context-zone .tool-section {
        position: static;
        top: auto;
    }
}


/* --- Generic Tool Page Styles --- */
.tool-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

.tool-section {
    background-color: var(--color-surface);
    border: 1px solid var(--color-outline);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    /* Remove internal top/bottom padding from children to rely on this padding */
}

.tool-section > *:first-child {
    margin-top: 0;
}
.tool-section > *:last-child {
    margin-bottom: 0;
}

.tool-section h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.1em;
    font-weight: 500;
    color: var(--color-on-surface-variant);
}

.io-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: stretch;
}

.io-box {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.io-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9em;
    font-weight: 500;
    color: var(--color-on-surface-variant);
    padding: 0 0.25rem;
}

.io-box textarea {
    width: 100%;
    min-height: 200px;
    resize: vertical;
    padding: 12px;
    font-family: var(--font-code);
    font-size: 0.85em;
    background-color: var(--color-background);
    color: var(--color-on-surface);
    border: 1px solid var(--color-outline);
    border-radius: 8px;
    box-sizing: border-box; /* This is the critical fix */
    transition: all 0.2s;
    overflow: auto; /* Only show scrollbar when needed */
}

.io-box pre {
    width: 100%;
    min-height: 100px; /* Adjust as needed */
    margin: 0; /* Reset pre default margin */
    padding: 12px;
    font-family: var(--font-code);
    font-size: 0.85em;
    background-color: var(--color-background);
    color: var(--color-on-surface);
    border: 1px solid var(--color-outline);
    border-radius: 8px;
    box-sizing: border-box;
    white-space: pre-wrap; /* Allow wrapping */
    word-break: break-all; /* Break long strings */
    overflow: auto;
}

/* Custom scrollbar for textareas */
.io-box textarea::-webkit-scrollbar {
    width: 8px;
}
.io-box textarea::-webkit-scrollbar-track {
    background: transparent;
}
.io-box textarea::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: 20px;
}


.io-box textarea:focus {
    border-color: #8B5CF6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
    outline: none;
}

/* Custom select dropdown */
.select-wrapper {
    position: relative;
}

select.tool-select {
    width: 100%;
    padding: 12px;
    font-family: var(--font-main);
    font-size: 1em;
    background-color: var(--color-surface);
    border: 1px solid var(--color-outline);
    border-radius: 8px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.select-wrapper::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%) rotate(45deg);
    width: 6px; 
    height: 6px; 
    border-right: 2px solid var(--color-on-surface-variant);
    border-bottom: 2px solid var(--color-on-surface-variant);
    pointer-events: none;
}


.knowledge-panel dt {
    font-weight: 600;
    color: var(--color-on-surface);
    margin-top: 1rem;
}

.knowledge-panel dd {
    margin-left: 0;
    font-size: 0.9em;
    color: var(--color-on-surface-variant);
    line-height: 1.6;
}


/* --- Tool Grid Styles --- */
.tool-grid {
    display: grid;
    /* Changed to a fixed 4-column layout as requested */
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

.tool-card {
    border: none;
    border-radius: 12px; /* Slightly less rounded */
    padding: 1.25rem; /* Adjusted padding */
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: var(--shadow-sm);
    /* Changed to row for side-by-side layout */
    display: flex;
    flex-direction: row;
    align-items: center; /* Vertically center icon and text */
    gap: 0.75rem; /* Reduced gap between icon and text */
}

.tool-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
}

.tool-card-icon {
    /* Made icons smaller */
    width: 24px;
    height: 24px;
    color: var(--color-on-surface);
    flex-shrink: 0; /* Prevent icon from shrinking */
}

.tool-card-title {
    font-size: 1.1em;
    font-weight: 500;
    color: var(--color-on-surface);
}

/* Assigning background colors */
.tool-card[data-tool-path="/tools/codec.html"] { background-color: var(--color-card-1); }
.tool-card[data-tool-path="/tools/base-converter.html"] { background-color: var(--color-card-2); }
.tool-card[data-tool-path="/tools/character-encoding.html"] { background-color: var(--color-card-3); }
.tool-card[data-tool-path="/tools/json-formatter.html"] { background-color: var(--color-card-4); }
.tool-card[data-tool-path="/tools/ip-converter.html"] { background-color: var(--color-card-5); }
.tool-card[data-tool-path="/tools/sql-formatter.html"] { background-color: var(--color-card-6); }
.tool-card[data-tool-path="/tools/user-agent.html"] { background-color: var(--color-card-7); }
.tool-card[data-tool-path="/tools/ascii-table.html"] { background-color: var(--color-card-8); }
.tool-card[data-tool-path="/tools/timestamp-converter.html"] { background-color: var(--color-card-3); }
.tool-card[data-tool-path="/tools/text-formatter.html"] { background-color: var(--color-card-9); }
.tool-card[data-tool-path="/tools/jwt-decoder.html"] { background-color: var(--color-card-1); }


/* --- Component Styles (from original file) --- */
.search-card {
	background: var(--color-surface);
	padding: 2rem;
	border-radius: 12px;
	border: 1px solid var(--color-outline);
    box-shadow: var(--shadow-md);
}

.input-group {
	display: flex;
	gap: 0.5rem;
}

input[type="text"] {
	flex-grow: 1;
	padding: 12px 16px;
	font-family: var(--font-code);
	font-size: 1.1em;
	background-color: var(--color-background);
	color: var(--color-on-surface);
	border: 1px solid var(--color-outline);
	border-radius: 8px;
	transition: all 0.2s;
}

input[type="text"]:focus {
	border-color: var(--color-primary);
	box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.2);
	outline: none;
}

button {
	padding: 12px 24px;
	font-size: 1em;
	font-family: var(--font-main);
	font-weight: 500;
	color: #fff;
	background-color: var(--color-primary);
	border: none;
	border-radius: 8px;
	cursor: pointer;
}

.card {
	background-color: var(--color-surface);
	padding: 1.5rem 2rem;
	border-radius: 12px;
	border: 1px solid var(--color-outline);
    box-shadow: var(--shadow-md);
}

.card h3 {
	margin: 0 0 1rem 0;
	font-size: 1.1em;
	font-weight: 500;
	color: var(--color-on-surface-variant);
}

.result-details dl {
	display: grid;
	grid-template-columns: 80px 1fr;
	gap: 1rem;
}

.result-details dt {
	color: var(--color-on-surface-variant);
	font-size: 0.9em;
}

.result-details dd {
	margin: 0;
	display: flex;
	align-items: center;
	gap: 0.5rem;
	font-weight: 500;
}

.vendor-icon {
	width: 24px;
	height: 24px;
}

.history-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.9em;
}

.history-table td {
	padding: 0.8rem 0;
	border-top: 1px solid var(--color-outline);
}

.history-table code {
	font-family: var(--font-code);
	color: var(--color-primary);
}

.error-bar {
	padding: 1rem;
	border-radius: 8px;
	background-color: #fce8e6;
	color: #a50e0e;
	font-weight: 500;
}

/* --- Copy Button --- */
.copy-btn {
    padding: 2px 8px;
    font-size: 0.75em;
    font-family: var(--font-main);
    font-weight: 500;
    color: #fff;
    background-color: var(--color-primary);
    border: 1px solid var(--color-primary);
    border-radius: 6px;
    cursor: pointer;
    margin-left: 1rem;
    transition: all 0.2s;
}

.copy-btn:hover {
    background-color: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}

.copy-btn:disabled {
    color: #fff;
    background-color: #1e8e3e; /* Success Green */
    border-color: #1e8e3e;
    cursor: default;
}

.editor-wrapper h3 {
    margin: 0;
    padding: 0.75rem 1rem;
    font-size: 1em;
    font-weight: 500;
    color: var(--color-on-surface-variant);
    background-color: var(--color-background);
    border-bottom: 1px solid var(--color-outline);
    display: flex;
    justify-content: space-between;
    align-items: center;
}