/* ========================================
   AFS-Software Tools Landing Page
   Apple-inspired Design System
   ======================================== */

:root {
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

    /* Light theme */
    --bg: #f5f5f7;
    --surface: rgba(255, 255, 255, 0.72);
    --surface-solid: #ffffff;
    --surface-hover: rgba(255, 255, 255, 0.88);
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-tertiary: #86868b;
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.16);
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --accent-subtle: rgba(0, 113, 227, 0.08);
    --overlay-bg: rgba(255, 255, 255, 0.45);
    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.06), 0 0.5px 2px rgba(0, 0, 0, 0.04);
    --shadow-card-hover: 0 8px 32px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-panel: 0 24px 80px rgba(0, 0, 0, 0.12);
    --glass-blur: 20px;
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --danger: #ff3b30;
    --success: #34c759;
    --warning: #ff9500;
}

[data-theme="dark"] {
    --bg: #000000;
    --surface: rgba(28, 28, 30, 0.72);
    --surface-solid: #1c1c1e;
    --surface-hover: rgba(44, 44, 46, 0.88);
    --text-primary: #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-tertiary: #6e6e73;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --accent: #2997ff;
    --accent-hover: #40a3ff;
    --accent-subtle: rgba(41, 151, 255, 0.1);
    --overlay-bg: rgba(0, 0, 0, 0.5);
    --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.3), 0 0.5px 2px rgba(0, 0, 0, 0.2);
    --shadow-card-hover: 0 8px 32px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-panel: 0 24px 80px rgba(0, 0, 0, 0.5);
}

/* ========================================
   Reset & Base
   ======================================== */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    color: var(--text-primary);
    background: var(--bg);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background 0.4s ease, color 0.4s ease;
}

/* ========================================
   Fixed Background
   ======================================== */

.bg-fixed {
    position: fixed;
    inset: 0;
    z-index: -2;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    transition: opacity 0.6s ease;
}

.bg-overlay {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: var(--overlay-bg);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    transition: background 0.4s ease;
}

/* ========================================
   Header
   ======================================== */

.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--border);
    transition: background 0.4s ease;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle,
.admin-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
}

.theme-toggle:hover,
.admin-btn:hover {
    background: var(--accent-subtle);
    color: var(--accent);
}

.theme-toggle svg,
.admin-btn svg {
    width: 20px;
    height: 20px;
}

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
.icon-sun { display: none; }
.icon-moon { display: block; }

/* ========================================
   Hero
   ======================================== */

.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    min-height: calc(100vh - 52px);
    display: flex;
    flex-direction: column;
}

.hero {
    text-align: center;
    padding: 80px 0 48px;
}

.hero-title {
    font-size: clamp(2.5rem, 6vw, 4rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.1;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 16px;
}

.hero-subtitle {
    font-size: clamp(1.125rem, 2.5vw, 1.375rem);
    color: var(--text-secondary);
    font-weight: 400;
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.5;
}

/* ========================================
   Tools Grid (Cards)
   ======================================== */

.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    padding-bottom: 80px;
    flex: 1;
}

.tool-card {
    background: var(--surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                box-shadow 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                background 0.3s ease,
                border-color 0.3s ease;
    box-shadow: var(--shadow-card);
    cursor: default;
    text-decoration: none;
    color: inherit;
    position: relative;
    overflow: hidden;
}

.tool-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    opacity: 0;
    background: linear-gradient(135deg, var(--accent-subtle), transparent);
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.tool-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-card-hover);
    border-color: var(--border-strong);
}

.tool-card:hover::before {
    opacity: 1;
}

.tool-card-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: var(--accent-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tool-card-icon img {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.tool-card-icon svg {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.tool-card-title {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.tool-card-text {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    line-height: 1.6;
    flex: 1;
}

.tool-card-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--accent);
    text-decoration: none;
    transition: gap 0.2s ease;
    margin-top: auto;
}

.tool-card-link:hover {
    gap: 10px;
}

.tool-card-link svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.tool-card-link-desc {
    font-size: 0.8125rem;
    color: var(--text-tertiary);
    margin-top: 4px;
}

/* Empty state */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 80px 20px;
    color: var(--text-tertiary);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 20px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 1.125rem;
}

/* ========================================
   Footer
   ======================================== */

/* ========================================
   Ad Banner
   ======================================== */

.ad-banner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

.ad-frame {
    width: 100%;
}

.ad-frame iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.site-footer {
    text-align: center;
    padding: 24px 24px 32px;
    color: var(--text-tertiary);
    font-size: 12px;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-top: 10px;
}

.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 12px;
    transition: color 0.2s ease;
}

.footer-links a:hover {
    color: var(--accent);
}

/* ========================================
   Admin Overlay & Panel
   ======================================== */

.admin-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.admin-overlay.active {
    opacity: 1;
    visibility: visible;
}

