/* ===== CSS Variables ===== */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --primary-bg: rgba(99, 102, 241, 0.1);

    --success: #10b981;
    --success-dark: #059669;
    --success-bg: rgba(16, 185, 129, 0.1);

    --danger: #ef4444;
    --danger-dark: #dc2626;
    --danger-bg: rgba(239, 68, 68, 0.1);

    --warning: #f59e0b;

    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-md:
        0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg:
        0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl:
        0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

    --radius-sm: 6px;
    --radius: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Dark Mode Variables ===== */
[data-theme="dark"] {
    --primary: #818cf8;
    --primary-dark: #6366f1;
    --primary-light: #a5b4fc;
    --primary-bg: rgba(129, 140, 248, 0.1);

    --success: #34d399;
    --success-dark: #10b981;
    --success-bg: rgba(52, 211, 153, 0.1);

    --danger: #f87171;
    --danger-dark: #ef4444;
    --danger-bg: rgba(248, 113, 113, 0.1);

    --warning: #fbbf24;

    --gray-50: #1f2937;
    --gray-100: #374151;
    --gray-200: #4b5563;
    --gray-300: #6b7280;
    --gray-400: #9ca3af;
    --gray-500: #d1d5db;
    --gray-600: #e5e7eb;
    --gray-700: #f3f4f6;
    --gray-800: #f9fafb;
    --gray-900: #ffffff;

    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --bg-tertiary: #374151;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.4), 0 1px 2px -1px rgba(0, 0, 0, 0.4);
    --shadow-md:
        0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg:
        0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
    --shadow-xl:
        0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
}

/* ===== Base Styles ===== */
body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family:
        "Pretendard",
        -apple-system,
        BlinkMacSystemFont,
        system-ui,
        Roboto,
        "Helvetica Neue",
        "Segoe UI",
        "Apple SD Gothic Neo",
        "Noto Sans KR",
        "Malgun Gothic",
        sans-serif;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--gray-800);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

input,
button,
select,
textarea {
    font-family: inherit;
}

/* ===== App Container ===== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: var(--bg-secondary);
    position: relative;
}

/* ===== Sidebar Styles ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 300px;
    height: 100%;
    background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
    z-index: 2000;
    transition: var(--transition-slow);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
}

/* Light mode sidebar */
:root:not([data-theme="dark"]) .sidebar {
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-right: 1px solid #e5e7eb;
}

:root:not([data-theme="dark"]) .sidebar-header {
    border-bottom: 1px solid #e5e7eb;
}

:root:not([data-theme="dark"]) .sidebar-nav li {
    color: #4b5563;
}

:root:not([data-theme="dark"]) .sidebar-nav li:hover {
    background: #f3f4f6;
    color: #1f2937;
}

:root:not([data-theme="dark"]) .sidebar-nav li.active {
    background: linear-gradient(
        90deg,
        rgba(99, 102, 241, 0.1) 0%,
        transparent 100%
    );
    color: #6366f1;
}

:root:not([data-theme="dark"]) .sidebar-nav .divider {
    background: #e5e7eb;
}

:root:not([data-theme="dark"]) .sidebar .icon-btn {
    color: #6b7280;
}

:root:not([data-theme="dark"]) .sidebar .icon-btn:hover {
    background: #f3f4f6;
    color: #6366f1;
}

.sidebar.active {
    left: 0;
}

.sidebar-header {
    padding: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header .logo {
    font-size: 1.25rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-light) 0%, #a78bfa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.sidebar-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-nav li {
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 15px;
    color: var(--gray-400);
    cursor: pointer;
    transition: var(--transition);
    border-left: 3px solid transparent;
    margin: 2px 0;
}

.sidebar-nav li i {
    width: 20px;
    font-size: 18px;
    text-align: center;
}

.sidebar-nav li:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--gray-100);
    border-left-color: var(--primary-light);
}

.sidebar-nav li.active {
    background: linear-gradient(
        90deg,
        rgba(99, 102, 241, 0.2) 0%,
        transparent 100%
    );
    color: var(--primary-light);
    font-weight: 600;
    border-left-color: var(--primary-light);
}

.sidebar-nav .divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 12px 24px;
    padding: 0;
    border: none;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1500;
    display: none;
    opacity: 0;
    transition: var(--transition);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ===== Top Bar ===== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    height: 70px;
    background: var(--bg-primary);
    box-shadow: var(--shadow);
    z-index: 1100;
    border-bottom: 1px solid var(--gray-100);
}

.search-area {
    display: flex;
    align-items: center;
    gap: 16px;
}

.top-left-group {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* ===== Icon Button ===== */
.icon-btn {
    background: transparent;
    border: none;
    padding: 10px;
    cursor: pointer;
    color: var(--gray-500);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--gray-100);
    color: var(--primary);
}

.sidebar .icon-btn {
    color: var(--gray-400);
}

.sidebar .icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--gray-100);
}

/* ===== Input Group ===== */
.input-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.input-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-600);
    white-space: nowrap;
    letter-spacing: -0.2px;
}

.input-group input {
    padding: 10px 14px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--gray-800);
    background: var(--bg-primary);
    transition: var(--transition);
    outline: none;
}

.input-group input::placeholder {
    color: var(--gray-400);
}

.input-group input[type="date"] {
    position: relative;
    min-width: 140px;
    cursor: pointer;
}

.input-group input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    padding: 4px;
    filter: invert(0.5);
    transition: var(--transition);
}

.input-group input[type="date"]:hover::-webkit-calendar-picker-indicator {
    filter: invert(0.3);
}

.input-group input:hover {
    border-color: var(--gray-300);
}

.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-bg);
}

/* ===== Buttons ===== */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius);
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.2px;
}

.btn-primary {
    background: linear-gradient(
        135deg,
        var(--primary) 0%,
        var(--primary-dark) 100%
    );
    color: white;
    border: none;
    box-shadow: 0 4px 14px 0 rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    background: var(--gray-50);
    color: var(--gray-800);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.btn-secondary:active {
    transform: translateY(0);
}

.btn-danger {
    background: linear-gradient(
        135deg,
        var(--danger) 0%,
        var(--danger-dark) 100%
    );
    color: white;
    border: none;
    box-shadow: 0 4px 14px 0 rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #f87171 0%, var(--danger) 100%);
    box-shadow: 0 6px 20px 0 rgba(239, 68, 68, 0.4);
    transform: translateY(-2px);
}

.btn-danger:active {
    transform: translateY(0);
}

/* ===== Login Button ===== */
.login-btn {
    padding: 3px 9px;
    color: #818181;
    border: none;
    background: none;
    cursor: pointer;
}

.login-btn:hover {
    transform: translateY(-1px);
    /*box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);*/
}

.login-btn:active {
    transform: translateY(0);
}

.login-btn i {
    font-size: 16px;
}

.login-btn.hidden {
    display: none;
}

/* ===== Profile Area ===== */
.profile-container {
    position: relative;
}

.profile-container.hidden {
    display: none;
}

.profile-img {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid var(--gray-100);
    transition: var(--transition);
    object-fit: cover;
    margin-left: 11px;
}

.profile-img:hover {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 4px var(--primary-bg);
}

.user-dropdown {
    position: absolute;
    top: 56px;
    right: 0;
    width: 200px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    display: none;
    z-index: 1000;
    border: 1px solid var(--gray-100);
    overflow: hidden;
}

.user-dropdown.active {
    display: block;
    animation: dropdownFadeIn 0.2s ease;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--gray-100);
    background: linear-gradient(
        135deg,
        var(--gray-50) 0%,
        var(--bg-primary) 100%
    );
}

