/* =============================================================================
   ADD STOCK GRID — Professional Compact Design
   ============================================================================= */

/* ── Card container ─────────────────────────────────────────────────────── */
.addstock-card {
    background: var(--bg-card, rgba(15, 23, 42, 0.7));
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06));
    border-radius: 12px;
    overflow: visible;
    margin-bottom: 1rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
}

/* ── Card header / toolbar ──────────────────────────────────────────────── */
.addstock-card-header {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.9)) !important;
    border-bottom: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06)) !important;
    padding: 0.5rem 0.75rem !important;
    overflow: visible !important;
    position: relative;
    z-index: 3;
}

.addstock-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.addstock-toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.addstock-toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* Icon+label buttons in toolbar */
.addstock-icon-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    height: 34px;
    padding: 0 8px !important;
    border-radius: 6px !important;
    color: var(--text-secondary, #cbd5e1) !important;
    background: var(--surface-200, rgba(255, 255, 255, 0.04)) !important;
    border: 1px solid transparent !important;
    transition: all 0.2s ease;
    text-decoration: none !important;
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
}

.addstock-label-btn {
    width: auto !important;
    gap: 0;
}

.addstock-icon-btn:hover {
    color: var(--accent-primary, #00d4ff) !important;
    background: var(--surface-400, rgba(255, 255, 255, 0.08)) !important;
    border-color: rgba(0, 212, 255, 0.2) !important;
    transform: translateY(-1px);
}

.addstock-icon-link {
    line-height: 34px;
    text-align: center;
}

/* Kite sync button — amber accent */
.addstock-kite-btn {
    font-weight: 500;
    color: #f59e0b !important;
    background: rgba(245, 158, 11, 0.08) !important;
    border: 1px solid rgba(245, 158, 11, 0.2) !important;
}

.addstock-kite-btn:hover {
    background: rgba(245, 158, 11, 0.15) !important;
    border-color: rgba(245, 158, 11, 0.4) !important;
    color: #fbbf24 !important;
}

/* Import CSV button — override to teal accent */
#import-kite-csv-btn.addstock-kite-btn {
    color: #2dd4bf !important;
    background: rgba(45, 212, 191, 0.08) !important;
    border: 1px solid rgba(45, 212, 191, 0.2) !important;
}

#import-kite-csv-btn.addstock-kite-btn:hover {
    background: rgba(45, 212, 191, 0.15) !important;
    border-color: rgba(45, 212, 191, 0.4) !important;
    color: #5eead4 !important;
}

/* ── Sort dropdown ──────────────────────────────────────────────────────── */
.addstock-sort-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.addstock-sort-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-muted, #64748b);
    text-transform: uppercase;
    white-space: nowrap;
}

