/* --- 1. VARIABLES & THEME --- */
    #tipm_calculator_wrapper {
      --primary-color: #0B1F51;    /* Navy */
      --secondary-color: #1e293b;  /* Dark Slate */
      --text-color: #2B3445;       /* Body Text */
      --bg-color: #F8FAFC;
      --white: #FFFFFF;
      --border-color: #E2E8F0;
      
      --success-color: #10B981;    /* Green */
      --success-bg: #DCFCE7;       
      --danger-color: #EF4444;     /* Red */
      --error-bg: #FEF2F2;         /* Light Red */
      --warning-bg: #FFF7ED;       /* Light Orange */
      --warning-text: #9A3412;     /* Dark Orange */
      
      --hover-btn-bg: #F1F5F9;     
    }

    #tipm_calculator_wrapper * { box-sizing: border-box; margin: 0; padding: 0; }

    #tipm_calculator_wrapper body {
      font-family: 'Inter', sans-serif;
      background-color: var(--bg-color);
      color: var(--text-color);
      line-height: 1.6;
      padding: 40px 20px;
      -webkit-font-smoothing: antialiased;
    }

    /* --- 2. LAYOUT --- */
    #tipm_calculator_wrapper .tipm_calculator-container {
      max-width: 1200px;
      margin: 0 auto;
      background: var(--white);
      border-radius: 16px;
      box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
      border: 1px solid var(--border-color);
      overflow: hidden;
      display: flex;
      flex-direction: column;
    }

    #tipm_calculator_wrapper .tipm_calculator-grid {
      display: grid;
      grid-template-columns: 1fr 1fr; 
      min-height: 850px;
    }

    /* --- LEFT COLUMN: INPUTS --- */
    #tipm_calculator_wrapper .tipm_input-section {
      background-color: #ffffff;
      border-right: 1px solid var(--border-color);
      padding: 40px;
      display: flex;
      flex-direction: column;
      height: 100%;
    }

    #tipm_calculator_wrapper .tipm_section-title {
      color: var(--primary-color);
      font-size: 20px;
      font-weight: 800;
      margin-bottom: 25px;
      padding-bottom: 12px;
      border-bottom: 2px solid var(--border-color);
    }

    /* Input Groups */
    #tipm_calculator_wrapper .tipm_input-row { display: flex; gap: 20px; margin-bottom: 20px; }
    #tipm_calculator_wrapper .tipm_input-row .tipm_input-group { margin-bottom: 0; flex: 1; }
    
    #tipm_calculator_wrapper .tipm_input-group { margin-bottom: 22px; position: relative; width: 100%; }
    
    #tipm_calculator_wrapper .tipm_input-group label {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 8px;
      font-weight: 800;
      color: #1e293b;
      font-size: 13px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    #tipm_calculator_wrapper .tipm_input-wrapper { position: relative; width: 100%; }

    #tipm_calculator_wrapper .tipm_input-wrapper input, #tipm_calculator_wrapper .tipm_input-wrapper select {
      width: 100%;
      padding: 14px 16px;
      border: 1px solid var(--border-color);
      border-radius: 10px;
      font-size: 16px; 
      background-color: var(--white);
      color: var(--primary-color);
      font-weight: 600;
      font-family: 'Inter', sans-serif;
      transition: all 0.2s;
    }
    
    /* Adjust padding if suffix exists */
    #tipm_calculator_wrapper .tipm_input-wrapper:has(.tipm_input-suffix) input {
        padding-right: 35px;
    }

    #tipm_calculator_wrapper .tipm_input-wrapper input:focus {
      outline: none;
      border-color: var(--primary-color);
      box-shadow: 0 0 0 3px rgba(11, 31, 81, 0.1);
    }

    /* Error State */
    #tipm_calculator_wrapper .tipm_input-wrapper.tipm_error input {
        border-color: var(--danger-color);
        background-color: var(--error-bg);
    }

    #tipm_calculator_wrapper .tipm_error-msg {
        color: var(--danger-color);
        font-size: 12px;
        margin-top: 6px;
        font-weight: 600;
        display: none; 
        animation: slideDown 0.2s ease-out;
    }

    /* Suffix ($ / %) */
    #tipm_calculator_wrapper .tipm_input-suffix {
        position: absolute;
        right: 14px;
        top: 50%;
        transform: translateY(-50%);
        color: #94A3B8;
        font-weight: 600;
        font-size: 14px;
        pointer-events: none;
    }

    /* Read-only inputs (Auto-Calculated) */
    #tipm_calculator_wrapper .tipm_input-wrapper input[readonly] {
        background-color: #F1F5F9; /* Distinct background for read-only */
        color: #64748B;
        cursor: default;
        border-color: #E2E8F0;
    }

    /* Mode Toggles */
    #tipm_calculator_wrapper .tipm_toggle-container {
        display: flex;
        background: #F1F5F9;
        padding: 5px;
        border-radius: 12px;
        margin-bottom: 25px;
        border: 1px solid var(--border-color);
    }
    #tipm_calculator_wrapper .tipm_toggle-btn {
        flex: 1;
        padding: 12px;
        font-size: 14px;
        font-weight: 600;
        border: none;
        background: transparent;
        color: #64748B;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.2s;
    }
    #tipm_calculator_wrapper .tipm_toggle-btn.tipm_active {
        background: var(--white);
        color: var(--primary-color);
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        font-weight: 800;
    }

    /* Highlight Box (Payment Section) */
    #tipm_calculator_wrapper .tipm_payment-box {
        background: #F8FAFC; 
        padding: 20px; 
        border-radius: 12px; 
        border: 1px solid var(--border-color); 
        margin-bottom: 25px;
        transition: all 0.3s ease;
    }
    
    #tipm_calculator_wrapper .tipm_payment-box.tipm_manual-mode {
        background: #fff;
        border-color: var(--primary-color);
        box-shadow: 0 4px 12px rgba(11, 31, 81, 0.05);
    }

    #tipm_calculator_wrapper .tipm_edit-link {
        font-size: 11px;
        color: var(--primary-color);
        cursor: pointer;
        text-transform: none;
        font-weight: 700;
        padding: 2px 8px;
        border-radius: 4px;
        background: #e0e7ff;
        transition: background 0.2s;
    }
    #tipm_calculator_wrapper .tipm_edit-link:hover { background: #c7d2fe; }

    #tipm_calculator_wrapper .tipm_manual-msg {
        font-size: 12px;
        color: var(--warning-text);
        background-color: var(--warning-bg);
        padding: 10px;
        border-radius: 8px;
        margin-top: 10px;
        line-height: 1.4;
        border: 1px solid #FED7AA;
        display: none; /* Hidden by default */
    }

    /* Accordion */
    #tipm_calculator_wrapper .tipm_accordion {
        border: 1px solid var(--border-color);
        border-radius: 12px;
        margin-bottom: 15px;
        background: #fff;
        overflow: hidden;
    }
    #tipm_calculator_wrapper .tipm_accordion-header {
        padding: 18px 20px;
        background: #F8FAFC;
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 14px;
        font-weight: 800;
        color: #475569; /* Softened from primary color */
        text-transform: uppercase;
        border-bottom: 1px solid transparent;
        transition: background 0.2s;
    }
    #tipm_calculator_wrapper .tipm_accordion-header:hover { background: #F1F5F9; }
    #tipm_calculator_wrapper .tipm_accordion.tipm_active .tipm_accordion-header { border-bottom-color: var(--border-color); background: #fff; color: var(--primary-color); }
    #tipm_calculator_wrapper .tipm_accordion-content { display: none; padding: 25px; background: #fff; }
    #tipm_calculator_wrapper .tipm_accordion.tipm_active .tipm_accordion-content { display: block; animation: slideDown 0.3s ease-out; }
    
    @keyframes slideDown {
        from { opacity: 0; transform: translateY(-5px); }
        to { opacity: 1; transform: translateY(0); }
    }

    /* Switch Toggle */
    #tipm_calculator_wrapper .tipm_switch-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
    #tipm_calculator_wrapper .tipm_switch-text { font-size: 15px; font-weight: 700; color: var(--primary-color); }
    #tipm_calculator_wrapper .tipm_switch {
        position: relative;
        display: inline-block;
        width: 48px;
        height: 26px;
    }
    #tipm_calculator_wrapper .tipm_switch input { opacity: 0; width: 0; height: 0; }
    #tipm_calculator_wrapper .tipm_slider {
        position: absolute;
        cursor: pointer;
        top: 0; left: 0; right: 0; bottom: 0;
        background-color: #CBD5E1;
        transition: .4s;
        border-radius: 34px;
    }
    #tipm_calculator_wrapper .tipm_slider:before {
        position: absolute;
        content: "";
        height: 20px;
        width: 20px;
        left: 3px;
        bottom: 3px;
        background-color: white;
        transition: .4s;
        border-radius: 50%;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    #tipm_calculator_wrapper input:checked + .tipm_slider { background-color: var(--primary-color); }
    #tipm_calculator_wrapper input:checked + .tipm_slider:before { transform: translateX(22px); }

    /* Lump Sum List */
    #tipm_calculator_wrapper .tipm_lump-sum-list { display: flex; flex-direction: column; gap: 12px; margin-top: 15px; }
    #tipm_calculator_wrapper .tipm_lump-item { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
    #tipm_calculator_wrapper .tipm_lump-item .tipm_input-wrapper { margin-bottom: 0; }
    #tipm_calculator_wrapper .tipm_remove-lump { 
        color: var(--danger-color); cursor: pointer; font-size: 24px; width: 44px; height: 50px;
        background: #FEF2F2; border: 1px solid #FECACA; border-radius: 10px; 
        display: flex; align-items: center; justify-content: center; transition: all 0.2s;
        flex-shrink: 0;
    }
    #tipm_calculator_wrapper .tipm_remove-lump:hover { background: #FCA5A5; color: white; }

    /* Buttons */
    #tipm_calculator_wrapper .tipm_btn-group { margin-top: auto; display: flex; gap: 15px; padding-top: 30px; }
    #tipm_calculator_wrapper .tipm_btn {
        flex: 1;
        padding: 16px;
        border: none;
        border-radius: 10px;
        font-weight: 800;
        font-size: 16px;
        cursor: pointer;
        transition: transform 0.1s, box-shadow 0.2s;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    #tipm_calculator_wrapper .tipm_btn-primary { background: var(--primary-color); color: white; box-shadow: 0 4px 10px rgba(11,31,81,0.2); }
    #tipm_calculator_wrapper .tipm_btn-secondary { background: white; border: 1px solid var(--border-color); color: var(--text-color); }
    #tipm_calculator_wrapper .tipm_btn:hover { transform: translateY(-1px); box-shadow: 0 6px 15px rgba(0,0,0,0.1); }
    #tipm_calculator_wrapper .tipm_btn:active { transform: translateY(0); }

    /* Helper Texts */
    #tipm_calculator_wrapper .tipm_helper-text { font-size: 12px; color: #64748B; margin-top: 6px; font-weight: 500; }

    /* --- RIGHT COLUMN: RESULTS --- */
    #tipm_calculator_wrapper .tipm_results-section {
        background-color: #fafbfd;
        padding: 40px;
        display: flex;
        flex-direction: column;
        gap: 25px;
        overflow-y: auto;
    }

    /* Single Hero Card (Refined) */
    #tipm_calculator_wrapper .tipm_hero-card {
        background-color: var(--white);
        border-radius: 12px;
        border: 1px solid var(--border-color);
        border-left: 6px solid var(--primary-color);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
        overflow: hidden;
    }

    #tipm_calculator_wrapper .tipm_hero-main {
        padding: 30px;
        text-align: center;
        border-bottom: 1px solid var(--border-color);
    }
    
    #tipm_calculator_wrapper .tipm_hero-label { font-size: 14px; color: var(--primary-color); font-weight: 800; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; opacity: 0.8; }
    #tipm_calculator_wrapper .tipm_hero-value { font-size: 42px; font-weight: 900; color: var(--primary-color); margin-bottom: 5px; letter-spacing: -1px; line-height: 1.1; }
    
    #tipm_calculator_wrapper .tipm_hero-subtext {
        font-size: 15px;
        color: #166534;
        margin-bottom: 10px;
        font-weight: 700;
        background: var(--success-bg);
        display: inline-block;
        padding: 6px 16px;
        border-radius: 30px;
    }
    /* Hide savings if 0 */
    #tipm_calculator_wrapper .tipm_hero-subtext.tipm_hidden { display: none; }

    #tipm_calculator_wrapper .tipm_hero-grid {
        display: grid; 
        grid-template-columns: 1fr 1fr; 
        background: #F8FAFC; 
    }
    
    #tipm_calculator_wrapper .tipm_hero-box {
        padding: 20px; 
        text-align: center; 
    }
    #tipm_calculator_wrapper .tipm_hero-box:first-child { border-right: 1px solid #E2E8F0; }
    
    #tipm_calculator_wrapper .tipm_hb-label { font-size: 11px; font-weight: 900; color: #475569; text-transform: uppercase; }
    #tipm_calculator_wrapper .tipm_hb-val { font-size: 20px; font-weight: 800; color: var(--success-color); margin-top: 5px; }
    #tipm_calculator_wrapper .tipm_hb-val.tipm_blue { color: var(--primary-color); }
    #tipm_calculator_wrapper .tipm_hb-sub { 
        font-size: 14px; /* Increased size */
        color: #1e293b; /* Darker color */
        margin-top: 6px; 
        line-height: 1.2; 
        font-weight: 800; /* Bold weight */
    }


    /* Comparison Grid Table */
    #tipm_calculator_wrapper .tipm_comparison-wrapper {
        background: var(--white);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
    }
    #tipm_calculator_wrapper .tipm_comp-header {
        background: #F1F5F9;
        padding: 18px 25px;
        border-bottom: 1px solid var(--border-color);
        font-size: 15px;
        font-weight: 800;
        color: var(--primary-color);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    #tipm_calculator_wrapper .tipm_comp-grid {
        display: grid;
        grid-template-columns: 1.8fr 1fr 1fr; /* Metric | Standard | New */
    }
    #tipm_calculator_wrapper .tipm_comp-cell {
        padding: 16px 20px;
        font-size: 14px;
        border-bottom: 1px solid #F1F5F9;
        display: flex;
        align-items: center;
    }
    #tipm_calculator_wrapper .tipm_comp-cell.tipm_head { 
        font-weight: 800; 
        color: #475569; 
        background: #F8FAFC; 
        border-right: 1px solid #F1F5F9;
    }
    #tipm_calculator_wrapper .tipm_comp-cell.tipm_val { font-weight: 600; color: #64748B; justify-content: flex-end; text-align: right; }
    #tipm_calculator_wrapper .tipm_comp-cell.tipm_val-new { 
        color: var(--primary-color); 
        background: #F0FDF4; 
        justify-content: flex-end; 
        font-weight: 800; 
        text-align: right;
    }

    /* Charts */
    #tipm_calculator_wrapper .tipm_chart-container {
        background: white;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 25px;
        height: 380px;
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center; /* Center the pie/doughnut */
    }
    #tipm_calculator_wrapper .tipm_chart-title { 
        font-size: 16px; 
        font-weight: 700; 
        color: var(--primary-color); 
        margin-bottom: 15px; 
        text-align: center; 
        width: 100%;
    }
    #tipm_calculator_wrapper .tipm_chart-wrapper-inner {
        position: relative;
        width: 100%;
        height: 100%;
        max-width: 320px; /* Constrain max width for nicer Doughnut */
    }

    /* Responsive */
    @media (max-width: 900px) {
        #tipm_calculator_wrapper .tipm_calculator-grid { grid-template-columns: 1fr; }
        #tipm_calculator_wrapper .tipm_input-section { 
            border-right: none; 
            border-bottom: 1px solid var(--border-color); 
            padding: 30px 20px;
        }
        #tipm_calculator_wrapper .tipm_results-section {
            padding: 30px 20px;
        }
        #tipm_calculator_wrapper .tipm_input-row { flex-direction: column; gap: 0; }
        /* Add margin bottom to first item in column layout */
        #tipm_calculator_wrapper .tipm_input-row .tipm_input-group:first-child { margin-bottom: 22px; }
        
        /* Mobile Table Fix */
        #tipm_calculator_wrapper .tipm_comparison-wrapper {
            overflow-x: auto; /* Enable scrolling */
        }
        #tipm_calculator_wrapper .tipm_comp-grid { 
            grid-template-columns: 140px 110px 110px; /* Fixed widths to ensure layout */
            width: max-content; /* Allow grid to grow beyond screen width */
        }
        #tipm_calculator_wrapper .tipm_comp-cell { padding: 10px 12px; font-size: 13px; }
        
        #tipm_calculator_wrapper .tipm_chart-container { height: 320px; }
    }