/* ============================================
   공통 CSS - 모든 페이지에서 사용
   ============================================ */

/* CSS 변수 */
:root {
    /* 브랜드 컬러 */
    --primary-color: #ff6b9d;
    --primary-dark:  #c44569;
    --primary-darker:#8b3a5e;
    --primary-gradient: linear-gradient(135deg, #ff6b9d 0%, #c44569 50%, #8b3a5e 100%);

    /* 앱 쉘 */
    --sidebar-width:       230px;
    --topbar-height:       52px;
    --sidebar-bg:          #ffffff;
    --sidebar-bg-hover:    #fff0f5;
    --sidebar-bg-active:   #ffe4ef;
    --sidebar-text:        #5a5575;
    --sidebar-text-active: #c44569;
    --sidebar-accent:      #ff6b9d;

    /* 페이지 영역 */
    --bg-page:      #f0f2f5;
    --surface:      #ffffff;
    --border:       #e4e7ec;
    --text-main:    #1a1d23;
    --text-sub:     #6b7280;
    --shadow-card:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-card-hover: 0 4px 12px rgba(0,0,0,0.12);
}

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

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-main);
    line-height: 1.6;
    background: var(--bg-page);
    overflow: hidden;  /* 앱 쉘: 전체 body 스크롤 없음 */
    display: flex;
    flex-direction: column;
}

/* ============================================
   앱 쉘 레이아웃
   ============================================ */

/* 최상단 토바 */
.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px 0 0;
    flex-shrink: 0;
    z-index: 200;
    position: relative;
}

.topbar-left {
    display: flex;
    align-items: center;
    width: var(--sidebar-width);
    flex-shrink: 0;
    padding: 0 16px;
    gap: 10px;
    border-right: 1px solid var(--border);
    height: 100%;
}

.topbar-logo-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    transition: opacity 0.2s;
}

.topbar-logo-link:hover {
    opacity: 0.8;
}

.topbar-logo {
    height: 30px;
    width: auto;
}

.topbar-title {
    font-size: 15px;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.3px;
    white-space: nowrap;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-notification {
    position: relative;
}

.topbar-notification-toggle {
    border: 1px solid #eadcf3;
    background: #f8f3ff;
    color: #5b4476;
    border-radius: 8px;
    min-height: 34px;
    padding: 6px 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.topbar-notification-toggle:hover {
    background: #f1e9ff;
    transform: translateY(-1px);
}

.topbar-notification-icon {
    font-size: 14px;
    line-height: 1;
}

.topbar-notification-text {
    line-height: 1;
}

.topbar-notification-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ff4d8d;
    color: #fff;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(255, 77, 141, 0.35);
}

.topbar-notification.has-unread .topbar-notification-toggle {
    border-color: rgba(255, 107, 157, 0.5);
}

.topbar-notification-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(360px, 92vw);
    max-height: 440px;
    background: #fff;
    border: 1px solid #e8e1f0;
    border-radius: 12px;
    box-shadow: 0 12px 28px rgba(53, 35, 83, 0.16);
    display: none;
    z-index: 1000;
    overflow: hidden;
}

.topbar-notification.open .topbar-notification-menu {
    display: block;
}

.topbar-notification-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid #f0e8f7;
    background: #faf7ff;
}

.topbar-notification-head-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.topbar-notification-head strong {
    font-size: 13px;
    color: #43344f;
}

.topbar-notification-summary {
    font-size: 11px;
    color: #7c6a8f;
}

.topbar-notification-sound-toggle {
    border: 1px solid #e8def3;
    background: #fff;
    color: #6c4f90;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 8px;
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 28px;
}

.topbar-notification-sound-toggle:hover {
    background: #faf7ff;
}

.topbar-notification-sound-label {
    font-size: 11px;
    color: #6c4f90;
}

.topbar-notification-switch {
    width: 34px;
    height: 18px;
    border-radius: 999px;
    background: #8e6ac7;
    position: relative;
    transition: background 0.18s ease;
}