.addstock-sort-select {
    width: 140px !important;
    min-width: 140px !important;
    height: 32px !important;
    font-size: 0.75rem !important;
    padding: 0.15rem 1.8rem 0.15rem 0.5rem !important;
    background-color: var(--input-bg, #f8f9fa) !important;
    color: var(--text-secondary, #334155) !important;
    border: 1px solid var(--border-color, #d1d5db) !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    -webkit-appearance: auto !important;
    appearance: auto !important;
    position: relative;
    z-index: 10;
}

.addstock-sort-select:focus {
    border-color: var(--primary, #3b82f6) !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15) !important;
}

/* Dark theme overrides for sort select */
[data-bs-theme="dark"] .addstock-sort-select,
.dark-theme .addstock-sort-select {
    background-color: rgba(255, 255, 255, 0.05) !important;
    color: #cbd5e1 !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-bs-theme="dark"] .addstock-sort-select:focus,
.dark-theme .addstock-sort-select:focus {
    border-color: rgba(0, 212, 255, 0.3) !important;
    box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.08) !important;
}

/* AI switch */
.addstock-ai-switch {
    margin-bottom: 0 !important;
}

.addstock-ai-switch .form-check-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-muted, #94a3b8);
    text-transform: uppercase;
    user-select: none;
}

.addstock-ai-switch .form-check-input {
    cursor: pointer;
}

.addstock-ai-switch .form-check-input:checked {
    background-color: #14b8a6;
    border-color: #14b8a6;
}

/* ── Card body ──────────────────────────────────────────────────────────── */
.addstock-card-body {
    background: transparent !important;
    color: var(--text-primary, #f8fafc);
    padding: 0.75rem !important;
}

/* ── Table container ────────────────────────────────────────────────────── */
.addstock-table-wrap {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0.5rem;
    position: relative;
}

.addstock-table {
    background: transparent !important;
    color: var(--text-secondary, #cbd5e1) !important;
    font-size: 0.85rem;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    width: 100%;
}

/* ── Fixed column widths (shared between TH and TD) ─────────────────── */
.addstock-col-date  { width: 130px; min-width: 120px; }
.addstock-col-stock { width: 200px; min-width: 150px; }
.addstock-col-qty   { width: 90px;  min-width: 80px; text-align: right; }
.addstock-col-price { width: 110px; min-width: 95px; text-align: right; }
.addstock-col-chk   { width: 65px;  min-width: 55px; text-align: center; }
.addstock-col-act   { width: 50px;  min-width: 44px; text-align: center; }

/* ── Table header ──────────────────────────────────────────────────────── */
.addstock-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.addstock-thead {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.8), rgba(15, 23, 42, 0.9)) !important;
}

.addstock-th {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted, #94a3b8) !important;
    border-bottom: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06)) !important;
    padding: 0.55rem 0.5rem !important;
    white-space: nowrap;
    vertical-align: middle;
}

/* ── Table body ────────────────────────────────────────────────────────── */
.addstock-td {
    background: transparent !important;
    border: none !important;
    padding: 0.4rem 0.5rem !important;
    vertical-align: middle;
}

.addstock-row {
    background: linear-gradient(180deg, rgba(13, 23, 28, 0.35), rgba(9, 17, 20, 0.35));
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    transition: background-color 0.15s ease;
}

.addstock-row:hover {
    background: rgba(255, 255, 255, 0.04);
}

/* ── Input styling (uniform look) ───────────────────────────────────── */
.addstock-input {
    background: rgba(255, 255, 255, 0.05) !important;
    color: #cfe7ee !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 4px !important;
    padding: 5px 8px !important;
    font-size: 0.82rem !important;
    transition: border-color 0.2s ease;
}

.addstock-input:focus {
    border-color: rgba(0, 212, 255, 0.4) !important;
    box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.08) !important;
    outline: none !important;
}

.addstock-input-stock { width: 100% !important; }
.addstock-input-num   { width: 80px !important; }

/* Checkbox alignment */
.addstock-chk {
    display: flex !important;
    justify-content: center;
    align-items: center;
    margin: 0 !important;
}

/* Per-row delete button */
.addstock-row-del-btn {
    width: 30px !important;
    height: 30px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 6px !important;
    font-size: 0.78rem;
}

.addstock-row-del-btn:hover {
    background: rgba(239, 68, 68, 0.15) !important;
}

/* ── Action Bar (bottom) ────────────────────────────────────────────────── */
.addstock-action-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.6rem 0;
    border-top: 1px solid var(--surface-200, rgba(255, 255, 255, 0.04));
    flex-wrap: wrap;
}

.addstock-actions-left {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.addstock-actions-right {
    display: flex;
    gap: 0.35rem;
}

.addstock-action-btn {
    font-size: 0.78rem !important;
    font-weight: 500 !important;
    padding: 0.3rem 0.7rem !important;
    border-radius: 6px !important;
    letter-spacing: 0.01em;
    transition: all 0.2s ease;
}

.addstock-action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.addstock-delete-btn {
    border-width: 1px !important;
    width: 34px !important;
    height: 34px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 8px !important;
}

.addstock-delete-btn:hover {
    background: rgba(239, 68, 68, 0.15) !important;
}

/* ── Pagination ─────────────────────────────────────────────────────────── */
.addstock-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.3rem 0;
}