.admin-panel {
    width: min(520px, calc(100vw - 32px));
    height: 100vh;
    background: var(--surface-solid);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: 32px;
    position: relative;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.admin-overlay.active .admin-panel {
    transform: translateX(0);
}

.admin-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.admin-close:hover {
    background: var(--border-strong);
}

.admin-close svg {
    width: 16px;
    height: 16px;
}

/* ========================================
   Admin Login
   ======================================== */

.admin-login {
    max-width: 360px;
    margin: 120px auto 0;
    text-align: center;
}

.admin-login h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.setup-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 28px;
}

/* ========================================
   Admin Dashboard
   ======================================== */

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.admin-header h2 {
    font-size: 1.375rem;
    font-weight: 600;
}

.admin-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    background: var(--border);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.tab {
    flex: 1;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab.active {
    background: var(--surface-solid);
    color: var(--text-primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.admin-section {
    margin-bottom: 32px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.admin-section h3 {
    font-size: 1.0625rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.section-header h3 {
    margin-bottom: 0;
}

/* ========================================
   Form Elements
   ======================================== */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="password"],
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-solid);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.9375rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.password-field {
    position: relative;
}

.password-field input {
    padding-right: 44px;
}

.pw-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.pw-toggle:hover {
    color: var(--text-secondary);
}

.pw-toggle svg {
    width: 18px;
    height: 18px;
}

.pw-toggle .eye-closed { display: none; }
.pw-toggle.showing .eye-open { display: none; }
.pw-toggle.showing .eye-closed { display: block; }

.pw-strength {
    margin-top: 6px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    overflow: hidden;
}

.pw-strength-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease, background 0.3s ease;
}

.error-msg {
    color: var(--danger);
    font-size: 0.8125rem;
    margin-top: 8px;
    min-height: 1.2em;
}

.success-msg {
    color: var(--success);
    font-size: 0.8125rem;
    margin-top: 8px;
    min-height: 1.2em;
}

/* ========================================
   Buttons
   ======================================== */

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    transform: scale(1.02);
}

.btn-sm {
    padding: 7px 14px;
    font-size: 0.8125rem;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}

.btn-ghost:hover {
    background: var(--border);
    color: var(--text-primary);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    padding: 8px 12px;
}

.btn-danger:hover {
    background: rgba(255, 59, 48, 0.1);
}

/* ========================================
   Card Editor Items
   ======================================== */

.card-editor-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 12px;
    transition: border-color 0.2s ease;
}

.card-editor-item:hover {
    border-color: var(--border-strong);
}

.card-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-editor-header span {
    font-weight: 600;
    font-size: 0.9375rem;
}

.card-editor-actions {
    display: flex;
    gap: 4px;
}

.card-editor-item .form-group {
    margin-bottom: 14px;
}

.card-editor-item .form-group:last-child {
    margin-bottom: 0;
}

.drag-handle {
    cursor: grab;
    color: var(--text-tertiary);
    padding: 4px;
    display: flex;
}

.drag-handle svg {
    width: 16px;
    height: 16px;
}

/* ========================================
   Toast Notifications
   ======================================== */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    background: var(--surface-solid);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-panel);
    font-size: 0.875rem;
    color: var(--text-primary);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    max-width: 360px;
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--danger);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(-8px) scale(0.96); }
}

/* ========================================
   Utility
   ======================================== */

.hidden {
    display: none !important;
}

/* ========================================
   Card appear animation
   ======================================== */

.tool-card {
    animation: cardAppear 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.tool-card:nth-child(1) { animation-delay: 0.05s; }
.tool-card:nth-child(2) { animation-delay: 0.1s; }
.tool-card:nth-child(3) { animation-delay: 0.15s; }
.tool-card:nth-child(4) { animation-delay: 0.2s; }
.tool-card:nth-child(5) { animation-delay: 0.25s; }
.tool-card:nth-child(6) { animation-delay: 0.3s; }
.tool-card:nth-child(7) { animation-delay: 0.35s; }
.tool-card:nth-child(8) { animation-delay: 0.4s; }
.tool-card:nth-child(9) { animation-delay: 0.45s; }

@keyframes cardAppear {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 768px) {
    .header-inner {
        padding: 0 16px;
    }

    .main-content {
        padding: 0 16px;
    }

    .hero {
        padding: 48px 0 32px;
    }

    .tools-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .admin-panel {
        width: 100vw;
        padding: 24px 20px;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: 2rem;
    }

    .hero-subtitle {
        font-size: 1rem;
    }

    .tool-card {
        padding: 20px;
    }

    .admin-tabs {
        flex-direction: column;
    }
}

@media (min-width: 1400px) {
    .tools-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ========================================
   Scrollbar
   ======================================== */

::-webkit-scrollbar {
    width: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}

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

/* ========================================
   Print
   ======================================== */

@media print {
    .site-header,
    .admin-overlay,
    .toast-container,
    .theme-toggle,
    .admin-btn {
        display: none !important;
    }

    .bg-fixed, .bg-overlay {
        display: none;
    }

    .tool-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