.topbar-notification-switch-knob {
    position: absolute;
    top: 2px;
    left: 18px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: left 0.18s ease;
}

.topbar-notification-sound-toggle.is-off {
    border-color: #e8e3ef;
    background: #f7f6fa;
    color: #7b7387;
}

.topbar-notification-sound-toggle.is-off .topbar-notification-sound-label {
    color: #7b7387;
}

.topbar-notification-sound-toggle.is-off .topbar-notification-switch {
    background: #c9c3d4;
}

.topbar-notification-sound-toggle.is-off .topbar-notification-switch-knob {
    left: 2px;
}

.topbar-notification-list {
    max-height: 300px;
    overflow-y: auto;
}

.topbar-notification-empty {
    font-size: 12px;
    color: #8a7d96;
    padding: 14px;
    text-align: center;
}

.topbar-notification-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    text-decoration: none;
    color: #3f324c;
    padding: 11px 14px;
    border-bottom: 1px solid #f3edf8;
    transition: background 0.15s ease;
}

.topbar-notification-item:hover {
    background: #faf6ff;
}

.topbar-notification-item:last-child {
    border-bottom: none;
}

.topbar-notification-item-icon {
    width: 18px;
    text-align: center;
    line-height: 1.1;
}

.topbar-notification-item-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.topbar-notification-item-type {
    font-size: 11px;
    font-weight: 700;
    color: #7a5a9d;
}

.topbar-notification-item-msg {
    font-size: 12px;
    color: #4d3f59;
    line-height: 1.4;
}

.topbar-notification-foot {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #f0e8f7;
    background: #fcfaff;
}

.topbar-notification-foot a {
    text-decoration: none;
    font-size: 12px;
    font-weight: 700;
    color: #6f5291;
    background: #f2ebfb;
    border: 1px solid #e6daf5;
    border-radius: 8px;
    padding: 6px 9px;
}

.topbar-notification-foot a:hover {
    background: #ede2fa;
}

.user-name {
    color: var(--text-sub);
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--bg-page);
    border-radius: 20px;
    border: 1px solid var(--border);
}

.user-icon {
    font-size: 14px;
}

.logout-btn {
    padding: 7px 16px;
    background: var(--primary-gradient);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(196, 69, 105, 0.3);
    display: flex;
    align-items: center;
    gap: 5px;
}

.logout-btn:hover {
    box-shadow: 0 4px 12px rgba(196, 69, 105, 0.4);
    transform: translateY(-1px);
}

.logout-icon {
    font-size: 14px;
}

.admin-hub {
    position: relative;
}

.admin-hub-toggle {
    border: 1px solid #e4daf8;
    background: #f4efff;
    color: #553b8a;
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 13px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.admin-hub-toggle:hover {
    background: #efe8ff;
    transform: translateY(-1px);
}

.admin-hub-icon {
    font-size: 14px;
}

.admin-hub-text {
    line-height: 1;
}

.admin-hub-count {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #5b8dee;
    color: #fff;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.admin-hub-caret {
    font-size: 11px;
    color: #7356ac;
    line-height: 1;
}

.admin-hub-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 230px;
    max-width: 320px;
    max-height: 340px;
    overflow: auto;
    background: #fff;
    border: 1px solid #e8e1f0;
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(53, 35, 83, 0.16);
    padding: 6px;
    display: none;
    z-index: 1000;
}

.admin-hub.open .admin-hub-menu {
    display: block;
}

.admin-hub-item {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: #3f324c;
    font-size: 13px;
    border-radius: 8px;
    padding: 8px 9px;
    transition: background 0.15s ease;
}

.admin-hub-item:hover {
    background: #f6f3fb;
}

.admin-hub-item-icon {
    width: 16px;
    text-align: center;
    line-height: 1;
}

.admin-hub-item-label {
    line-height: 1.25;
}

/* 모바일 햄버거 버튼 */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    color: var(--text-sub);
    font-size: 20px;
    line-height: 1;
    transition: background 0.2s;
}

