/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px 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);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans",
                 "Noto Sans JP", sans-serif;
    color: var(--gray-900);
    background: var(--gray-50);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 24px; }

/* === Header === */
.header {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    padding: 12px 0;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; }
.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
    text-decoration: none;
}
.nav { display: flex; gap: 12px; align-items: center; }
.user-email { font-size: 0.85rem; color: #555; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.user-email:hover { color: var(--primary); text-decoration: underline; }

/* === Main === */
.main { flex: 1; padding: 48px 0; }

/* === Footer === */
.footer {
    text-align: center;
    padding: 24px 0;
    color: var(--gray-500);
    font-size: 0.85rem;
    border-top: 1px solid var(--gray-200);
}

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
    text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-google {
    background: #fff;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}
.btn-google:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn-github {
    background: #24292f;
    color: #fff;
    border: 1px solid #24292f;
}
.btn-github:hover { background: #32383f; color: #fff; }
.btn-discord {
    background: #5865F2;
    color: #fff;
    border: 1px solid #5865F2;
}
.btn-discord:hover { background: #4752C4; color: #fff; }

/* OAuth button group */
.oauth-buttons { display: flex; flex-direction: column; gap: 10px; }
.btn-oauth {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 11px 20px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s;
}
.oauth-icon { width: 20px; height: 20px; flex-shrink: 0; }
.btn-lg { padding: 14px 32px; font-size: 1.05rem; }
.btn-block { width: 100%; display: block; }

/* === Hero Section === */
.hero { text-align: center; padding: 32px 0; }
.hero h1 { font-size: 2rem; line-height: 1.3; margin-bottom: 16px; }
.hero-sub { color: var(--gray-500); font-size: 1.1rem; margin-bottom: 40px; }

.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 24px; margin-bottom: 40px; }
.feature-card {
    background: #fff;
    padding: 28px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}
.feature-icon { font-size: 2rem; margin-bottom: 12px; }
.feature-card h3 { margin-bottom: 8px; font-size: 1.05rem; }
.feature-card p { color: var(--gray-500); font-size: 0.9rem; }

.cta-group { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }

/* === App Cards (Portal) === */
.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
    max-width: 960px;
    margin-left: auto;
    margin-right: auto;
}
.app-card {
    display: block;
    background: #fff;
    padding: 28px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--gray-900);
    border-left: 4px solid var(--card-accent, var(--primary));
    transition: box-shadow 0.2s, transform 0.15s;
}
.app-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}
.app-card-icon { font-size: 2rem; margin-bottom: 12px; }
.app-card h3 { margin-bottom: 8px; font-size: 1.1rem; font-weight: 600; }
.app-card p { color: var(--gray-500); font-size: 0.9rem; line-height: 1.5; }
.no-apps { color: var(--gray-500); padding: 40px 0; }
.oauth-divider {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 24px 0;
    color: var(--gray-500);
    font-size: 0.9rem;
}
.oauth-divider::before,
.oauth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--gray-200);
}

/* === Auth Forms === */
.auth-section { display: flex; justify-content: center; padding: 24px 0; }
.auth-card {
    background: #fff;
    padding: 40px 36px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 440px;
}
.auth-card h2 { text-align: center; margin-bottom: 28px; }

.auth-form { display: flex; flex-direction: column; gap: 20px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.9rem; font-weight: 500; color: var(--gray-700); }
.form-group .optional { font-weight: 400; color: var(--gray-500); }
.form-group input {
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
}
.form-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

.auth-links {
    text-align: center;
    margin-top: 20px;
    display: flex;
    justify-content: center;
    gap: 24px;
}
.auth-links a { color: var(--primary); font-size: 0.9rem; text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }
.auth-description { color: var(--gray-500); font-size: 0.9rem; line-height: 1.5; margin-bottom: 20px; text-align: center; }

/* === Alerts === */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 0.9rem;
}
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

/* === Responsive === */
@media (max-width: 640px) {
    .hero h1 { font-size: 1.5rem; }
    .auth-card { padding: 28px 20px; }
    .cta-group { flex-direction: column; align-items: center; }
}

/* Form hints */
.form-hint {
    display: block;
    margin-top: 4px;
    font-size: 0.8rem;
    color: #6b7280;
}