.user-info-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--primary-light);
}

.user-info-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-800);
}

.user-email {
    font-size: 12px;
    color: var(--gray-500);
}

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

.user-dropdown ul {
    list-style: none;
    margin: 0;
    padding: 8px;
}

.user-dropdown li {
    padding: 12px 16px;
    font-size: 14px;
    color: var(--gray-700);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.user-dropdown li i {
    width: 18px;
    color: var(--gray-500);
}

.user-dropdown li:hover {
    background: var(--gray-50);
    color: var(--primary);
}

.user-dropdown li:hover i {
    color: var(--primary);
}

.user-dropdown .divider {
    height: 1px;
    background: var(--gray-100);
    margin: 8px 0;
    padding: 0;
}

/* ===== Bottom Bar ===== */
.bottom-bar {
    min-height: 90px;
    background: var(--bg-primary);
    border-top: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 40px;
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease;
}

/* ===== Mobile Trading Panel Toggle Button ===== */
.mobile-trade-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: linear-gradient(
        135deg,
        var(--primary) 0%,
        var(--primary-dark) 100%
    );
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 999;
    transition: all 0.3s ease;
}

.mobile-trade-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.mobile-trade-toggle:active {
    transform: scale(0.95);
}

/* ===== Trade Panel Overlay ===== */
.trade-panel-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.trade-panel-overlay.active {
    opacity: 1;
}

/* ===== Mobile Panel Close Button ===== */
.mobile-panel-close {
    display: none;
    position: absolute;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    background: var(--gray-100);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--gray-600);
    font-size: 18px;
    transition: all 0.2s ease;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.mobile-panel-close:hover {
    background: var(--gray-200);
    color: var(--gray-800);
}

.mobile-panel-close:active {
    transform: scale(0.9);
}

.trade-controls {
    display: flex;
    align-items: center;
    gap: 20px;
    padding-right: 40px;
    border-right: 2px solid var(--gray-100);
}

.btn-group {
    display: flex;
    gap: 10px;
}

.btn-buy {
    background: linear-gradient(
        135deg,
        var(--danger) 0%,
        var(--danger-dark) 100%
    );
    color: white;
    box-shadow: 0 4px 14px 0 rgba(239, 68, 68, 0.3);
    min-width: 80px;
    justify-content: center;
}

.btn-buy:hover {
    background: linear-gradient(135deg, #f87171 0%, var(--danger) 100%);
    box-shadow: 0 6px 20px 0 rgba(239, 68, 68, 0.4);
    transform: translateY(-2px);
}

.btn-buy:active {
    transform: translateY(0);
}

.btn-sell {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(59, 130, 246, 0.3);
    min-width: 80px;
    justify-content: center;
}

.btn-sell:hover {
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
    box-shadow: 0 6px 20px 0 rgba(59, 130, 246, 0.4);
    transform: translateY(-2px);
}

.btn-sell:active {
    transform: translateY(0);
}

.trade-info {
    display: flex;
    gap: 36px;
    flex: 1;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 100px;
}

.info-item .label {
    font-size: 12px;
    color: var(--gray-500);
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    text-align: right;
}

.info-item .value {
    font-size: 18px;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.5px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.highlight-up {
    color: var(--danger) !important;
}

.highlight-down {
    color: #3b82f6 !important;
}

.date-navigation {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.date-navigation .btn {
    min-width: 100px;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    .main-content {
        padding-bottom: 0;
    }

    .top-bar {
        height: auto;
        padding: 12px 16px;
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .top-left-group {
        width: 100%;
        gap: 12px;
    }

    .menu-btn {
        position: absolute;
        top: 12px;
        left: 16px;
    }

    .search-area {
        width: 100%;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
        padding-top: 44px;
    }

    .input-group input {
        width: 100px;
        padding: 8px 10px;
    }

    .autocomplete-wrapper {
        width: clamp(50px, 24vw, 100px);
        min-width: 50px;
        max-width: 100px;
        flex: 0 1 100px;
    }

    .autocomplete-wrapper input {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    .user-area {
        position: absolute;
        top: 12px;
        right: 16px;
    }

    /* 모바일 매매 패널 토글 버튼 숨김 */
    .mobile-trade-toggle {
        display: none;
    }

    /* 모바일 오버레이 숨김 */
    .trade-panel-overlay {
        display: none;
    }

    /* 모바일에서 bottom-bar를 보유종목 패널 하단으로 이동 */
    .bottom-bar {
        display: none; /* 기본적으로 숨김, holdings-panel에 통합됨 */
    }

    /* 모바일에서 닫기 버튼 숨김 */
    .mobile-panel-close {
        display: none;
    }

    .user-dropdown {
        right: 0;
        left: auto;
    }
}

@media (max-width: 480px) {
    .search-area .input-group label {
        display: none;
    }

    .input-group input {
        width: 100%;
    }

    .trade-controls {
        flex-wrap: wrap;
        gap: 10px;
    }

    .trade-controls .input-group {
        flex: 1 1 calc(50% - 5px);
        min-width: calc(50% - 5px);
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .trade-controls .input-group input {
        width: 100%;
        font-size: 14px;
        padding: 10px;
    }

    .trade-controls .btn-group {
        width: 100%;
        margin-top: 4px;
        gap: 8px;
    }

    .trade-controls .btn-group .btn {
        font-size: 15px;
        padding: 12px;
    }

    .trade-controls .input-group label {
        font-size: 11px;
        font-weight: 600;
    }

    .info-item {
        padding: 12px;
    }

    .info-item .label {
        font-size: 11px;
    }

    .info-item .value {
        font-size: 16px;
    }

    .bottom-bar {
        width: 320px;
        max-width: 95vw;
        padding: 60px 16px 16px 16px;
        gap: 16px;
    }

    .mobile-trade-toggle {
        width: 52px;
        height: 52px;
        font-size: 20px;
    }
}

/* ===== Chart Container ===== */
#chartContainer {
    padding: 10px;
    flex: 1;
    width: 100%;
    position: relative;
    overflow: hidden;
    background-color: var(--bg-primary);
    display: flex;
    flex-direction: column;
}

#myCanvas {
    background-color: var(--bg-primary);
    cursor: crosshair;
    flex: 1;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: none;
}

#myCanvas.select-mode {
    cursor: default;
}

#labelContainer {
    display: flex;
    align-items: stretch;
    justify-content: center;
    background-color: var(--bg-primary);
    border-left: 1px solid var(--gray-200);
}

#labelCanvas {
    height: 100%;
    background-color: var(--bg-primary);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: none;
    cursor: ns-resize;
}

/* 설정 팝업 포커스 시 ESC로 닫기 — 포커스 아웃라인 숨김 */
.chart-config-panel:focus,
.drawing-tools-settings-panel:focus,
.drawing-layer-panel:focus {
    outline: none;
}

/* 그리기 도구 SVG 아이콘 (SVG 파일을 mask로 사용 → 버튼 글자색(currentColor)을 따라감) */
.drawing-svg-icon {
    display: inline-block;
    width: 18px;
    height: 18px;
    background-color: currentColor;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
}

.drawing-svg-icon.icon-rate-of-change {
    -webkit-mask-image: url("/img/rate-of-change.svg");
    mask-image: url("/img/rate-of-change.svg");
}

.drawing-svg-icon.icon-candle-count {
    -webkit-mask-image: url("/img/candle-count.svg");
    mask-image: url("/img/candle-count.svg");
}

/* 우측 가격 범위 상태 */
.price-range-status {
    position: absolute;
    top: 35px;
    right: 5px;
    z-index: 11;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 55px;
    max-width: 55px;
    padding: 5px 7px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--gray-600);
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    user-select: none;
}