.sidebar-toggle:hover {
    background: var(--bg-page);
}

/* 앱 바디 (토바 아래) */
.app-shell {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* ============================================
   사이드바
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: #e4d8ef transparent;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

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

.sidebar::-webkit-scrollbar-thumb {
    background: #edd5e3;
    border-radius: 2px;
}

/* 사이드바 카테고리 섹션 */
.sidebar-section {
    padding: 16px 0 4px;
}

.sidebar-section:first-child {
    padding-top: 12px;
}

.sidebar-section:last-child {
    padding-bottom: 14px;
}

.sidebar-category-label {
    padding: 0 14px 5px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #c0b8d0;
}

/* 사이드바 메뉴 항목 */
.sidebar-item {
    list-style: none;
    padding: 0 8px;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 400;
    transition: background 0.15s, color 0.15s;
    position: relative;
    border-radius: 7px;
}

.sidebar-item a:hover {
    background: var(--sidebar-bg-hover);
    color: var(--primary-dark);
}

.sidebar-item.active a {
    background: var(--sidebar-bg-active);
    color: var(--sidebar-text-active);
    font-weight: 600;
}

.sidebar-item.active a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 60%;
    width: 3px;
    background: var(--sidebar-accent);
    border-radius: 0 2px 2px 0;
    left: -8px;
}

.sidebar-item-icon {
    font-size: 14px;
    flex-shrink: 0;
    width: 18px;
    text-align: center;
    opacity: 0.75;
}

.sidebar-item.active .sidebar-item-icon {
    opacity: 1;
}

.sidebar-item-text {
    flex: 1;
    line-height: 1.3;
}

.sidebar-item-badge {
    margin-left: 8px;
    min-width: 28px;
    height: 21px;
    padding: 0 8px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #ff8fb2 0%, #ff6f96 55%, #ff5f8a 100%);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, 0.72);
    box-shadow:
        0 3px 10px rgba(255, 95, 138, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.sidebar-item.has-pending > a {
    background: linear-gradient(180deg, #fff7fb 0%, #fff 100%);
}

.sidebar-item.has-pending .sidebar-item-icon {
    opacity: 1;
    transform: scale(1.04);
}

.sidebar-item.has-pending .sidebar-item-badge {
    animation: sidebarBadgePulse 1.6s ease-in-out infinite;
}

@keyframes sidebarBadgePulse {
    0% { transform: translateY(0) scale(1); box-shadow: 0 3px 10px rgba(255, 95, 138, 0.24); }
    50% { transform: translateY(-1px) scale(1.07); box-shadow: 0 6px 16px rgba(255, 95, 138, 0.38); }
    100% { transform: translateY(0) scale(1); box-shadow: 0 3px 10px rgba(255, 95, 138, 0.24); }
}

.sidebar-divider {
    height: 1px;
    background: #f0eaf5;
    margin: 6px 14px;
}

/* 사이드바 에러/로딩 */
.sidebar-error {
    padding: 20px 16px;
    color: #c0b8d0;
    font-size: 12px;
    text-align: center;
}

/* ============================================
   페이지 콘텐츠 영역
   ============================================ */
.page-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.mainwrap {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-page);
}

/* 페이지 타이틀 */
.page-header {
    margin-bottom: 20px;
}

.page-title,
.mainwrap > h1,
.mainwrap > h2:first-child {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.3px;
    margin-bottom: 4px;
}

/* ============================================
   공통 유틸리티
   ============================================ */
.loading-message,
.error-message,
.no-data,
.info-message {
    text-align: center;
    padding: 40px;
    color: var(--text-sub);
}

.error-message {
    background: #fff5f5;
    color: #c33;
    border: 1px solid #fcc;
    border-radius: 8px;
}

/* ============================================
   버튼 공통
   ============================================ */
.btn {
    padding: 9px 18px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary,
.btn-add,
.btn-save,
.btn-search {
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(196, 69, 105, 0.25);
    transition: all 0.2s ease;
}

.btn-primary:hover,
.btn-add:hover,
.btn-save:hover,
.btn-search:hover {
    box-shadow: 0 4px 12px rgba(196, 69, 105, 0.35);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: var(--bg-page);
    border-color: #c9ced6;
}

/* ============================================
   입력 필드 공통
   ============================================ */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="month"],
select,
textarea {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: 13px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    background: var(--surface);
    color: var(--text-main);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 107, 157, 0.12);
}

/* ============================================
   카드 / 섹션 래퍼
   ============================================ */
.card,
.section-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-card-hover);
}

