/* ==========================================================================
   PREMIUM OVERHAUL: MARUF TOOLS & UTILITIES SYSTEM
   ========================================================================== */

/* 1. Dynamic CSS Theme Variables */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --panel-bg: rgba(255, 255, 255, 0.65);
    --panel-alt-bg: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-light: #94a3b8;
    --border-color: rgba(226, 232, 240, 0.8);
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --accent-color: #3b82f6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --shadow-md: 0 10px 25px rgba(15, 23, 42, 0.04);
    --border-radius: 14px;
    --transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

[data-theme="dark"] {
    --bg-primary: #0b0f19;
    --bg-secondary: #0f172a;
    --panel-bg: rgba(17, 24, 39, 0.65);
    --panel-alt-bg: #1e293b;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-light: #6b7280;
    --border-color: rgba(255, 255, 255, 0.08);
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --accent-color: #8b5cf6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* 2. Base Styles & Body Overrides */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden;
    max-width: 100%;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

a {
    color: inherit;
    text-decoration: none;
}

.site-shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* 3. Header & Navigation styling */
.tg-header {
    background: var(--panel-bg);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: background-color 0.3s, border-color 0.3s;
}

.tg-brand {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--text-primary) !important;
}

.tg-nav a {
    color: var(--text-secondary);
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 30px;
    transition: var(--transition);
}

.tg-nav a:hover, .tg-nav a[data-active="true"] {
    background: rgba(99, 102, 241, 0.08);
    color: var(--primary-color) !important;
}

/* Shared theme toggle */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.theme-toggle:hover {
    transform: scale(1.05);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.theme-toggle i {
    position: absolute;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.5s ease;
}

.theme-toggle .sun-icon {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
}

.theme-toggle .moon-icon {
    transform: translateY(30px) rotate(90deg);
    opacity: 0;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    transform: translateY(-30px) rotate(-90deg);
    opacity: 0;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    transform: translateY(0) rotate(0deg);
    color: #f59e0b;
    opacity: 1;
}

/* 4. Page layouts & Cards */
.hero {
    padding: 3.5rem 0 2rem;
}

.hero h1 {
    font-size: clamp(2rem, 5vw, 2.75rem);
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.hero p {
    color: var(--text-secondary);
    max-width: 65ch;
    font-size: 1.05rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.card, .tool-app {
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.card:hover {
    transform: translateY(-5px);
    border-color: rgba(99, 102, 241, 0.25);
    box-shadow: 0 15px 35px rgba(99, 102, 241, 0.08);
}

.card h2 {
    font-size: 1.35rem;
    margin: 0.5rem 0;
    color: var(--text-primary);
}

.card p {
    color: var(--text-secondary);
    margin: 0 0 1.25rem 0;
    font-size: 0.95rem;
    line-height: 1.5;
}

.chip {
    font-size: 0.75rem;
    font-weight: 700;
    border: 1px solid rgba(99, 102, 241, 0.2);
    background: rgba(99, 102, 241, 0.06);
    border-radius: 999px;
    padding: 0.25rem 0.65rem;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    display: inline-block;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: #fff !important;
    border: 0;
    border-radius: 10px;
    padding: 0.75rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.25);
}

.btn.secondary {
    background: var(--panel-alt-bg);
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color);
}

.btn.secondary:hover {
    background: var(--border-color);
    box-shadow: none;
    transform: none;
}

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

.btn.danger:hover {
    background: #dc2626;
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.25);
}

/* 5. Tool App controls and forms */
.tool-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    margin-top: 1.5rem;
}

.actions {
    margin-top: 1.25rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

label {
    display: block;
    margin: 1rem 0 0.4rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

textarea, input, select {
    width: 100%;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: 10px;
    padding: 0.8rem 1rem;
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}

textarea:focus, input:focus, select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.15);
}

textarea {
    min-height: 240px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.6;
}

.stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.stat {
    border: 1px solid var(--border-color);
    background: var(--panel-alt-bg);
    border-radius: 10px;
    padding: 1rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.stat b {
    display: block;
    color: var(--text-primary);
    font-size: 1.5rem;
    margin-top: 0.35rem;
    font-weight: 700;
}

.helper {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.helper.success {
    color: var(--success-color);
    font-weight: 600;
}

/* Calculator keypad */
.keypad {
    margin-top: 1.25rem;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.65rem;
}

.keypad button {
    padding: 1.1rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.15rem;
    cursor: pointer;
    transition: var(--transition);
}

.keypad button:hover {
    background: var(--panel-alt-bg);
    transform: scale(1.03);
}

.keypad button.btn {
    background: var(--primary-color);
    color: #fff;
}

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

.keypad .span-2 {
    grid-column: span 2;
}

/* Color picker split view */
.split {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.color-preview {
    height: 120px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    margin: 1rem 0;
    box-shadow: var(--shadow-md);
}

/* 6. Footer Layout */
.tg-footer {
    margin-top: 4rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.tg-footer-inner {
    padding: 1.5rem 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Media Queries for Responsive grids */
@media (min-width: 860px) {
    .tool-layout {
        grid-template-columns: 1.3fr 1fr;
        gap: 3rem;
    }
    .split {
        grid-template-columns: 1fr 1fr;
    }
}