.addstock-page-btn {
    width: 30px;
    height: 30px;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 6px !important;
    color: var(--text-muted, #94a3b8) !important;
    font-size: 0.8rem;
}

.addstock-page-btn:hover {
    color: var(--accent-primary, #00d4ff) !important;
    background: var(--surface-300, rgba(255, 255, 255, 0.06)) !important;
}

.addstock-page-label {
    font-size: 0.75rem;
    color: var(--text-muted, #94a3b8);
    font-weight: 500;
    letter-spacing: 0.03em;
    min-width: 50px;
    text-align: center;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .addstock-card-header { padding: 0.4rem 0.5rem !important; }
    .addstock-card-body { padding: 0.5rem !important; }
    .addstock-toolbar { gap: 0.25rem; }
    .addstock-icon-btn { height: 30px; font-size: 0.75rem; padding: 0 6px !important; }
    .addstock-sort-select { width: 115px !important; font-size: 0.7rem !important; }
    .addstock-th { font-size: 0.68rem; padding: 0.4rem 0.35rem !important; }
    .addstock-table { font-size: 0.8rem; }
    .addstock-action-btn { font-size: 0.72rem !important; padding: 0.25rem 0.5rem !important; }
    .addstock-delete-btn { width: 30px !important; height: 30px !important; }
}

@media (max-width: 480px) {
    .addstock-toolbar { flex-direction: column; align-items: stretch; }
    .addstock-toolbar-left { justify-content: center; }
    .addstock-toolbar-right { justify-content: center; }
    .addstock-sort-group { justify-content: center; }
    .addstock-action-bar { flex-direction: column; align-items: stretch; }
    .addstock-actions-left { justify-content: center; }
    .addstock-actions-right { justify-content: center; }
}

/* =============================================================================
   TRADING RULES SECTION — Modern React-style Design
   ============================================================================= */

/* ── Container ────────────────────────────────────────────────────────── */
.rules-section-container {
    background: var(--bg-card, rgba(15, 23, 42, 0.6));
    border: 1px solid rgba(129, 140, 248, 0.12);
    border-radius: 16px;
    overflow: visible;
    position: relative;
}

/* Gradient top accent bar */
.rules-section-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #818cf8, #f59e0b, #10b981);
    border-radius: 16px 16px 0 0;
}

/* ── Header ───────────────────────────────────────────────────────────── */
.rules-section-header {
    padding: 1.25rem 1.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.rules-header-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, #818cf8, #6366f1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.rules-header-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary, #f1f5f9);
    margin: 0;
    letter-spacing: -0.01em;
}

.rules-header-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
    display: block;
    margin-top: 2px;
}

.rules-count-pill {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

/* ── Step indicators ──────────────────────────────────────────────────── */
.rules-step-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rules-step-number {
    font-size: 0.65rem;
    font-weight: 800;
    color: #818cf8;
    background: rgba(129, 140, 248, 0.1);
    border: 1px solid rgba(129, 140, 248, 0.2);
    border-radius: 6px;
    padding: 2px 8px;
    letter-spacing: 0.05em;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.rules-step-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary, #94a3b8);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

/* ── Create Rule Card ─────────────────────────────────────────────────── */
.rules-create-card {
    padding: 1.25rem 1.5rem;
    background: linear-gradient(
        135deg,
        rgba(129, 140, 248, 0.03) 0%,
        rgba(245, 158, 11, 0.02) 50%,
        rgba(16, 185, 129, 0.02) 100%
    );
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

/* ── Field labels ─────────────────────────────────────────────────────── */
.rules-field-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.rules-field-hint {
    display: block;
    font-size: 0.68rem;
    color: var(--text-muted, #475569);
    margin-top: 4px;
    font-style: italic;
}

/* ── Dropdown override ────────────────────────────────────────────────── */
.rules-dropdown .Select-control,
.rules-dropdown .Select-menu-outer {
    background: rgba(15, 23, 42, 0.5) !important;
    border-color: rgba(129, 140, 248, 0.2) !important;
    border-radius: 10px !important;
}

.rules-dropdown .Select-value {
    background: rgba(129, 140, 248, 0.15) !important;
    border-color: rgba(129, 140, 248, 0.3) !important;
    border-radius: 6px !important;
    color: #c7d2fe !important;
}

#rule-stock-selector {
    font-size: 0.82rem;
}

/* ── Textarea ─────────────────────────────────────────────────────────── */
.rules-textarea {
    min-height: 68px !important;
    font-size: 0.82rem !important;
    background: rgba(15, 23, 42, 0.4) !important;
    border: 1px solid rgba(129, 140, 248, 0.15) !important;
    color: #e2e8f0 !important;
    border-radius: 10px !important;
    padding: 12px !important;
    line-height: 1.5;
    resize: vertical;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.rules-textarea:focus {
    border-color: rgba(129, 140, 248, 0.4) !important;
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.08) !important;
    outline: none !important;
}

.rules-textarea::placeholder {
    color: rgba(148, 163, 184, 0.5) !important;
    font-style: italic;
}

/* ── Refine Button (CTA) ─────────────────────────────────────────────── */
.rules-refine-btn {
    width: 100%;
    padding: 10px 16px !important;
    font-size: 0.82rem !important;
    font-weight: 700 !important;
    border-radius: 10px !important;
    border: none !important;
    background: linear-gradient(135deg, #818cf8, #6366f1) !important;
    color: #ffffff !important;
    transition: all 0.25s ease;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
    letter-spacing: 0.02em;
}

.rules-refine-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45) !important;
    background: linear-gradient(135deg, #6366f1, #4f46e5) !important;
}

.rules-refine-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3) !important;
}

/* ── Rules List Section ───────────────────────────────────────────────── */
.rules-list-section {
    padding: 1.25rem 1.5rem;
}

/* ── Rule card text ───────────────────────────────────────────────────── */
.rules-card-text {
    font-size: 0.8rem;
    color: #e2e8f0;
    line-height: 1.5;
}

.rules-card-scope {
    display: flex;
    align-items: center;
    margin-top: 4px;
    font-size: 0.7rem;
    color: #64748b;
}

body.light-theme .rules-card-text {
    color: #334155;
}

body.light-theme .rules-card-scope {
    color: #64748b;
}

/* ── Light theme — full overrides ─────────────────────────────────────── */
body.light-theme .rules-section-container {
    background: #ffffff;
    border-color: rgba(129, 140, 248, 0.18);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

body.light-theme .rules-header-title {
    color: #1e293b;
}

body.light-theme .rules-header-subtitle {
    color: #64748b;
}

body.light-theme .rules-step-label {
    color: #475569;
}

body.light-theme .rules-field-label {
    color: #475569;
}

body.light-theme .rules-field-hint {
    color: #94a3b8;
}

body.light-theme .rules-create-card {
    background: linear-gradient(135deg, rgba(129, 140, 248, 0.05) 0%, rgba(245, 158, 11, 0.03) 100%);
    border-bottom-color: #f1f5f9;
}

body.light-theme .rules-section-header {
    border-bottom-color: #f1f5f9;
}

/* Textarea */
body.light-theme .rules-textarea {
    background: #f8fafc !important;
    border-color: #e2e8f0 !important;
    color: #1e293b !important;
}

body.light-theme .rules-textarea:focus {
    border-color: #818cf8 !important;
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.12) !important;
}

body.light-theme .rules-textarea::placeholder {
    color: #94a3b8 !important;
}

/* Dropdown */
body.light-theme #rule-stock-selector .Select-control {
    background: #f8fafc !important;
    border-color: #e2e8f0 !important;
    color: #1e293b !important;
}

body.light-theme #rule-stock-selector .Select-placeholder {
    color: #94a3b8 !important;
}