.price-range-status.manual {
    color: var(--warning);
    border-color: var(--warning);
}

.price-range-status button {
    padding: 3px 7px;
    border: 0;
    border-radius: 3px;
    color: white;
    background: var(--primary);
    font-size: 9px;
    font-weight: 600;
    cursor: pointer;
}

.price-range-status button:hover {
    filter: brightness(1.1);
}

.price-range-status button[hidden] {
    display: none;
}

[data-theme="dark"] .price-range-status {
    color: var(--gray-700);
    background: rgba(17, 24, 39, 0.88);
    border-color: var(--gray-500);
}

[data-theme="dark"] .price-range-status.manual {
    color: var(--warning);
    border-color: var(--warning);
}

/* ===== Chart Layout ===== */
.chart-area {
    display: flex;
    flex: 1;
    min-height: 0;
}

.date-container {
    display: flex;
    height: 30px;
    box-sizing: border-box;
    background-color: var(--bg-primary);
    border-top: 1px solid var(--gray-200);
}

#dateCanvas {
    flex: 1;
    background-color: var(--bg-primary);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: none;
}

.date-corner {
    width: 70px;
    background-color: var(--bg-primary);
    border-left: 1px solid var(--gray-200);
}

.tooltip {
    position: fixed;
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    padding: 10px 12px;
    display: none;
    pointer-events: none;
    font-size: 12px;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius);
    z-index: 2000;
}

.selection-overlay {
    position: absolute;
    background: linear-gradient(
        135deg,
        rgba(124, 58, 237, 0.08) 0%,
        rgba(99, 102, 241, 0.08) 100%
    );
    border: 2px solid rgba(124, 58, 237, 0.3);
    pointer-events: none;
    display: none;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.15);
}

.selection-date-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(
        135deg,
        rgba(124, 58, 237, 0.95) 0%,
        rgba(99, 102, 241, 0.95) 100%
    );
    color: #ffffff;
    padding: 10px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.15),
        0 4px 8px rgba(0, 0, 0, 0.1);
    z-index: 10;
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    letter-spacing: 0.3px;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* ===== Loading Overlay ===== */
.chart-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.chart-loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 14px;
    border-radius: 10px;
    background: #a6b4e126;
}
[data-theme="dark"] .chart-loading-content {
    background: #a6b4e100;
}

.chart-loading-spinner {
    position: relative;
    width: 60px;
    height: 60px;
}

.chart-spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid transparent;
    animation: chart-spin 1.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
}

.chart-spinner-ring:nth-child(1) {
    border-top-color: var(--primary);
    animation-delay: 0s;
}

.chart-spinner-ring:nth-child(2) {
    width: 44px;
    height: 44px;
    top: 8px;
    left: 8px;
    border-right-color: var(--primary-light);
    animation-delay: 0.15s;
    animation-direction: reverse;
}

.chart-spinner-ring:nth-child(3) {
    width: 28px;
    height: 28px;
    top: 16px;
    left: 16px;
    border-bottom-color: var(--primary-dark);
    animation-delay: 0.3s;
}

@keyframes chart-spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.chart-loading-text {
    display: none;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-600);
    letter-spacing: -0.3px;
    animation: chart-pulse-text 1.5s ease-in-out infinite;
}

@keyframes chart-pulse-text {
    0%,
    100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

.chart-loading-bar {
    display: none;
    width: 150px;
    height: 4px;
    background: var(--gray-200);
    border-radius: 2px;
    overflow: hidden;
}

.chart-loading-bar-fill {
    height: 100%;
    width: 30%;
    background: linear-gradient(
        90deg,
        var(--primary) 0%,
        var(--primary-light) 50%,
        var(--primary) 100%
    );
    background-size: 200% 100%;
    border-radius: 2px;
    animation: chart-loading-slide 1.2s ease-in-out infinite;
}

@keyframes chart-loading-slide {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(400%);
    }
}

/* Dark mode support for chart loading */
[data-theme="dark"] .chart-loading-overlay {
    background: transparent;
}

[data-theme="dark"] .chart-loading-text {
    color: var(--gray-400);
}

[data-theme="dark"] .chart-loading-bar {
    background: var(--gray-700);
}

/* ===== No Data Message ===== */
.chart-no-data-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-tertiary);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 900;
}

.chart-no-data-overlay i {
    font-size: 56px;
    color: var(--gray-300);
    margin-bottom: 16px;
}

.chart-no-data-overlay span {
    color: var(--gray-500);
    font-size: 16px;
    font-weight: 600;
}

/* ===== Previous Data Button ===== */
.get-data-btn {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 800;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-primary);
    /*border: 2px solid var(--primary);*/
    border: none;
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    box-shadow: var(--shadow-md);
}

.get-data-btn:hover {
    /*background: var(--primary);*/
    border: 2px solid var(--primary);
    /*color: white;*/
    box-shadow: var(--shadow-lg);
    transform: translateY(-50%) scale(1.1);
}

.get-data-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.get-data-btn i {
    font-size: 18px;
}

/* ===== Line Legend ===== */
.line-legend {
    position: absolute;
    top: 59px;
    left: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 100;
}

.line-legend-add {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    /*background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);*/
    color: var(--gray-600);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    /*box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);*/
    user-select: none;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
}

.line-legend-add:hover {
    transform: translateY(-1px);
    color: var(--primary);
    /*box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);*/
}

.line-legend-add:active {
    transform: translateY(0);
}