/* ============================================
   테이블 공통
   ============================================ */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow-card);
}

table th,
table td {
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid #e9ecef;
}

table thead th,
table th {
    background: linear-gradient(180deg, #f8f9fa 0%, #eef1f4 100%);
    color: #343a40;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: -0.02em;
    border-bottom: 2px solid var(--primary-color);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

table thead th {
    white-space: nowrap;
}

table tbody th {
    background: #f8f9fa;
    color: #495057;
    font-weight: 600;
    border-bottom: 1px solid #e9ecef;
}

table tbody tr:hover {
    background: #f8f9fa;
}

/* 페이지 전용 테이블 클래스 헤더 통일 */
.dashboard-table thead th, .dashboard-table th,
.phoneauth-table thead th, .phoneauth-table th,
.payment-service-table thead th, .payment-service-table th,
.payment-account-table thead th, .payment-account-table th,
.payment-platform-table thead th, .payment-platform-table th,
.service-account-table thead th, .service-account-table th,
.domain-table thead th, .domain-table th,
.dns-table thead th, .dns-table th,
.carrier-table thead th, .carrier-table th,
.charge-table thead th, .charge-table th,
.platform-table thead th, .platform-table th,
.member-ranking-table thead th, .member-ranking-table th,
.settlement-table thead th, .settlement-table th,
.tbl.detail thead th,
.summary-table thead th, .summary-table th,
#dbStatusContainer table thead th, #dbStatusContainer table th {
    background: linear-gradient(180deg, #f8f9fa 0%, #eef1f4 100%);
    color: #343a40;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: -0.02em;
    border-bottom: 2px solid var(--primary-color);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

#dbStatusContainer table thead {
    background: transparent;
    color: inherit;
}

.settlement-table th {
    text-align: center;
}

.member-ranking-table thead th {
    white-space: nowrap;
}

/* ============================================
   반응형 (모바일)
   ============================================ */
@media (max-width: 768px) {
    body {
        overflow: auto; /* 모바일에서는 body 스크롤 허용 */
    }

    .app-shell {
        overflow: visible;
    }

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .topbar-left {
        width: auto;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: var(--topbar-height);
        bottom: 0;
        z-index: 300;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        top: var(--topbar-height);
        background: rgba(0,0,0,0.4);
        z-index: 299;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .page-content {
        overflow: visible;
    }

    .mainwrap {
        overflow: visible;
        padding: 16px;
    }

    .user-name {
        display: none;
    }

    .topbar-right {
        gap: 8px;
    }

    .topbar-notification-text {
        display: none;
    }

    .topbar-notification-toggle {
        min-width: 34px;
        justify-content: center;
        padding: 6px 8px;
    }

    .admin-hub-text {
        display: none;
    }

    .admin-hub-toggle {
        padding: 7px 8px;
    }
}

@media (max-width: 480px) {
    .mainwrap {
        padding: 12px;
    }

    .topbar-title {
        font-size: 14px;
    }

    .logout-btn span.logout-icon ~ span {
        display: none;
    }

    .admin-hub-caret,
    .admin-hub-count {
        display: none;
    }

    .admin-hub-menu {
        min-width: 210px;
        right: -4px;
    }

    .topbar-notification-menu {
        right: -46px;
        width: min(340px, 94vw);
    }
}
