/* ============================================================
   IG Tool — Dark Theme (matches LINE tool style)
   ============================================================ */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a2e;
    --bg-input: #16213e;
    --border: #2a2a4a;
    --accent: #E1306C;
    --accent-hover: #c92b5f;
    --accent-blue: #405DE6;
    --accent-green: #06d6a0;
    --accent-red: #ef476f;
    --accent-yellow: #ffd166;
    --accent-orange: #F77737;
    --text-primary: #e8e8f0;
    --text-secondary: #8888aa;
    --text-muted: #555577;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: 'Segoe UI', 'Microsoft JhengHei', 'Noto Sans TC', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ============================================================
   Auth Pages
   ============================================================ */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.auth-logo {
    text-align: center;
    margin-bottom: 30px;
}

.auth-logo h1 {
    font-size: 28px;
    background: linear-gradient(135deg, var(--accent), var(--accent-orange));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-logo p {
    color: var(--text-secondary);
    margin-top: 8px;
    font-size: 14px;
}

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: 20px; }
.form-group label {
    display: block;
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 6px;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    transition: border-color 0.2s;
    outline: none;
}

.form-input:focus {
    border-color: var(--accent);
}

.form-textarea {
    resize: vertical;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    line-height: 1.5;
}

.flash {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
}
.flash-error { background: rgba(239,71,111,0.15); color: var(--accent-red); border: 1px solid rgba(239,71,111,0.3); }
.flash-success { background: rgba(6,214,160,0.15); color: var(--accent-green); border: 1px solid rgba(6,214,160,0.3); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), var(--accent-orange));
    color: white;
    border: none;
    padding: 12px;
    font-size: 15px;
}
.btn-primary:hover { opacity: 0.9; color: white; }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-xs { padding: 4px 10px; font-size: 12px; }
.btn-danger { color: var(--accent-red); border-color: rgba(239,71,111,0.3); }
.btn-danger:hover { background: rgba(239,71,111,0.15); border-color: var(--accent-red); }
.btn-warning { color: var(--accent-yellow); border-color: rgba(255,209,102,0.3); }
.btn-warning:hover { background: rgba(255,209,102,0.15); border-color: var(--accent-yellow); }

/* ============================================================
   Layout
   ============================================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
    font-size: 20px;
    background: linear-gradient(135deg, var(--accent), var(--accent-orange));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
    text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.nav-item.active { background: rgba(225,48,108,0.1); color: var(--accent); }
.nav-item .icon { font-size: 18px; width: 24px; text-align: center; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-orange));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: white;
}

.user-name { font-size: 14px; font-weight: 500; }
.user-role { font-size: 12px; color: var(--text-muted); }

.logout-btn {
    display: block;
    text-align: center;
    padding: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}
.logout-btn:hover { background: rgba(239,71,111,0.1); color: var(--accent-red); }

.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 24px;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.card-title { font-size: 20px; font-weight: 600; }
.card-subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   Account Grid
   ============================================================ */
.account-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.account-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: border-color 0.2s, box-shadow 0.2s;
    position: relative;
}
.account-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 24px rgba(225,48,108,0.08);
}

/* Top row: avatar + name/status + edit gear */
.account-top {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 14px;
}

.account-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.account-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid var(--border);
    object-fit: cover;
    transition: border-color 0.2s;
}
.account-card:hover .account-avatar {
    border-color: var(--accent);
}

.account-avatar-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
}
.account-avatar-badge.badge-active { background: var(--accent-green); }
.account-avatar-badge.badge-expired { background: var(--accent-red); }
.account-avatar-badge.badge-pending { background: var(--accent-yellow); }
.account-avatar-badge.badge-error { background: var(--accent-orange); }

.account-name-block {
    flex: 1;
    min-width: 0;
}