.line-legend-add i {
    font-size: 10px;
}

.line-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow);
    user-select: none;
    opacity: 0.8;
}

.line-legend-item:hover {
    background: var(--bg-secondary);
    box-shadow: var(--shadow-md);
}

.line-legend-item.disabled {
    opacity: 0.5;
}

.line-legend-item.disabled .line-legend-color {
    background-color: var(--gray-400) !important;
}

.line-legend-item.disabled .line-legend-label {
    text-decoration: line-through;
    color: var(--gray-400);
}

.line-legend-color {
    width: 20px;
    height: 3px;
    border-radius: 2px;
    flex-shrink: 0;
}

.line-legend-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-800);
}

.line-legend-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.line-legend-settings {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: var(--gray-400);
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.2s ease;
    margin-left: 4px;
}

.line-legend-settings:hover {
    color: var(--gray-800);
    background: var(--gray-100);
}

.line-legend-settings i {
    font-size: 11px;
}

.line-legend-buttons {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
}

.line-legend-delete {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    color: var(--gray-400);
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.line-legend-delete:hover {
    color: var(--danger);
    background: var(--danger-bg);
}

.line-legend-delete i {
    font-size: 10px;
}

/* ===== Line Settings Popup ===== */
.line-settings-overlay {
    display: none !important;
}

.line-settings-body {
    padding: 16px;
    background: var(--bg-primary);
}

.line-settings-row {
    margin-bottom: 14px;
}

.line-settings-row:last-child {
    margin-bottom: 0;
}

.line-settings-row label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 6px;
}

.line-settings-row input {
    width: calc(100% - 27px);
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--gray-800);
    transition:
        border-color 0.2s,
        box-shadow 0.2s;
}

.line-settings-row input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

.line-settings-row input:disabled {
    background: var(--gray-100);
    color: var(--gray-500);
    cursor: not-allowed;
    opacity: 0.7;
}

.line-settings-key-display {
    width: calc(100% - 27px);
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    background: var(--gray-100);
    color: var(--gray-600);
    font-family: "Consolas", "Monaco", "Courier New", monospace;
    user-select: text;
    cursor: default;
}

.line-settings-row input[type="color"] {
    width: 50px;
    height: 36px;
    padding: 2px;
    cursor: pointer;
}

.color-input-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-hex-input {
    width: 100px !important;
    padding: 8px 10px !important;
    font-size: 15px !important;
    font-family: "Consolas", "Monaco", "Courier New", monospace;
    text-align: center;
    background: var(--bg-primary) !important;
    color: var(--gray-800) !important;
    border: 1px solid var(--gray-300) !important;
    border-radius: 6px;
    cursor: text;
    transition: var(--transition);
}

.color-hex-input:focus {
    outline: none;
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px var(--primary-bg);
}

.line-settings-row select {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--gray-800);
    cursor: pointer;
    transition:
        border-color 0.2s,
        box-shadow 0.2s;
}

.line-settings-row select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

.line-settings-row select:disabled {
    background: var(--gray-100);
    color: var(--gray-500);
    cursor: not-allowed;
    opacity: 0.7;
}

.line-settings-divider {
    height: 1px;
    background: var(--gray-200);
    margin: 16px 0;
}

.line-settings-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 12px;
}

.line-settings-footer {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--gray-200);
}

.line-settings-footer button {
    flex: 1;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.line-settings-apply {
    background: var(--primary);
    color: white;
    border: none;
}

.line-settings-apply:hover {
    background: var(--primary-dark);
}

.line-settings-cancel {
    background: var(--bg-primary);
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
}

.line-settings-cancel:hover {
    background: var(--gray-50);
}

/* ===== Dark Mode Toggle Button ===== */
.dark-mode-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: var(--gray-600);
    font-size: 16px;
    box-shadow: var(--shadow-sm);
}

.dark-mode-toggle:hover {
    background: var(--gray-50);
    color: var(--primary);
    box-shadow: var(--shadow);
    transform: scale(1.05);
}

.dark-mode-toggle i {
    transition: transform 0.3s ease;
}

.dark-mode-toggle:active i {
    transform: rotate(20deg);
}

/* ===== Fullscreen Toggle Button ===== */
.fullscreen-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: var(--gray-600);
    font-size: 16px;
    box-shadow: var(--shadow-sm);
    margin-right: 8px;
}

.fullscreen-toggle:hover {
    background: var(--gray-50);
    color: var(--primary);
    box-shadow: var(--shadow);
    transform: scale(1.05);
}

.fullscreen-toggle i {
    transition: transform 0.3s ease;
}

.fullscreen-toggle:active i {
    transform: scale(1.2);
}

/* ===== Period Toggle (일/주/월) ===== */
.period-toggle {
    position: absolute;
    top: 6px;
    left: 192px;
    background: var(--bg-secondary);
    padding: 5px;
    border-radius: 5px;
    box-shadow: var(--shadow);
    display: flex;
    scale: 1;
    border: 1px solid var(--gray-200);
    margin-right: 4px;
    height: 38px;
    box-sizing: border-box;
    align-items: center;
}

.period-toggle button {
    margin: 0 2px;
    padding: 4px 10px;
    cursor: pointer;
    border: none;
    border-radius: 3px;
    background: var(--bg-primary);
    color: var(--gray-800);
    transition: all 0.2s ease;
    font-weight: 600;
    font-size: 13px;
    height: 100%;
}

.period-toggle button:hover {
    background: var(--gray-100);
}

.period-toggle button.active {
    background: var(--gray-200);
}

[data-theme="dark"] .period-toggle {
    background: var(--bg-secondary);
    border-color: var(--gray-200);
}

[data-theme="dark"] .period-toggle button {
    background: var(--bg-tertiary);
    color: var(--gray-800);
}

[data-theme="dark"] .period-toggle button:hover {
    background: var(--gray-100);
}