/* === Language Dropdown === */
.lang-dropdown { position: relative; display: inline-block; }
.lang-dropdown-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 10px; border-radius: 6px;
    border: 1px solid var(--gray-200); background: #fff;
    cursor: pointer; font-size: .85rem; color: var(--gray-700);
    transition: all .15s; white-space: nowrap;
}
.lang-dropdown-btn:hover { border-color: var(--gray-500); background: var(--gray-50); }
.lang-dropdown-btn .flag { font-size: 1.1rem; }
.lang-dropdown-btn .arrow { font-size: .6rem; color: var(--gray-500); margin-left: 2px; }
.lang-dropdown-menu {
    display: none; position: absolute; top: calc(100% + 4px); right: 0;
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: 8px; box-shadow: var(--shadow-lg);
    min-width: 170px; z-index: 100; overflow: hidden;
}
.lang-dropdown.open .lang-dropdown-menu { display: block; }
.lang-dropdown-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; font-size: .88rem; color: var(--gray-700);
    text-decoration: none; cursor: pointer; transition: background .1s;
}
.lang-dropdown-item:hover { background: var(--gray-50); }
.lang-dropdown-item.selected { background: #f0fdf4; color: #166534; font-weight: 500; }
.lang-dropdown-item .flag { font-size: 1.15rem; }
.lang-dropdown-item .check { margin-left: auto; color: #16a34a; font-size: .85rem; }

/* ======================================================================
   Profile Page
   ====================================================================== */
.profile-container {
    width: 100%; max-width: 700px; margin: 0 auto;
}
.profile-container h2 { text-align: center; margin-bottom: 28px; }

.profile-card {
    background: #fff; padding: 24px; border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 20px;
}
.profile-card h3 {
    margin: 0 0 18px 0; font-size: 1.05rem; color: var(--gray-800);
    border-bottom: 1px solid var(--gray-100); padding-bottom: 10px;
}
.profile-field {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 0; border-bottom: 1px solid var(--gray-50);
}
.profile-field:last-child { border-bottom: none; }
.profile-label {
    min-width: 140px; font-size: 0.88rem; color: var(--gray-500); font-weight: 500; flex-shrink: 0;
}
.profile-value { font-size: 0.95rem; color: var(--gray-800); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.profile-empty { color: var(--gray-400); font-size: 0.9rem; margin: 0; }
.profile-empty-inline { color: var(--gray-400); font-size: 0.88rem; }

/* Inline form (display name) */
.profile-inline-form {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 0; border-bottom: 1px solid var(--gray-50);
}
.profile-inline-row {
    display: flex; align-items: center; gap: 8px; flex: 1;
}
.profile-inline-row input {
    flex: 1; padding: 8px 12px; border: 1px solid var(--gray-300);
    border-radius: var(--radius); font-size: 0.95rem;
}
.profile-inline-row input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59,130,246,.15); }

/* Badges */
.badge {
    display: inline-block; padding: 2px 10px; border-radius: 12px;
    font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-danger { background: #fef2f2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-role { background: #f3e8ff; color: #6b21a8; }

/* Buttons */
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-danger {
    background: #dc2626; color: #fff; border: 1px solid #dc2626;
    padding: 10px 20px; border-radius: var(--radius); cursor: pointer;
    font-size: 0.9rem; font-weight: 500;
}
.btn-danger:hover { background: #b91c1c; }
.btn-danger-outline {
    background: transparent; color: #dc2626; border: 1px solid #dc2626;
    padding: 6px 14px; border-radius: var(--radius); cursor: pointer;
    font-size: 0.85rem; font-weight: 500;
}
.btn-danger-outline:hover { background: #fef2f2; }

/* Link row */
.profile-link-row { padding-top: 14px; }

/* Danger zone */
.danger-zone { border: 1px solid #fecaca; }
.danger-zone h3 { color: #991b1b; border-bottom-color: #fecaca; }
.profile-danger-desc { font-size: 0.88rem; color: var(--gray-500); margin: 0 0 14px 0; }
.danger-details summary { list-style: none; display: inline-block; }
.danger-details summary::-webkit-details-marker { display: none; }
.danger-form {
    margin-top: 16px; padding-top: 16px; border-top: 1px solid #fecaca;
    display: flex; flex-direction: column; gap: 12px;
}

/* Change password form within profile card */
.profile-card .auth-form { gap: 16px; }

@media (max-width: 600px) {
    .profile-container { padding: 0 4px; }
    .profile-card { padding: 16px; }
    .profile-field { flex-direction: column; align-items: flex-start; gap: 4px; }
    .profile-label { min-width: auto; }
    .profile-inline-form { flex-direction: column; align-items: flex-start; }
    .profile-inline-row { width: 100%; }
}