.account-username {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-fullname {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-status {
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}
.status-active { background: rgba(6,214,160,0.15); color: var(--accent-green); }
.status-expired { background: rgba(239,71,111,0.15); color: var(--accent-red); }
.status-pending { background: rgba(255,209,102,0.15); color: var(--accent-yellow); }
.status-error { background: rgba(247,119,55,0.15); color: var(--accent-orange); }

/* Stats row */
.account-stats {
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    margin-bottom: 10px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.account-stat {
    text-align: center;
}
.account-stat-num {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}
.account-stat-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Bio */
.account-bio {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 12px;
    max-height: 54px;
    overflow: hidden;
    word-break: break-word;
}
.account-bio:empty { display: none; }

/* Action buttons */
.account-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-edit-profile {
    color: var(--accent-blue);
    border-color: rgba(64,93,230,0.3);
}
.btn-edit-profile:hover {
    background: rgba(64,93,230,0.15);
    border-color: var(--accent-blue);
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}
.empty-state .text-muted { color: var(--text-muted); font-size: 13px; margin-top: 8px; }

/* ============================================================
   Check All Button
   ============================================================ */
.btn-check-all {
    color: var(--accent-blue);
    border-color: rgba(64,93,230,0.3);
}
.btn-check-all:hover {
    background: rgba(64,93,230,0.15);
    border-color: var(--accent-blue);
}

/* ============================================================
   Follow Tab
   ============================================================ */
.follow-form {
    max-width: 600px;
}

.account-select-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.account-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
    user-select: none;
}
.account-checkbox:hover { border-color: var(--accent); }
.account-checkbox input:checked + .account-avatar-sm { border-color: var(--accent); }
.account-checkbox input { accent-color: var(--accent); }

.account-avatar-sm {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.follow-results {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.follow-result-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.follow-result-item:last-child { border-bottom: none; }
.follow-result-ok { color: var(--accent-green); }
.follow-result-fail { color: var(--accent-red); }
.follow-result-account { color: var(--accent); font-weight: 500; }

.admin-info {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 2;
}

/* ============================================================
   Tabs
   ============================================================ */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============================================================
   Modals
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.show { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}
.modal-footer .btn-primary { width: 100%; }

/* ============================================================
   Toast
   ============================================================ */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    animation: slideIn 0.3s ease;
    min-width: 280px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.toast-success { background: rgba(6,214,160,0.9); color: #000; }
.toast-error { background: rgba(239,71,111,0.9); color: #fff; }
.toast-info { background: rgba(64,93,230,0.9); color: #fff; }

@keyframes slideIn {
    from { transform: translateX(100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   Loading Spinner
   ============================================================ */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   AI Post
   ============================================================ */
.ai-post-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 24px;
    align-items: start;
}

.ai-post-settings {
    max-width: 340px;
}

.ai-preview-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.ai-preview-image-wrap {
    position: relative;
    aspect-ratio: 1;
    background: var(--bg-input);
}

.ai-preview-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ai-preview-caption-wrap {
    padding: 16px;
    position: relative;
}

.ai-preview-caption-wrap textarea {
    font-size: 13px;
    line-height: 1.6;
    background: transparent;
    border-color: transparent;
    resize: vertical;
}
.ai-preview-caption-wrap textarea:focus {
    border-color: var(--accent);
}

.ai-regen-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.6) !important;
    border: none !important;
    color: white !important;
    backdrop-filter: blur(4px);
    z-index: 2;
}
.ai-regen-btn:hover {
    background: rgba(225,48,108,0.8) !important;
}

.ai-preview-card .btn-primary {
    margin: 0 16px 16px;
    width: calc(100% - 32px);
}

.ai-loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(10,10,15,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    z-index: 10;
    color: var(--text-secondary);
    font-size: 14px;
}

.ai-loading-overlay .spinner {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

/* ============================================================
   Edit Profile Modal
   ============================================================ */
.edit-avatar-section {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.edit-avatar-preview {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.edit-avatar-btn {
    position: relative;
    overflow: hidden;
}
.edit-avatar-btn input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.edit-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.edit-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-header h2, .nav-item span:not(.icon), .user-info div:not(.user-avatar), .logout-btn { display: none; }
    .sidebar-header { padding: 16px 10px; }
    .nav-item { justify-content: center; padding: 12px; }
    .main-content { margin-left: 60px; padding: 16px; }
    .account-grid { grid-template-columns: 1fr; }
    .ai-post-layout { grid-template-columns: 1fr; }
}