[data-theme="dark"] .period-toggle button.active {
    background: var(--primary-bg) !important;
    color: var(--primary) !important;
    border-color: var(--primary) !important;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.mode-toggle {
    position: absolute;
    top: 6px;
    left: 10px;
    background: var(--bg-secondary);
    padding: 5px;
    border-radius: 5px;
    box-shadow: var(--shadow);
    display: flex;
    scale: 1;
    border: 1px solid var(--gray-200);
    height: 38px;
    box-sizing: border-box;
    align-items: center;
}

.mode-toggle button {
    margin: 0 5px;
    padding: 4px 10px;
    cursor: pointer;
    border: none;
    border-radius: 3px;
    background: var(--bg-primary);
    color: var(--gray-800);
    transition: all 0.2s ease;
    height: 100%;
}

.mode-toggle button:hover {
    background: var(--gray-100);
}

.mode-toggle button.active {
    background: var(--gray-200);
}

.mode-toggle input[type="number"] {
    width: 60px;
    margin: 0 5px;
    padding: 5px;
    border-radius: 3px;
    border: 1px solid var(--gray-300);
    background: var(--bg-primary);
    color: var(--gray-800);
    outline: none;
}

/* ===== Dark Mode Overrides for Chart Controls ===== */
[data-theme="dark"] .mode-toggle,
[data-theme="dark"] .drawing-tools {
    background: var(--bg-secondary);
    border-color: var(--gray-200);
}

[data-theme="dark"] .mode-toggle button,
[data-theme="dark"] .drawing-tools button {
    background: var(--bg-tertiary);
    color: #e5e7eb;
    border-color: var(--gray-100);
}

[data-theme="dark"] .mode-toggle button:hover,
[data-theme="dark"] .drawing-tools button:hover {
    background: var(--gray-100);
    color: #ffffff;
}

[data-theme="dark"] .mode-toggle button.active,
[data-theme="dark"] .drawing-toggle-btn.active,
[data-theme="dark"] .drawing-tools button.active {
    background: var(--primary-bg) !important;
    color: var(--primary) !important;
    border-color: var(--primary) !important;
}

[data-theme="dark"] .mode-toggle input[type="number"] {
    background: var(--bg-tertiary);
    /*color: var(--gray-300);*/
    border-color: var(--gray-200);
}

/* Number input spinner buttons - 다크모드 스타일링 */
.mode-toggle input[type="number"]::-webkit-inner-spin-button,
.mode-toggle input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
    background: transparent;
    cursor: pointer;
}

[data-theme="dark"]
    .mode-toggle
    input[type="number"]::-webkit-inner-spin-button,
[data-theme="dark"]
    .mode-toggle
    input[type="number"]::-webkit-outer-spin-button {
    background: transparent; /* 배경 제거 */
    border: none;
    box-shadow: none;
    filter: invert(0.8); /* 아이콘 색 반전 */
    opacity: 1; /* 흐려지지 않게 */
}

[data-theme="dark"] .drawing-tools {
    background: var(--bg-primary);
    border-color: var(--gray-200);
}

[data-theme="dark"] .drawing-tools-divider {
    background: var(--gray-200);
}

[data-theme="dark"] .drawing-toggle-btn:hover {
    background: var(--bg-tertiary) !important;
}

[data-theme="dark"] .drawing-count-badge {
    background: var(--danger);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    opacity: 0.8;
}

/* ===== Dark Mode Selection Overlay ===== */
[data-theme="dark"] .selection-overlay {
    background: linear-gradient(
        135deg,
        rgba(129, 140, 248, 0.12) 0%,
        rgba(99, 102, 241, 0.12) 100%
    );
    border: 2px solid rgba(129, 140, 248, 0.4);
    box-shadow: 0 4px 12px rgba(129, 140, 248, 0.2);
}

[data-theme="dark"] .selection-date-label {
    background: linear-gradient(
        135deg,
        rgba(129, 140, 248, 0.95) 0%,
        rgba(99, 102, 241, 0.95) 100%
    );
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.3),
        0 4px 8px rgba(0, 0, 0, 0.2);
}

/* ===== Chart Config Panel ===== */
.chart-config-panel {
    position: absolute;
    top: 44px;
    right: 6px;
    z-index: 2000;
    width: 260px;
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    max-height: 70vh;
    overflow: hidden;
}
.cfg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px 8px;
    border-bottom: 1px solid var(--gray-200);
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-800);
    flex-shrink: 0;
    cursor: move;
    user-select: none;
}
.cfg-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    color: var(--gray-400);
    padding: 0 2px;
}
.cfg-close:hover {
    color: var(--gray-700);
}
.cfg-body {
    overflow-y: auto;
    padding: 6px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-300) transparent;
}
.cfg-body::-webkit-scrollbar {
    width: 4px;
}
.cfg-body::-webkit-scrollbar-track {
    background: transparent;
    margin: 4px 0;
}
.cfg-body::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 10px;
}
.cfg-body::-webkit-scrollbar-thumb:hover {
    background: var(--primary-light);
}
[data-theme="dark"] .cfg-body {
    scrollbar-color: var(--gray-600) transparent;
}
[data-theme="dark"] .cfg-body::-webkit-scrollbar-thumb {
    background: var(--gray-600);
}
[data-theme="dark"] .cfg-body::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}
.cfg-section {
    margin-bottom: 2px;
}
.cfg-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--gray-700);
    letter-spacing: 0.01em;
    padding: 8px 12px 7px;
    background: var(--bg-secondary);
    border-top: 2px solid var(--gray-200);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 6px;
}
.cfg-section-title::before {
    content: "";
    display: inline-block;
    width: 3px;
    height: 13px;
    background: var(--primary);
    border-radius: 2px;
    flex-shrink: 0;
}
.cfg-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 12px;
    gap: 8px;
}
.cfg-row label {
    font-size: 12px;
    color: var(--gray-700);
    flex: 1;
    cursor: default;
}
.cfg-row-color {
    gap: 6px;
}
.cfg-row-color label {
    flex: 1;
    min-width: 0;
}
.cfg-color-picker {
    width: 28px;
    height: 24px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    cursor: pointer;
    padding: 1px;
    background: none;
    flex-shrink: 0;
}
.cfg-color-hex {
    width: 72px;
    flex-shrink: 0;
    padding: 2px 5px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 11px;
    font-family: monospace;
    text-align: center;
    color: var(--gray-800);
    background: var(--bg-primary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: border-color 0.15s;
}
.cfg-color-hex:focus {
    outline: none;
    border-color: var(--primary);
}
[data-theme="dark"] .cfg-color-hex {
    background: var(--bg-secondary);
    border-color: var(--gray-600);
    color: var(--gray-400);
}
.cfg-number {
    width: 56px;
    padding: 2px 4px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 12px;
    text-align: right;
    color: var(--gray-800);
    background: var(--bg-primary);
}
.cfg-number:focus {
    outline: none;
    border-color: var(--primary);
}

/* 불투명도 슬라이더 행 */
.cfg-row-opacity {
    flex-wrap: nowrap;
    gap: 6px;
}
.cfg-row-opacity label {
    min-width: 72px;
    flex-shrink: 0;
}
.cfg-slider {
    flex: 1;
    min-width: 0;
    height: 4px;
    accent-color: var(--primary);
    cursor: pointer;
    border-radius: 2px;
    appearance: auto;
}
.cfg-opacity-num {
    width: 46px;
    flex-shrink: 0;
}
.cfg-toggle {
    width: 36px;
    height: 20px;
    appearance: none;
    background: var(--gray-300);
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}
.cfg-toggle:checked {
    background: var(--primary);
}
.cfg-toggle::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}
.cfg-toggle:checked::before {
    transform: translateX(16px);
}
.cfg-select {
    font-size: 12px;
    padding: 2px 4px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--gray-800);
    cursor: pointer;
}
.cfg-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
}
.cfg-reset-btn {
    width: 100%;
    padding: 6px;
    font-size: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    cursor: pointer;
    color: var(--gray-600);
}
.cfg-reset-btn:hover {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger);
}