body.light-theme #rule-stock-selector .Select-value-label {
    color: #1e293b !important;
}

body.light-theme #rule-stock-selector .Select-menu-outer {
    background: #ffffff !important;
    border-color: #e2e8f0 !important;
}

body.light-theme #rule-stock-selector .Select-option {
    color: #1e293b !important;
}

body.light-theme #rule-stock-selector .Select-option.is-focused {
    background: #eff6ff !important;
}

/* Rule cards in light theme */
body.light-theme .rules-list-section .d-flex.justify-content-between {
    background-color: #f8fafc !important;
    border-color: rgba(129, 140, 248, 0.12) !important;
}

body.light-theme .rules-list-section .d-flex.justify-content-between > .d-flex > div:last-child > div:nth-child(2) {
    color: #334155 !important;
}

/* Rule refined text */
body.light-theme .rules-list-section div[style*="color: #e2e8f0"] {
    color: #334155 !important;
}

/* Scope text */
body.light-theme .rules-list-section div[style*="color: #64748b"] {
    color: #64748b !important;
}

/* Action buttons in light theme */
body.light-theme .rules-list-section button[style*="color: #94a3b8"] {
    color: #64748b !important;
    border-color: rgba(100, 116, 139, 0.2) !important;
}

body.light-theme .rules-list-section button[style*="color: #94a3b8"]:hover {
    background: rgba(99, 102, 241, 0.08) !important;
    color: #4f46e5 !important;
}

/* Empty state */
body.light-theme .rules-list-section .text-center p {
    color: #64748b !important;
}

/* Count pill */
body.light-theme .rules-count-pill {
    background: rgba(16, 185, 129, 0.08);
    border-color: rgba(16, 185, 129, 0.15);
}

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .rules-section-header { padding: 1rem 1rem 0.75rem; }
    .rules-create-card { padding: 1rem; }
    .rules-list-section { padding: 1rem; }
    .rules-header-icon { width: 34px; height: 34px; border-radius: 10px; }
    .rules-header-title { font-size: 0.95rem; }
    .rules-refine-btn { padding: 8px 12px !important; }
}