/* Dark mode - config panel */
[data-theme="dark"] .chart-config-panel {
    background: var(--bg-primary);
    border-color: var(--gray-100);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
[data-theme="dark"] .cfg-header {
    border-color: var(--gray-100);
    color: var(--gray-400);
    background: var(--gray-50);
}
[data-theme="dark"] .cfg-close {
    color: var(--gray-500);
}
[data-theme="dark"] .cfg-close:hover {
    color: var(--gray-200);
}
[data-theme="dark"] .cfg-section-title {
    background: #1a1f2e;
    border-color: var(--gray-100);
    color: var(--gray-600);
}
[data-theme="dark"] .cfg-row label {
    color: var(--gray-400);
}
[data-theme="dark"] .cfg-number {
    background: var(--bg-secondary);
    border-color: var(--gray-600);
    color: var(--gray-400);
}
[data-theme="dark"] .cfg-select {
    background: var(--bg-secondary);
    border-color: var(--gray-600);
    color: var(--gray-400);
}
[data-theme="dark"] .cfg-footer {
    border-color: var(--gray-100);
}
[data-theme="dark"] .cfg-reset-btn {
    background: var(--bg-secondary);
    border-color: var(--gray-600);
    color: var(--gray-400);
}

/* ===== Chart Context Menu ===== */
.chart-context-menu {
    position: absolute;
    z-index: 3000;
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    min-width: 180px;
    padding: 4px 0;
    user-select: none;
}
.ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 14px;
    background: none;
    border: none;
    text-align: left;
    font-size: 13px;
    color: var(--gray-700);
    cursor: pointer;
    transition: background 0.1s;
}
.ctx-item i {
    width: 14px;
    text-align: center;
    color: var(--gray-400);
}
.ctx-item:hover:not(.disabled) {
    background: var(--primary-bg);
    color: var(--primary);
}
.ctx-item:hover:not(.disabled) i {
    color: var(--primary);
}
.ctx-item.disabled {
    color: var(--gray-300);
    cursor: default;
}
.ctx-separator {
    height: 1px;
    background: var(--gray-100);
    margin: 3px 0;
}
[data-theme="dark"] .chart-context-menu {
    background: var(--bg-primary);
    border-color: var(--gray-100);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
[data-theme="dark"] .ctx-item {
    color: var(--gray-400);
}
[data-theme="dark"] .ctx-item i {
    color: var(--gray-500);
}
[data-theme="dark"] .ctx-item:hover:not(.disabled) {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary-light);
}
[data-theme="dark"] .ctx-item:hover:not(.disabled) i {
    color: var(--primary-light);
}
[data-theme="dark"] .ctx-item.disabled {
    color: var(--gray-600);
}
[data-theme="dark"] .ctx-separator {
    background: var(--gray-100);
}

/* ===== Drawing Toggle Button ===== */
.drawing-toggle-btn {
    position: absolute;
    top: 6px;
    left: 321px;
    z-index: 1000;
    padding: 0 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    cursor: pointer;
    color: var(--gray-600);
    font-size: 16px;
    min-width: 38px;
    height: 38px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.drawing-toggle-btn:hover {
    background: var(--gray-100) !important;
    border-color: var(--primary) !important;
    color: var(--primary) !important;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.drawing-toggle-btn.active {
    background: var(--primary-bg) !important;
    border-color: var(--primary) !important;
    color: var(--primary) !important;
    box-shadow: var(--shadow);
}

.drawing-toggle-btn i {
    font-size: 14px;
}

/* Automatic market structure overlays */
.drawing-tools .ict-tool-button {
    min-width: 44px;
    width: auto;
    padding: 0 6px;
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
}
.ict-settings {
    position: fixed;
    z-index: 2200;
    width: min(300px, calc(100vw - 16px));
    box-sizing: border-box;
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg-primary);
    color: var(--gray-800);
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    box-shadow: 0 6px 24px #0003;
}
.ict-settings label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 12px;
}
.ict-settings input:not([type="checkbox"]) { width: 65px; }
.ict-settings p { padding: 0 12px; font-size: 12px; line-height: 1.6; }
.ict-settings .ict-diagnostic { margin: 0; padding: 10px 12px; border-top: 1px solid var(--gray-200); color: var(--gray-600); }
.ict-settings .ict-diagnostic.error { color: #b42318; background: #fff1f0; font-weight: 600; }
.ict-menu-header { display:flex; align-items:center; justify-content:space-between; padding:10px 12px; font-size:13px; font-weight:600; }
.ict-menu-header button { border:0; background:transparent; color:inherit; font-size:20px; cursor:pointer; }
.ict-toggle-grid { display:grid; grid-template-columns:1fr 1fr; gap:8px; padding:0 12px 12px; }
.ict-type-toggle { display:flex; flex-direction:column; align-items:center; gap:3px; padding:10px; border:1px solid var(--gray-300); border-radius:6px; background:var(--bg-primary); color:var(--gray-600); cursor:pointer; }
.ict-type-toggle span { font-size:11px; }
.ict-type-toggle[aria-pressed="true"] { background:var(--primary-bg); border-color:var(--primary); color:var(--primary); box-shadow:inset 0 0 0 1px var(--primary); }
.ict-type-toggle:focus-visible, .ict-menu-header button:focus-visible { outline:2px solid var(--primary); outline-offset:2px; }
.ict-settings summary { padding:10px 12px; cursor:pointer; border-top:1px solid var(--gray-200); font-size:12px; }
.ict-settings input:not([type="checkbox"]) { background:var(--bg-secondary); color:var(--gray-800); border:1px solid var(--gray-300); border-radius:3px; }
.ict-tooltip {
    position: absolute;
    z-index: 2201;
    pointer-events: none;
    white-space: pre-line;
    max-width: calc(100% - 16px);
    padding: 8px;
    border-radius: 5px;
    background: var(--bg-primary);
    color: var(--gray-800);
    border: 1px solid var(--gray-300);
    font-size: 12px;
}
.ict-tooltip[hidden] { display: none; }

/* ===== Drawing Tools Settings Button ===== */
.drawing-tool-settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--gray-500);
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
}
.drawing-tool-settings-btn:hover {
    background: var(--primary-bg);
    border-color: var(--primary);
    color: var(--primary);
}
[data-theme="dark"] .drawing-tool-settings-btn {
    background: var(--bg-secondary);
    border-color: var(--gray-600);
    color: var(--gray-400);
}
[data-theme="dark"] .drawing-tool-settings-btn:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary-light);
    color: var(--primary-light);
}

/* ===== Drawing Tools Settings Panel ===== */
.drawing-tools-settings-panel {
    position: absolute;
    z-index: 2100;
    width: 240px;
    max-height: calc(100vh - 16px);
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--gray-300) transparent;
}
.drawing-tools-settings-panel::-webkit-scrollbar {
    width: 4px;
}
.drawing-tools-settings-panel::-webkit-scrollbar-track {
    background: transparent;
}
.drawing-tools-settings-panel::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 10px;
}
.dts-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px 9px;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-800);
    border-bottom: 1px solid var(--gray-100);
    cursor: move;
    user-select: none;
    background: var(--bg-secondary);
}
.dts-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 17px;
    line-height: 1;
    color: var(--gray-400);
    padding: 0 2px;
}
.dts-close:hover {
    color: var(--gray-700);
}
.dts-body {
    padding: 6px 0;
}
.dts-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 14px;
    transition: background 0.1s;
}
.dts-row:hover {
    background: var(--gray-50);
}
.dts-row-left {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--gray-700);
}
.dts-icon {
    width: 16px;
    text-align: center;
    color: var(--primary);
    font-size: 13px;
}
.dts-row-disabled .dts-row-left {
    color: var(--gray-400);
}
.dts-row-disabled .dts-icon {
    color: var(--gray-300);
}
/* 토글 스위치 */
.dts-toggle {
    width: 36px;
    height: 20px;
    appearance: none;
    background: var(--gray-300);
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}
.dts-toggle:checked {
    background: var(--primary);
}
.dts-toggle::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.dts-toggle:checked::before {
    transform: translateX(16px);
}
.dts-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--gray-600);
    padding: 7px 14px 5px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--gray-200);
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    gap: 6px;
    letter-spacing: 0.03em;
}
.dts-section-title::before {
    content: "";
    display: inline-block;
    width: 3px;
    height: 11px;
    background: var(--primary);
    border-radius: 2px;
}
[data-theme="dark"] .dts-section-title {
    background: #1a1f2e;
    border-color: var(--gray-100);
    color: var(--gray-400);
}
.dts-footer {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--gray-100);
    background: var(--bg-secondary);
}
.dts-btn {
    flex: 1;
    padding: 5px 0;
    font-size: 12px;
    border-radius: 5px;
    border: 1px solid var(--primary);
    background: var(--primary-bg);
    color: var(--primary);
    cursor: pointer;
    transition: all 0.15s;
}
.dts-btn:hover {
    background: var(--primary);
    color: #fff;
}
.dts-btn-off {
    border-color: var(--gray-300);
    background: transparent;
    color: var(--gray-500);
}
.dts-btn-off:hover {
    background: var(--gray-100);
    color: var(--gray-700);
    border-color: var(--gray-400);
}

/* Dark mode */
[data-theme="dark"] .drawing-tools-settings-panel {
    background: var(--bg-primary);
    border-color: var(--gray-100);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
[data-theme="dark"] .dts-header {
    background: #1a1f2e;
    border-color: var(--gray-100);
    color: var(--gray-200);
}
[data-theme="dark"] .dts-close {
    color: var(--gray-500);
}
[data-theme="dark"] .dts-close:hover {
    color: var(--gray-200);
}
[data-theme="dark"] .dts-row:hover {
    background: rgba(255, 255, 255, 0.04);
}
[data-theme="dark"] .dts-row-left {
    color: var(--gray-300);
}
[data-theme="dark"] .dts-row-disabled .dts-row-left {
    color: var(--gray-600);
}
[data-theme="dark"] .dts-row-disabled .dts-icon {
    color: var(--gray-700);
}
[data-theme="dark"] .dts-footer {
    background: #1a1f2e;
    border-color: var(--gray-100);
}
[data-theme="dark"] .dts-body::-webkit-scrollbar-thumb {
    background: var(--gray-600);
}

/* ===== Drawing Tools Grip ===== */
.drawing-tools-grip {
    display: flex;
    align-items: center;
    padding: 0 4px;
    cursor: grab;
    color: var(--gray-400);
    font-size: 13px;
    user-select: none;
    flex-shrink: 0;
}
.drawing-tools-grip:active {
    cursor: grabbing;
}
[data-theme="dark"] .drawing-tools-grip {
    color: var(--gray-500);
}

/* ===== Drawing Tools ===== */
.drawing-tools {
    position: absolute;
    top: 6px;
    left: 363px;
    background: var(--bg-primary);
    padding: 0 4px;
    border-radius: 8px;
    box-shadow: var(--shadow-xl);
    display: none;
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    overflow: hidden;
    max-width: calc(100% - 20px);
    gap: 0;
    height: 47px;
    box-sizing: border-box;
    border: 1px solid var(--gray-200);
    z-index: 1000;
}

/* 내부 스크롤 영역 */
.drawing-tools-scroll-wrapper {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    gap: 6px;
    height: 100%;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.drawing-tools-scroll-wrapper::-webkit-scrollbar {
    display: none;
}

/* 스크롤 버튼 */
.drawing-tools-scroll-btn {
    flex-shrink: 0;
    width: 20px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-500);
    font-size: 10px;
    padding: 0;
    transition:
        opacity 0.2s,
        color 0.15s;
}

.drawing-tools-scroll-btn:hover {
    color: var(--primary);
}

[data-theme="dark"] .drawing-tools-scroll-btn {
    color: #9ca3af;
}

[data-theme="dark"] .drawing-tools-scroll-btn:hover {
    color: var(--primary-light);
}

/* Responsive styles for drawing tools */
@media (max-width: 768px) {
    .drawing-toggle-btn {
        top: 50px;
        left: 10px;
    }

    .drawing-tools {
        top: 95px;
        left: 10px;
        right: 10px;
        width: calc(100vw - 20px);
        max-width: none;
        height: 47px;
        padding: 0 4px;
        overflow: hidden;
    }
}

/* ===== Drawing Settings Group ===== */
.drawing-settings-group {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 34px;
    background-color: var(--bg-secondary, #f0f0f0);
    padding: 2px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color, #e0e0e0);
}

.drawing-settings-input {
    height: 30px;
    border: none;
    border-radius: 4px;
    padding: 0 6px;
    font-size: 12px;
    background: transparent;
    color: var(--gray-800);
    box-sizing: border-box;
    text-align: center;
}

.drawing-settings-input.hex-input {
    width: 65px;
    font-family: monospace;
}

.drawing-settings-input[type="number"] {
    width: 48px;
}

.drawing-settings-input select,
select.drawing-settings-input {
    width: auto;
    min-width: 90px;
    cursor: pointer;
    border: 1px solid var(--border-color, #ccc);
    border-radius: 4px;
    background: var(--bg-primary, #fff);
    color: var(--gray-800);
}

.drawing-color-picker {
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
}

.drawing-color-picker::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.drawing-color-picker::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

.drawing-tools button {
    padding: 0px 8px;
    cursor: pointer;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    background: var(--bg-primary);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--gray-600);
    width: 32px;
    height: 32px;
}

.drawing-tools button i {
    font-size: 14px;
}

.drawing-tools button:hover {
    background: var(--gray-100);
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.drawing-tools button.active {
    background: var(--primary-bg);
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

.drawing-tools input[type="color"] {
    width: 32px;
    height: 32px;
    cursor: pointer;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 2px;
    background: var(--bg-primary);
    transition: all 0.2s ease;
}

.drawing-tools input[type="color"]:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.drawing-tools input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.drawing-tools input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

/* ===== Drawing Tools Divider ===== */
.drawing-tools-divider {
    width: 1px;
    align-self: stretch;
    background: var(--gray-200);
    margin: 0 2px;
}

/* ===== Drawing Count Badge ===== */
.drawing-count-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    background: var(--danger);
    color: white;
    border-radius: 9px;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    z-index: 1;
    opacity: 0.8;
}

/* ===== Chart Mode Indicator ===== */
.chart-mode-indicator {
    position: absolute;
    top: 8px;
    right: 90px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-bg);
    border: 1px solid var(--primary);
    border-radius: 4px;
    z-index: 10;
    pointer-events: none;
    opacity: 0.9;
}

[data-theme="dark"] .chart-mode-indicator {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--primary);
    color: var(--primary);
}

/* ===== Drawing Edit Popup ===== */
.drawing-edit-popup {
    position: absolute;
    z-index: 100;
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    font-size: 13px;
}

.drawing-edit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
}

.drawing-edit-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 2px;
    line-height: 1;
}

.drawing-edit-close:hover {
    color: var(--danger);
}

.drawing-edit-body {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.drawing-edit-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.drawing-edit-row label {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.drawing-edit-row input[type="number"],
.drawing-edit-row input[type="text"] {
    width: 110px;
    padding: 4px 6px;
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    font-size: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.drawing-edit-row select {
    width: 122px;
    padding: 4px 6px;
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    font-size: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.drawing-edit-row input[type="color"] {
    width: 32px;
    height: 26px;
    padding: 1px;
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    cursor: pointer;
    background: none;
}

.drawing-edit-value {
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 500;
}

.drawing-edit-footer {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--gray-200);
}

.drawing-edit-apply {
    flex: 1;
    padding: 5px 0;
    border: none;
    border-radius: 4px;
    background: var(--primary);
    color: white;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.drawing-edit-apply:hover {
    opacity: 0.85;
}

.drawing-edit-delete {
    padding: 5px 12px;
    border: 1px solid var(--danger);
    border-radius: 4px;
    background: none;
    color: var(--danger);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.drawing-edit-delete:hover {
    background: var(--danger);
    color: white;
}

[data-theme="dark"] .drawing-edit-popup {
    background: var(--bg-secondary);
    border-color: var(--gray-100);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .drawing-edit-header {
    border-color: var(--gray-100);
}

[data-theme="dark"] .drawing-edit-footer {
    border-color: var(--gray-100);
}

[data-theme="dark"] .drawing-edit-row input[type="number"],
[data-theme="dark"] .drawing-edit-row input[type="text"] {
    background: var(--bg-tertiary);
    border-color: var(--gray-100);
    color: #e5e7eb;
}

[data-theme="dark"] .drawing-edit-row select {
    background: var(--bg-tertiary);
    border-color: var(--gray-100);
    color: #e5e7eb;
}

[data-theme="dark"] .drawing-edit-row input[type="color"] {
    border-color: var(--gray-100);
}

/* ===== Dark Mode Select Options & Line Settings ===== */
[data-theme="dark"] select option {
    background: var(--bg-secondary);
    color: #e5e7eb;
}

[data-theme="dark"] .line-settings-row select,
[data-theme="dark"] .line-settings-row input[type="text"],
[data-theme="dark"] .line-settings-row input[type="number"],
[data-theme="dark"] .line-settings-row input[type="color"] {
    background: var(--bg-tertiary);
    border-color: var(--gray-200);
    color: #e5e7eb;
}

[data-theme="dark"] .line-settings-row select:focus,
[data-theme="dark"] .line-settings-row input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

[data-theme="dark"] .line-settings-key-display {
    background: var(--bg-tertiary);
    border-color: var(--gray-200);
    color: #e5e7eb;
}

/* ===== Dark Mode Drawing Tools Inputs (Color/Opacity) ===== */
[data-theme="dark"] .drawing-tools input[type="text"],
[data-theme="dark"] .drawing-tools input[type="number"],
[data-theme="dark"] .drawing-tools input[type="color"] {
    background: var(--bg-tertiary) !important;
    border-color: var(--gray-200) !important;
    color: #e5e7eb !important;
}

[data-theme="dark"] .color-hex-input {
    background: var(--bg-tertiary) !important;
    border-color: var(--gray-200) !important;
    color: #e5e7eb !important;
}

/* ===== Calculator Popup ===== */
.calc-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.calc-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.calc-label {
    width: 70px;
    flex-shrink: 0;
    font-size: 13px;
    color: var(--gray-600);
    font-weight: 500;
}

.calc-input-wrap {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.calc-input {
    flex: 1;
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg-primary);
    color: var(--text-primary);
    text-align: right;
    outline: none;
    transition: border-color 0.15s;
}

.calc-input:focus {
    border-color: var(--primary);
}

.calc-input-wrap .calc-input {
    padding-right: 24px;
}

.calc-unit {
    position: absolute;
    right: 8px;
    font-size: 12px;
    color: var(--gray-500);
    pointer-events: none;
}

.calc-divider {
    height: 1px;
    background: var(--gray-200);
    margin: 2px 0;
}

.calc-result-row {
    background: var(--bg-secondary);
    border-radius: 6px;
    padding: 5px 8px;
}

.calc-result-row .calc-label {
    color: var(--gray-500);
    font-size: 12px;
}

.calc-result {
    flex: 1;
    text-align: right;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.calc-result.positive {
    color: #ef4444;
}

.calc-result.negative {
    color: #3b82f6;
}

.calc-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
}

.calc-reset-btn {
    padding: 6px 14px;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--gray-600);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.calc-reset-btn:hover {
    background: var(--gray-50);
    border-color: var(--primary);
    color: var(--primary);
}

.calc-order-price-btn {
    flex-shrink: 0;
    padding: 5px 8px;
    border: 1px solid var(--gray-200);
    border-radius: 5px;
    background: var(--bg-secondary);
    color: var(--gray-600);
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
    line-height: 1;
}

.calc-order-price-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

[data-theme="dark"] .calc-order-price-btn {
    background: var(--bg-tertiary);
    border-color: var(--gray-200);
    color: #e5e7eb;
}

[data-theme="dark"] .calc-order-price-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

[data-theme="dark"] .calc-input {
    background: var(--bg-tertiary) !important;
    border-color: var(--gray-200) !important;
    color: #e5e7eb !important;
}

[data-theme="dark"] .calc-result-row {
    background: var(--bg-tertiary);
}

[data-theme="dark"] .calc-reset-btn {
    background: var(--bg-tertiary);
    border-color: var(--gray-200);
    color: #e5e7eb;
}
